AB PLC通信问题
公司突然由原来的西门子PLC换成了AB的,搞得我们写上位机程序的不知所措,没有测试过,目前了解的情况来看,据说AB的plc也是可以用OPC来通信,但是一次只能读写一个单元,也就是说之前用西门子的时候上位机能够写入一个object,这个object可以是一个数组,但是ab却只能是一个int。请问网上有没有高手回答下我的问题,并提供相关的例程。
以下是西门子写入plc的方式,OPCComm是OPC的实例:
private bool setItemDataI(int ItemIndex, int[] data)
{
// TODO: 添加 PLCCommunicate.setItemDataI 实现
object setData = new object();
int oneData;
short[] tempShort = new short[data.Length];
for (int i = 0; i < data.Length; i++)
{
tempShort[i] = (short)data[i];
}
if (tempShort.GetLength(0) == 1)
{
oneData = tempShort[0];
setData = oneData;
}
else
{
setData = tempShort;
}
if (0 != OPCComm.SetItem(ItemIndex, setData))
{
this.errorInfo = OPCComm.GetLastErrInfo();
return false;
}
else
{
return true;
}
}