I try to read data from datablock (DB60), but I get only ?5
. So in data block should be JAMES17
.
private void button1_Click(object sender, EventArgs e)
{
if (button1.Text == "Connect PLC")
{
button1.Text = "Disconnect PLC";
ClassPLCS7Client.PLCClientConnect_Result ConnectResult = new
ClassPLCS7Client.PLCClientConnect_Result();
ConnectResult = PLCClient.Connect(("192.168.0.2"), 0, 1);
if (ConnectResult.State == ClassPLCS7Client.PLCClientConnectState.Connected)
{
this.label1.Text = "Connected PLC1 " + ConnectResult.ReSultString;
label1.ForeColor = Color.Green;
ClassPLCS7Client.ReadDataBlockString_Result read = new ClassPLCS7Client.ReadDataBlockString_Result();
read = PLCClient.ReadDataBlockString(60, 0, 7);
this.textBox1.Text = read.DataValue[0];
//this.textBox1.Text = arr4[];// read.ReSultString;
}
else
{
this.label1.Text = "Fail " + ConnectResult.ReSultString;
label1.ForeColor = Color.Red;
}
}
else
{
button1.Text = "Connect PLC";
disconnect_plc();
this.label1.Text = "Disconnect";
label1.ForeColor = Color.Black;
}
}<code>
First : you are putting J string in byte offset 0 and A string in byte offset 256 and M string in byte offset 512 etcetera .... you don't have a string in consecutive bytes as it should be.
Second: when S7 stores a string the two first bytes are reserved to store the first the max string size in bytes and the second the actual size of string. Therefore in your case your memory must contain this: (Assuming the reserved memory is 256 bytes size)
offset 0 == 254, offset 1 == 7, offset 2 to 8 == 'JAMES17'