前言有小伙伴问:ABB机器人实现了Modbus通讯后,数据传输问题解决了,但是怎么样能实现IO功能呢?那么今天给大家分享一下Modbus slave模式下的 IO映射案例。功能演示
video: https://mp.weixin.qq.com/mp/readtemplate?t=pages/video_player_tmpl&action=mpvideo&auto=0&vid=wxv_3149812478416060418虚拟IO的创建与关联创建虚拟do信号(数量根据需要而定)。
创建虚拟di信号(数量根据需要而定)。
创建用于关联di使用的虚拟do信号,这里我命名为Ass信号(数量根据di信号而定)。将Ass信号与di信号关联。
当然你也可以使用这份EIO.CFG文件作为参考,将下列代码复制另存为后缀.cfg文件。EIO:CFG_1.0:6:1::#EIO_CROSS:
-Name "ASS1" -Res "Modbus_DI1" -Act1 "Modbus_ASS1"
-Name "ASS2" -Res "Modbus_DI2" -Act1 "Modbus_ASS2"
-Name "ASS3" -Res "Modbus_DI3" -Act1 "Modbus_ASS3"
-Name "ASS4" -Res "Modbus_DI4" -Act1 "Modbus_ASS4"
-Name "ASS5" -Res "Modbus_DI5" -Act1 "Modbus_ASS5"
-Name "ASS6" -Res "Modbus_DI6" -Act1 "Modbus_ASS6"
-Name "ASS7" -Res "Modbus_DI7" -Act1 "Modbus_ASS7"
-Name "ASS8" -Res "Modbus_DI8" -Act1 "Modbus_ASS8"
-Name "ASS9" -Res "Modbus_DI9" -Act1 "Modbus_ASS9"
-Name "ASS10" -Res "Modbus_DI10" -Act1 "Modbus_ASS10"
-Name "ASS11" -Res "Modbus_DI11" -Act1 "Modbus_ASS11"
-Name "ASS12" -Res "Modbus_DI12" -Act1 "Modbus_ASS12"
-Name "ASS13" -Res "Modbus_DI13" -Act1 "Modbus_ASS13"
-Name "ASS14" -Res "Modbus_DI14" -Act1 "Modbus_ASS14"
-Name "ASS15" -Res "Modbus_DI15" -Act1 "Modbus_ASS15"
-Name "ASS16" -Res "Modbus_DI16" -Act1 "Modbus_ASS16"#EIO_SIGNAL:
-Name "Modbus_ASS1" -SignalType "DO" -Label "modbus slave"
-Name "Modbus_ASS2" -SignalType "DO" -Label "modbus slave"
-Name "Modbus_ASS3" -SignalType "DO" -Label "modbus slave"
-Name "Modbus_ASS4" -SignalType "DO" -Label "modbus slave"
-Name "Modbus_ASS5" -SignalType "DO" -Label "modbus slave"
-Name "Modbus_ASS6" -SignalType "DO" -Label "modbus slave"
-Name "Modbus_ASS7" -SignalType "DO" -Label "modbus slave"
-Name "Modbus_ASS8" -SignalType "DO" -Label "modbus slave"
-Name "Modbus_ASS9" -SignalType "DO" -Label "modbus slave"
-Name "Modbus_ASS10" -SignalType "DO" -Label "modbus slave"
-Name "Modbus_ASS11" -SignalType "DO" -Label "modbus slave"
-Name "Modbus_ASS12" -SignalType "DO" -Label "modbus slave"
-Name "Modbus_ASS13" -SignalType "DO" -Label "modbus slave"
-Name "Modbus_ASS14" -SignalType "DO" -Label "modbus slave"
-Name "Modbus_ASS15" -SignalType "DO" -Label "modbus slave"
-Name "Modbus_ASS16" -SignalType "DO" -Label "modbus slave"
-Name "Modbus_DI1" -SignalType "DI" -Label "modbus slave"
-Name "Modbus_DI2" -SignalType "DI" -Label "modbus slave"
-Name "Modbus_DI3" -SignalType "DI" -Label "modbus slave"
-Name "Modbus_DI4" -SignalType "DI" -Label "modbus slave"
-Name "Modbus_DI5" -SignalType "DI" -Label "modbus slave"
-Name "Modbus_DI6" -SignalType "DI" -Label "modbus slave"
-Name "Modbus_DI7" -SignalType "DI" -Label "modbus slave"
-Name "Modbus_DI8" -SignalType "DI" -Label "modbus slave"
-Name "Modbus_DI9" -SignalType "DI" -Label "modbus slave"
-Name "Modbus_DI10" -SignalType "DI" -Label "modbus slave"
-Name "Modbus_DI11" -SignalType "DI" -Label "modbus slave"
-Name "Modbus_DI12" -SignalType "DI" -Label "modbus slave"
-Name "Modbus_DI13" -SignalType "DI" -Label "modbus slave"
-Name "Modbus_DI14" -SignalType "DI" -Label "modbus slave"
-Name "Modbus_DI15" -SignalType "DI" -Label "modbus slave"
-Name "Modbus_DI16" -SignalType "DI" -Label "modbus slave"
-Name "Modbus_DO1" -SignalType "DO" -Label "modbus slave"
-Name "Modbus_DO2" -SignalType "DO" -Label "modbus slave"
-Name "Modbus_DO3" -SignalType "DO" -Label "modbus slave"
-Name "Modbus_DO4" -SignalType "DO" -Label "modbus slave"
-Name "Modbus_DO5" -SignalType "DO" -Label "modbus slave"
-Name "Modbus_DO6" -SignalType "DO" -Label "modbus slave"
-Name "Modbus_DO7" -SignalType "DO" -Label "modbus slave"
-Name "Modbus_DO8" -SignalType "DO" -Label "modbus slave"
-Name "Modbus_DO9" -SignalType "DO" -Label "modbus slave"
-Name "Modbus_DO10" -SignalType "DO" -Label "modbus slave"
-Name "Modbus_DO11" -SignalType "DO" -Label "modbus slave"
-Name "Modbus_DO12" -SignalType "DO" -Label "modbus slave"
-Name "Modbus_DO13" -SignalType "DO" -Label "modbus slave"
-Name "Modbus_DO14" -SignalType "DO" -Label "modbus slave"
-Name "Modbus_DO15" -SignalType "DO" -Label "modbus slave"
-Name "Modbus_DO16" -SignalType "DO" -Label "modbus slave"
后台程序编写
加载下面两个链接源码,建议开通Multitask 623-1功能选项,实现实时后台刷新。
ABB机器人Modbus(Master与Slave)源码分享
ABB机器人Socket模块更新(支持最大32路信道同时收发)
主程序示例
!.Demo of the modbus slave function.PROCMain()VARrawbytessnd_raw;VAR rawbytes rcv_raw; SocketCreateConn 1,"127.0.0.1",503\Server;WHILETRUEDOIF CheckSocket(1)>1 THEN SocketReceiveData 1\RawData:=snd_raw; ReplyModbusSlaveMsg snd_raw,rcv_raw; SocketSendData 1\RawData:=rcv_raw; MappingIO;ENDIFENDWHILE ENDPROC !.Map virtual IO. PROC MappingIO()VAR signaldo ass1{16};VAR signaldo out1{16};VAR string str{2};FOR i FROM 1 TO 16DO str{1}:="Modbus_ASS"+ValToStr(i); str{2}:="Modbus_DO"+ValToStr(i); AliasIO str{1},ass1{i}; AliasIO str{2},out1{i}; SetDO ass1{i},ModbusCoil{i}; ModbusInputCoil{i}:=DOutput(out1{i});ENDFOR ENDPROC |