C# OPC客户端写入项 我制作了一个OPC客户端,它使用OPC基金会API DA 3和使用施耐德OFS服务器。 我能够从服务器读取组中的项目,也能够向项目写入短值
我面临着将字符串值写入项和将浮点值写入项的困难 该项的值不会更改 浮动项名为“DevExample_1!”!在服务器上输出“实际值”C# OPC客户端写入项 我制作了一个OPC客户端,它使用OPC基金会API DA 3和使用施耐德OFS服务器。 我能够从服务器读取组中的项目,也能够向项目写入短值,c#,opc,C#,Opc,我面临着将字符串值写入项和将浮点值写入项的困难 该项的值不会更改 浮动项名为“DevExample_1!”!在服务器上输出“实际值” string[] groupitems = { "Test_device!INPUT_INT_VALUE", "Test_device!OUTPUT_INT_VALUE", "DevExample_1!INPUT_STRING_VALUE","DevExample_1!OUPUT_STRING_VALUE","DevExample_1!OUTPUT
string[] groupitems = { "Test_device!INPUT_INT_VALUE", "Test_device!OUTPUT_INT_VALUE", "DevExample_1!INPUT_STRING_VALUE","DevExample_1!OUPUT_STRING_VALUE","DevExample_1!OUTPUT_REAL_VALUE"};
Opc.Da.Subscription group = CreateGroup(server, "GroupTest", groupitems);
WriteGroupItemValue(group, "DevExample_1!OUTPUT_REAL_VALUE", 1.5e-02);
public static Opc.Da.Subscription CreateGroup(Opc.Da.Server server, string groupName, string[] groupitems)
{
Opc.Da.SubscriptionState groupState;
Opc.Da.Subscription groupReadWrite;
groupState = new Opc.Da.SubscriptionState(); // subscr state
groupState.Name = groupName;
groupState.UpdateRate = 1000;// this is the time between every reads from OPC server
groupState.Active = true;//this must be true if you the group has to read value
groupReadWrite = (Opc.Da.Subscription)server.CreateSubscription(groupState); // add subscr for groupReadWrite
itemsLength = groupitems.Length; // determine amount of items
items = new Opc.Da.Item[itemsLength]; // items array of DA type
for (int i = 0; i < items.Length; i++)
{
items[i] = new Opc.Da.Item(); // create new DA item for every index
items[i].ItemName = groupitems[i];
}
items = groupReadWrite.AddItems(items);
return groupReadWrite;
}
public static void WriteGroupItemValue(Opc.Da.Subscription group, string itemName, object itemValue){
Opc.Da.Item[] itemToAddWrite = new Opc.Da.Item[1]; /
itemToAddWrite[0] = new Opc.Da.Item();
itemToAddWrite[0].ItemName = itemName;
Opc.Da.ItemValue[] writeValues = new Opc.Da.ItemValue[1];
writeValues[0] = new Opc.Da.ItemValue(itemToAddWrite[0]);
writeValues[0].Value = itemValue; // set value
writeValues[0].ServerHandle = group.Items[0].ServerHandle;
group.Write(writeValues); // write the value of the items
}
string[]groupitems={“测试设备!输入值”,“测试设备!输出值”,“DevExample\u 1!输入值”,“DevExample\u 1!输出值”,“DevExample\u 1!输出值”};
Opc.Da.Subscription group=CreateGroup(服务器,“GroupTest”,groupitems);
WriteGroupItemValue(组,“DevExample_1!输出实际值”,1.5e-02);
公共静态Opc.Da.Subscription CreateGroup(Opc.Da.Server服务器,字符串groupName,字符串[]groupitems)
{
Opc.Da.SubscriptionState组状态;
Opc.Da.Subscription-groupReadWrite;
groupState=new Opc.Da.SubscriptionState();//subscr state
groupState.Name=groupName;
groupState.UpdateRate=1000;//这是每次从OPC服务器读取数据之间的时间间隔
groupState.Active=true;//如果必须读取组中的值,则该值必须为true
groupReadWrite=(Opc.Da.Subscription)server.CreateSubscription(groupState);//为groupReadWrite添加subscr
itemsLength=groupitems.Length;//确定项目数量
items=new Opc.Da.Item[itemsLength];//Da类型的items数组
对于(int i=0;i
您能详细说明一下吗?是否有任何错误?“组。项[0]。服务器句柄;“错误,[0]应替换为表示要写入的组中iten名称的索引。