Snap7 read INT value

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

hello, I have Siemens 1500 PLC and I want to increase the security level of the project. I was trying to define a password to the communication...
5
Replies
765
Views
Bonjour, je voudrais avec <windev communiquer avec un automate siemens du type s7-1200. Pouvez-vous me dire si possible ? J'essai d'utiliser snap7...
0
Replies
515
Views
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 !!
0
Replies
2,319
Views
i started running this code python but give me errors code python: import snap7 import struct import time from snap7.snap7exceptions import...
1
Replies
4,419
Views
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")...
0
Replies
2,246
Views
Top