Comments (8)
@jkoplo - I'd be keen to get your view on this.
from libplctag.net.
from libplctag.net.
What about something like this:
The consumer provides the preferred C# they want to use, and they provide the method by which the tag is encoded/decoded.
public class Tag<T, U> where T : IDataType<U>, new()
{
T dataType = new T();
Tag tag;
public void Read(TimeSpan timeout)
{
tag.Read(timeout);
Value = dataType.Decode(tag);
}
public void Write(TimeSpan timeout)
{
dataType.Encode(tag, Value);
tag.Write(timeout);
}
public U Value { get; set; }
}
public interface IDataType<T>
{
int ElementSize { get; }
int CipCode { get; }
void Encode(Tag tag, T t);
T Decode(Tag tag);
}
Our library could implement the DataType for the basic types but if they wanted to extend this (PID tags, other UDTs, etc) they could just implement IDataType.
This is probably better than the abstract classes I did last year for my own projects in my opinion. The main thing missing is array indexers.
from libplctag.net.
That's really nice and just about what I had in mind. I particularly like the interface. You kinda did the work already, but I'm hoping I'll have time to integrate this tonight.
from libplctag.net.
Cool, nice - I haven't compiled/tried it but seems roughly right. Do you know if there is a way to make classes be arrays in a generic way:
i.e. a single class can have 0, 1, 2 or 3 dimensions?
from libplctag.net.
Nice!
Perhaps you could call something like your DataType.Decode(), but it would take two arguments: the tag and an offset. The offset would be the byte offset to that element of the array in the tag's data. After Read you would calculate the element offsets, and then call Decode() on one element at a time?
In C++ this is painful. Easier to have a class that overloads the array operator and pretends to be an array than to use the normal notation for array declarations. I think that there is some template magic to make this a bit more palatable.
Minor nit: in your example code, if the timeout is too short or zero, Read() will return before there is any data and perhaps throw an exception.
from libplctag.net.
@kyle-github I think we're thinking along the same lines: maybe we should only support 0D and 1D access because that is what libplctag does. I know that AB have 2d and 3d arrays, but not sure about other systems.
If users want to inherit this class and provide 2d or 3d indexers and different constructors (with array sizes) they could do so. I don't know how this would work in C++but in C# it is fairly straightforward to provide 2D indexers.
So the base type would provide access via a Value
property, and 1d access via a 1D indexer.
What do you think?
public class Tag<T, U> where T : IDataType<U>, new()
{
// .....
public U Value { get; set; } // check that element_count == 1 and throw error if not
public U this[int index] { get; set; } // Of course do checks on index bounds
}
Hmmmm... it doesn't feel right, maybe only the indexer? hmmmm...
from libplctag.net.
This is long done
from libplctag.net.
Related Issues (20)
- BoolPlcMapper not returning properly HOT 1
- Connecting to a topic name HOT 2
- Running on .NET Alpine docker image HOT 3
- ReadAsync + Dispose HOT 4
- Async call exception behavior varies HOT 5
- Why can't I read out the PLC data type after a "Read" although the data type is supplied with the read? HOT 2
- Read Performance for Numerous Tags HOT 1
- Determining which tag read/write operation a warning in the log is associated with HOT 16
- Unloading of plctag.dll stuck in Shutdown HOT 5
- ErrorNoData exceptions thrown by LibPlcTag are not able to be handled by Try/Catch. HOT 9
- PowerFlex 753 communication over Ethernet. Is it possible? HOT 4
- Booleans in UDTs HOT 3
- Deadlock if Async Read/Write called from UI Thread HOT 2
- How to write an UDT subset HOT 5
- UDT with mixed read/write access HOT 3
- Expose more TagOfT properties to ITag interface HOT 2
- String tag read but not write HOT 4
- Issue's when controller is located in last slot of rack HOT 7
- How to read/write strings HOT 41
- Reading PLC 5 Data File HOT 5
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from libplctag.net.