基于OMRON Fins通信的实验请教各位高手

chenxicheng 2012-08-23 09:24:23
另开新帖(原帖不允许同一用户连续回复三次,所以只有关闭原帖另开了)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。
}

...全文
314 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
chenxicheng 2012-08-23
  • 打赏
  • 举报
回复
[Quote=引用 2 楼 的回复:]
用char[]试试
[/Quote]
还是一样:
Unsupported Variant Type on the Method argument。
assiwe 2012-08-23
  • 打赏
  • 举报
回复
用char[]试试
chenxicheng 2012-08-23
  • 打赏
  • 举报
回复

根据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 Variant

var = 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 Long

var = SYSMAC_CS11.readArea(plcAreaDM, 0, 10, vbVariant Or vbArray)
dm5 = var(6)



Communication Communication is executed.
See Also FINS command 2301

110,499

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧