-
Notifications
You must be signed in to change notification settings - Fork 648
Value conversion
FalcoGoodbody edited this page Sep 9, 2020
·
14 revisions
- Read S7 Word:
ushort result = (ushort)plc.Read("DB1.DBW0");- Write S7 Word:
ushort val = 40000;
plc.Write("DB1.DBW0", val);- Read S7 Int / Dec, you need to use the method ConvertToShort():
short result = ((ushort)plc.Read("DB1.DBW0")).ConvertToShort();- Write S7 Int / Dec, you need to use the method ConvertToUshort():
short value = -100;
plc.Write("DB1.DBW0", value.ConvertToUshort());- Read S7 DWord:
uint result = (uint)plc.Read("DB1.DBD40");- Write S7 DWord:
uint val = 1000;
plc.Write("DB1.DBD40", val);- Read S7 Dint, you need to use ConvertToInt():
int result2 = ((uint)plc.Read("DB1.DBD60")).ConvertToInt();- Write S7 Dint:
int value = -60000;
plc.Write("DB1.DBD60", value);- Read S7 Real, you need to use ConvertToDouble():
double result = ((uint)plc.Read("DB1.DBD40")).ConvertToDouble();- Write S7 Real, you need to use ConvertToUInt():
double val = 35.687;
plc.Write("DB1.DBD40", val.ConvertToUInt());- Read bool/bit from byte
myByte = plc.ReadBytes(DataType.DataBlock, 153, 0, 1); // myByte = 5 = 0000 0101
myByte.SelectBit(0) // true
myByte.SelectBit(1) // false- Write bool/bit from byte
plc.WriteBit(DataType.DataBlock, 157, 0, 0, false);