S7NetPlus / s7netplus

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

Written value is offset by 2 bytes #509

Closed 2287728768 closed 11 months ago

mycroes commented 11 months ago

Please provide an English description of your problem and add a minimal reproduction that shows when the issue happens.

2287728768 commented 11 months ago

The DB address you want to write is DB1. DBW0.0, and the result is written to DB1. DBW2.0

mycroes commented 11 months ago

Please add a minimal reproduction. The behavior you're experiencing doesn't seem to be a known issue.

2287728768 commented 11 months ago

yes,Write value offset by 2 bytes

mycroes commented 11 months ago

Please add a minimal reproduction (code sample) that causes this problem.

2287728768 commented 11 months ago

Plc PLC20 = new Plc(CpuType.S71500, "192.168.12.254", 0, 1); PLC20.Open(); PLC20.Write(textBox2.Text, int.Parse(textBox1.Text)); //textBox2 To obtain the DB block address

2287728768 commented 11 months ago

The operating environment is Visual Studio 2017. PLC operates in a simulation environment Thank you

mycroes commented 11 months ago

You're writing an int, which is 4 bytes, comparable to Siemens DINT. From your explanation of the issue I'm assuming you were expecting to write a short, or INT in Siemens terminology. Changing the code to short.Parse(textBox1.Text) will probably do what you expected.

2287728768 commented 11 months ago

such is the case. Thank you for explaining