Open Wobeam opened 1 year ago
You write plc_data = (float)plc.Read("DB1300.DBD0");
You write plc_data = (float)plc.Read("DB1300.DBD0");
Thanks of course but it doesn't matter. Seems the library can't read/write float directly. It still needs some convertations.
Use the Read(DataType dataType, int db, int startByteAdr, VarType varType, int varCount, byte bitAdr = 0)
method instead if you want the correct type in one call.
As seen in the internal PLCAddress
class a DBD
address is always converted to a DWord
and that translates to a C# uint
:
case "DBD": varType = VarType.DWord; return;
Just do this:
var floatNumber = BitConverter.ToSingle(BitConverter.GetBytes((uint)plc.Read("DB200.DBD34")), 0)
You can also use the method which is described in the wiki at "value conversion":
float result = ((uint)plc.Read("DB1.DBD40")).ConvertToFloat();
OR you use the method to read multiple vars from a list. The list can also contain only one item. When declaring the items you can define the datatype.
You can also use the method which is described in the wiki at "value conversion":
float result = ((uint)plc.Read("DB1.DBD40")).ConvertToFloat();
OR you use the method to read multiple vars from a list. The list can also contain only one item. When declaring the items you can define the datatype.
Yeah, I have found conversion in docs last year. Thanks.
Hello,
In PLC DB shown absolute address is Real type.
used library version is latest.