C#如何使用三菱FX系列以太网模块进行数据通信?需要具体的连接步骤及软硬件型号? 10
目前使用的是PLC:FX3U-32MT;以太网模块FX-ENET-L;软件MXcomponent;FX-enet-l设置软件;计算机使用visualstudio2015C...
目前使用的是PLC:FX3U-32MT;以太网模块FX-ENET-L;软件MX component;FX-enet-l设置软件;计算机使用visual studio2015 C#编写的!
展开
展开全部
直接走OPC就可以了,
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
提供一个EntFxPlc_ADP.DLL这个.NET组件的C#代码:
EntFxPlc_ADP.PlcClient PLC = new EntFxPlc_ADP.PlcClient();
bool EntLink;
long ScanCount;
int PlcHand;
public void butLink_Click(System.Object sender, System.EventArgs e)
{
short re = 0;
string restr = "";
re = PLC.EntLink(txtLocalIP.Text.Trim(), System.Convert.ToUInt16(Conversion.Val(txtLocalPort.Text)), txtRemoteIP.Text.Trim(), System.Convert.ToUInt16(Conversion.Val(txtRemotePort.Text)), "DEMO", ref PlcHand, System.Convert.ToUInt16(1000), System.Convert.ToBoolean(cmbCmdType.SelectedIndex));
txtReLink.Text = re.ToString();
if (re == 0)
{
EntLink = true;
MessageBox.Show("PLC联接成功!");
}
else
{
EntLink = false;
MessageBox.Show("PLC联接失败: " + restr);
}
}
public void butClose_Click(System.Object sender, System.EventArgs e)
{
short re = PLC.DeLink(PlcHand);
txtReClose.Text = re.ToString();
EntLink = false;
}
public void butRead_Click(System.Object sender, System.EventArgs e)
{
short i = 0;
short re = 0;
object[] RD = null;
RD = new object[int.Parse(txtReadCnt.Text)];
if (!EntLink)
{
MessageBox.Show("还未与PLC建立联接!");
return;
}
int val1 =cmbReadMry.SelectedIndex + 1;
EntFxPlc_ADP .PlcClient .PlcMemory mry = (EntFxPlc_ADP .PlcClient .PlcMemory )val1;
val1 = cmbReadType.SelectedIndex + 1;
EntFxPlc_ADP.PlcClient.DataType typ = (EntFxPlc_ADP .PlcClient .DataType )val1;
re = PLC.CmdRead(PlcHand, mry, typ, System.Convert.ToUInt16(ushort.Parse(txtReadAdd.Text)), System.Convert.ToUInt16(ushort.Parse(txtReadCnt.Text)), ref RD);
txtReRead.Text = re.ToString();
lstRead.Items.Clear();
for (i = 0; i < RD.Length; i++)
{
if (!ReferenceEquals(RD[i], null))
{
lstRead.Items.Add(RD[i]);
}
else
{
lstRead.Items.Add("0");
}
}
}
public void butWrite_Click(System.Object sender, System.EventArgs e)
{
short i = 0;
short re = 0;
string[] temp = null;
object[] WD = null;
if (!EntLink)
{
MessageBox.Show("还未与PLC建立联接!");
return;
}
WD = new object[int.Parse(txtWriteCnt.Text)];
temp = txtWrite.Text.Split('\n');
for (i = 0; i < WD.Length; i++)
{
if (i >= temp.Length)
{
WD[i] = 0;
}
else
{
WD[i] = temp[i].Trim();
}
}
int val1 = cmbWriteMry.SelectedIndex + 1;
EntFxPlc_ADP.PlcClient.PlcMemory mry = (EntFxPlc_ADP.PlcClient.PlcMemory)val1;
val1 = cmbWriteType.SelectedIndex + 1;
EntFxPlc_ADP.PlcClient.DataType typ = (EntFxPlc_ADP.PlcClient.DataType)val1;
re = PLC.CmdWrite(PlcHand, mry, typ, System.Convert.ToUInt16(ushort.Parse(txtWriteAdd.Text)), System.Convert.ToUInt16(ushort.Parse(txtWriteCnt.Text)), ref WD);
txtReWrite.Text = re.ToString();
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询