Snap7 read INT value

userxyz

Member
Join Date
May 2002
Location
any
Posts
2,768
Hi,

I allways used libnodave, but now trying snap7.

However this code doesn't work:

int intValue = 0;
int Area = 0x84;
int DBNumber = Convert.ToInt16(txtDBnr1.Text);
int Start = Convert.ToInt16(txtDBitem1.Text);
int Amount = 1;
int WordLen = 0x04;
Buffer = new byte[2];
intValue = Client.ReadArea(Area, DBNumber, Start, Amount, WordLen, Buffer);
int value = Convert.ToInt16(S7.GetLIntAt(Buffer, 0));
txtRcvVar1.Text = Convert.ToString(value);


Exception thrown: 'System.IndexOutOfRangeException'

A length error somewhere ?
 
Test

Just made the buffer bigger, but then I get the exception that the value received is to big for INT32 ???

int intValue = 0;
int Area = 0x84;
int DBNumber = Convert.ToInt16(txtDBnr1.Text);
int Start = Convert.ToInt16(txtDBitem1.Text);
int Amount = 1;
int WordLen = 0x04;
Buffer = new byte[20];
intValue = Client.ReadArea(Area, DBNumber, Start, Amount, WordLen, Buffer);
int value = Convert.ToInt32(S7.GetLIntAt(Buffer, 0));
txtRcvVar1.Text = Convert.ToString(value);
 
A strange thread and actions taken.

I use Snap7 (Sharp7) nowadays and find it easier, although very similar. Snap has already the PLC simulator (Client, Server) pre compiled to verify communications. But, as proven here, the difficulties and about 90% of code is not related to whatever library is used. Instead it's the stuff around. Exceptions are of great use and error handling is always the most lines of code.
 

Similar Topics

how can i do to write into plc using script python (library snap7) some here have simple exemple to write a bit into plc Regards !!
Replies
0
Views
1,522
i started running this code python but give me errors code python: import snap7 import struct import time from snap7.snap7exceptions import...
Replies
1
Views
3,264
code python: import snap7 from time import sleep import struct import snap7.client as c plc = snap7.client.Client() plc.connect("192.168.0.1")...
Replies
0
Views
1,561
Hello guys i tried to use snap7 with plcsim and it works very well, was wondering if i could use snap7 with ibhs7 link gateway, bacecause the cpu...
Replies
2
Views
2,102
Hi all, I am just starting out with playing with the Raspberry PI and the Snap7 libraries. I was hoping there are more users here that would like...
Replies
22
Views
7,565
Back
Top Bottom