S7NetPlus / s7netplus

S7.NET+ -- A .NET library to connect to Siemens Step7 devices
MIT License
1.35k stars 595 forks source link

"DATE" data type #505

Open TheGEZ opened 1 year ago

TheGEZ commented 1 year ago

Hi All !

Tis is my first post so first of all I want to thank everyone is supporting the awesome project, thank you very much !

As I said I'm new to S7Net+ and I have a question, may be stupid but ... I'm developing a datalogging application that collects some data from an S7-300 PLC using the "ReadMultipleVars" function that has the amazing feature to automatically converts values in the corriponding C# data type, and I've noticed that seems that the "old" type DATE (16Bit IEC 61131-3 "number of days from 1-1-1990") is not directly supported, i I request the data using the "VarType.DateTime" type I get an error. To be clear, this is not a big deal sice the data ca be read by using the "VarType.Word" type en then convert it to the C# DateTime using C# DateTime methods, but i think that would be very handy if the fuction could hande the type by itself. So the question is, is the "DATE" type effectively unsupported or I missed something ?

Thank you again !

bonk-dev commented 1 year ago

If the PR gets merged, you can clone this repo, build the solution, add the reference to your project (while you wait for the official release) and use the new VarType.Date like that: var dataItems = new List<DataItem>() { new DataItem() { VarType = VarType.Date, Count = 1, DataType = DataType.DataBlock, DB = 1 } }; var result = await plc.ReadMultipleVarsAsync(dataItems);