另开新帖(原帖不允许同一用户连续回复三次,所以只有关闭原帖另开了)GM请见谅。
基于OMRON Fins通信的实验,找了好几种方法,结果都遇到了vbstring在C#中,
Unsupported Variant Type on the Method argument。
本人玩C#纯属业余爱好,想请大师们指点迷经。
//================================================================================================================
//VB6.0事件处理 OnReceive()如下,收发数据正常。 //Private Sub Command1_Click()
//FinsMsg1.sendFinsCommand 0, 1, 0, "0101820064000002"
//End Sub //Private Sub FinsMsg1_OnReceive()
//Dim net As Integer, node As Integer, unit As Integer
//Text1.Text = FinsMsg1.receiveMessage(net, node, unit, vbString)
//End Sub
//================================================================================================================ private void button1_Click(object sender, EventArgs e)
{
axFinsMsg1.sendFinsCommand(0, 1, 0, "0101820064000002");
}
private void axFinsMsg1_OnReceive(object sender, EventArgs e)
{
//public virtual object receiveMessage(ref short netID, ref short nodeID, ref short unitID, object messageType)
//AxFINSMSGCTLLib.AxFinsMsg 的成员
short a=0,b=0,c=0;
//object Variant = new object();
object str = new object();
string Variant = "";
//string temp = "";
axFinsMsg1.receiveMessage(ref a, ref b, ref c, Variant);
//Unsupported Variant Type on the Method argument。
}
基于OMRON Fins通信的实验,找了好几种方法,结果都遇到了vbstring在C#中,
Unsupported Variant Type on the Method argument。
本人玩C#纯属业余爱好,想请大师们指点迷经。
//================================================================================================================
//VB6.0事件处理 OnReceive()如下,收发数据正常。 //Private Sub Command1_Click()
//FinsMsg1.sendFinsCommand 0, 1, 0, "0101820064000002"
//End Sub //Private Sub FinsMsg1_OnReceive()
//Dim net As Integer, node As Integer, unit As Integer
//Text1.Text = FinsMsg1.receiveMessage(net, node, unit, vbString)
//End Sub
//================================================================================================================ private void button1_Click(object sender, EventArgs e)
{
axFinsMsg1.sendFinsCommand(0, 1, 0, "0101820064000002");
}
private void axFinsMsg1_OnReceive(object sender, EventArgs e)
{
//public virtual object receiveMessage(ref short netID, ref short nodeID, ref short unitID, object messageType)
//AxFINSMSGCTLLib.AxFinsMsg 的成员
short a=0,b=0,c=0;
//object Variant = new object();
object str = new object();
string Variant = "";
//string temp = "";
axFinsMsg1.receiveMessage(ref a, ref b, ref c, Variant);
//Unsupported Variant Type on the Method argument。
}
根据Fins软件提供的资料,返回值应该是:Variant类型。
另有另一种操作方法的帮助文档解释如下:
Definition Function readArea(Type As SysmacCS1_DataArea_Constants, Offset As Long, Size As Long, RetValType)
Explanation Reads the PLC continuous I/O memory area.
Parameters Type Specifies the area type.
Offset Specifies the area offset.
Size Specifies the area size (number of words).
RetValType Specifies the return value type: character string, byte array, or Variant array.
Return Value The readArea method returns the read value in the type specified in the fourth parameter, stored as a Variant.
Example 1 - Read the data from DM 0 to 100, and store it in the Variant variable var, with subtype String:
Dim var As Variantvar = SYSMAC_CS11.readArea(plcAreaDM, 0, 100, vbString) 2 - Read 10 words of data starting from DM 0, and store it in the variable var, with subtype Variant array. Store the data from word 5 of the Variant array in the Long variable dm5:Dim var As Variant
Dim dm5 As Longvar = SYSMAC_CS11.readArea(plcAreaDM, 0, 10, vbVariant Or vbArray)
dm5 = var(6)
Communication Communication is executed.
See Also FINS command 2301
Unsupported Variant Type on the Method argument。