我正在尝试在S7-1200 CPU的布尔型内存中设置值,我使用了SNAP7库,但无法成功:
Result result = new Result();
byte[] Buffer = new byte[26];
Client.DBRead(1, 0, 2, Buffer);
result.bArret = S7.GetBitAt(Buffer, 0, 1);
result.bMarche = S7.GetBitAt(Buffer, 0, 2);
Client.DBWrite(1, 0, 10, buff);
这是DataBlock 1:
我需要在不使用OPC或其他一些第三方软件的情况下完成此任务.
解决方法:
通过用数据块变量替换Merkers来解决问题,这是一个示例:
S7Client client = new S7Client();
int res = client.ConnectTo("192.168.0.10", 0, 0);
int DBNumber;
int Size;
int Result;
byte[] buffer = new byte[2];
DBNumber = System.Convert.ToInt32(1);
Size = System.Convert.ToInt32(2);
Result = client.DBWrite(DBNumber, 0, Size, buffer);
buffer[0] = 1;
buffer[1] = 1;
Result = client.DBWrite(DBNumber, 0, Size, buffer);
希望将来有人会有用.