环境:打开三菱PLC安装目录下,Act>Samples>Vcs.NET>Sample2010>bin>Debug目录下分别加载以下 dll(全部都加载是为了后续开发需要用到)
准备工作:
打开官方提供的Sample2010(在Act>Samples>Vcs.NET目录下)将图中两个控件copy到自己的项目中
代码:
#region 建立连接
//连接
private void button1_Click(object sender, EventArgs e)
{
//逻辑站
axActUtlType1.ActLogicalStationNumber = int.Parse(this.textBox1.Text);
//密码
axActUtlType1.ActPassword = this.textBox2.Text;
//打开plc
int status = axActUtlType1.Open();
if (status == 0)
{
LoadInputPage(iniPath, ref butList);
LoadOutputPage(iniPath, ref butList);
Monitor_IO(butList);
MessageBox.Show("连接成功!");
}
}
//断开连接
private void button2_Click(object sender, EventArgs e)
{
axActUtlType1.Close();
}
#endregion
完整项目另见:https://blog.csdn.net/weixin_44490080/article/details/102919269