C#连接三菱PLC
用到的DLL: Interop.ActUtlTypeLib
一、建立项目
用.net4.8
二、引用DLL
三、连接PLC
这个里的逻辑站号怎么来,参照MX的连接配置。
ActUtlTypeClass com_ReferencesUtlType = new ActUtlTypeClass();//建连接对象
com_ReferencesUtlType.ActLogicalStationNumber = 50;//这个是MX的配置逻辑好号
int err = com_ReferencesUtlType.Open();//打开连接
四、读取PLC地址
int num = com_ReferencesUtlType.ReadDeviceBlock2("D9000", 1, out short test);//返回值=ReadDeviceBlock2(PLC地址,读取长度,读取值)
五、需入PLC地址
short test1 = 234;
int nu1 = com_ReferencesUtlType.WriteDeviceBlock2("D9000", 1, ref test1);//返回值=WriteDeviceBlock2(PLC地址,读取长度,写入值)