更多内容请点击上方 ABB机器人实战技巧 关注
也可点击公众号下方 往期经典 浏览更多内容
转载请先后台留言,大家一起支持原创,推动机器人使用和发展
本公众号对各类ABB机器人应用,仿真,毕业设计提供技术支持,详细后台留言
本公众号诚挚希望与各机器人培训机构,机器人使用单元合作,提供技术支持,详细后台留言
1.ABB机器人未直接提供ModbusTCP主站功能。需要用户根据定义自行编写。
2.modbusTCP主站一般包括对从站的线圈读写和寄存器读写,以下代码实现了功能码:
0x01 读多线圈,
0x03 读保持寄存器,
0x05 写单个线圈,
0x06 写单个寄存器
0x0F 写多个线圈
0x10 写多个寄存器
MODULEmodbusTCP_Master!author: Liao Chen, mousechen17@163.com !!!!!!! support holding register !!!!!!! support holding coil !!!!!!! support 0x03 0x06 0x10 0x01 0x05 0x0F function
VARsocketdev sock_mod;VARrawbytes recv_raw;VARrawbytes send_raw; !!!!!! data need to be modifiedPERSbool bBigEndian:=TRUE;PERSstring slave_ip:="127.0.0.1";PERSnum slave_ID:=1;PERSnum write_data{2}:=[10,20];varnum read_data{2}:=[0,0];PERSnum write_coils{20}:=[1,1,1,1,0,1,1,1,1,0,1,1,1,1,0,1,1,1,1,0];varnum read_coils{20};PERSnum regAdd:=1;VARnum outValue{50};
PROCmain()writeMultiRegregAdd,2,write_data; ! 向地址1开始的2个寄存器写入数据,数据为write_data中的前2个数据readMultiReg1,2,read_data; ! 从地址1开始的2个寄存读取数据,存入read_data中的前2个数据stop;
writeSingRegregAdd,99; ! 向地址regAdd的寄存器写入数据99readMultiReg1,1,read_data; ! 从地址1开始的1个寄存器,读取数据并存储到readdata中第一个元素stop;writeMultiCoilregAdd,10,write_coils; ! 向地址regAdd开始的连续10个线圈写入值readMultiCoilregAdd,10,read_coils; ! 从regAdd开始的10个线圈读取值并存储到read_coils数组中stop;writeSingCoilregAdd,0; ! 向地址regAdd线圈写入值0readMultiCoilregAdd,1,read_coils; ! 从regAdd开始的1个线圈读取值并存储到read_coils数组中的第一个元素stop;ENDPROC
PROCcheckSocket()ifSocketGetStatus(sock_mod)<>SOCKET_CONNECTED THENSocketClosesock_mod;SocketCreatesock_mod;SocketConnectsock_mod,slave_ip,502\Time:=10;endifENDPROC
PROCwriteMultiCoil(num regAdd,num coilCount,num coils{*}) ! funNo: 0x0F: write multi Coil ! device send: 00 01 00 00 00 09 01 0F 0005 000A 02 CD 01 ! ttl data len slaveID funNo add coil_count byte_len byte1 byte2 ! robot feedback: 0000 0000 0006 01 0F 0005 000A ! ttl data len slaveID funNo add coil_num !VAR num outValue{50};VARnum byteCount:=1;VARnum b{100};checkSocket;b{1}:=0x00;b{2}:=0x00;b{3}:=0x00;b{4}:=0x00; ! b{5}:=0x00; ! b{6}:=0x06;b{7}:=slave_ID;b{8}:=0x0F;
ClearRawBytessend_raw;FORi FROM 1 TO 8 DOPackRawBytesb{i},send_raw,i\IntX:=1;ENDFORPackRawBytesregAdd,send_raw\Network,9\IntX:=2;PackRawBytescoilCount,send_raw\Network,11\IntX:=2;
FORi FROM 1 TO coilCount DOoutValue{byteCount}:=outValue{byteCount}+coils{i}*pow(2,(i-1) mod 8);IF(i mod 8)=0 THENbyteCount:=byteCount+1;ENDIFENDFOR
FORi FROM 1 TO byteCount DOPackRawBytesoutValue{i},send_raw\Network,13+i\IntX:=1;ENDFORPackRawBytesbyteCount,send_raw\Network,13\IntX:=1;PackRawBytes7+byteCount,send_raw\Network,5\IntX:=2;sendAndReceive;ENDPROC
PROCsendAndReceive()SocketSendsock_mod\RawData:=send_raw;SocketReceivesock_mod\RawData:=recv_raw;ENDPROC
PROCwriteSingCoil(num regAdd,num data\switch bSiemens) ! funNo: 0x05: write single coil ! device send: 0000 0000 0006 01 05 0002 FF00 ! ttl data len slaveID funNo add data(FF00:ON, 0000:OFF) ! robot feedback: 0000 0000 0006 01 05 0002 FF00 ! ttl data len slaveID funNo add data
VARnum b{100};checkSocket;b{1}:=0x00;b{2}:=0x00;b{3}:=0x00;b{4}:=0x00;b{5}:=0x00;b{6}:=0x06;b{7}:=slave_ID;b{8}:=0x05;
ClearRawBytessend_raw;FORi FROM 1 TO 8 DOPackRawBytesb{i},send_raw,i\IntX:=1;ENDFORPackRawBytesregAdd,send_raw\Network,9\IntX:=2;IFdata>0 THENdata:=0xFF00;ENDIF
IFPresent(bSiemens) THENPackRawBytesdata,send_raw,11\IntX:=2;ELSEPackRawBytesdata,send_raw\Network,11\IntX:=2;ENDIFsendAndReceive;ENDPROC
PROCreadMultiCoil(num regAdd,num coilCount,inout num coils{*}) ! funNo: 0x01: read multi Coil ! device send: 00 00 00 00 00 06 01 01 0002 0002 ! ttl data len slaveID funNo add coil_num ! robot feedback: 0000 0000 0004 01 01 01 01 ! ttl data len slaveID funNo rest_data_len data
VARbyte inValue;VARnum byteCount:=1;VARnum tmpValue;VARnum b{100};checkSocket;b{1}:=0x00;b{2}:=0x00;b{3}:=0x00;b{4}:=0x00;b{5}:=0x00;b{6}:=0x06;b{7}:=slave_ID;b{8}:=0x01;
ClearRawBytessend_raw;FORi FROM 1 TO 8 DOPackRawBytesb{i},send_raw,i\IntX:=1;ENDFORPackRawBytesregAdd,send_raw\Network,9\IntX:=2;PackRawBytescoilCount,send_raw\Network,11\IntX:=2;sendAndReceive;FORi FROM 1 TO coilCount DOIF(i mod 8)=1 THENUnPackRawBytesrecv_raw\Network,9+byteCount,tmpValue\IntX:=USINT;inValue:=tmpValue;byteCount:=byteCount+1;ENDIFcoils{i}:=bitand(inValue,1);inValue:=BitRSh(inValue,1);ENDFORENDPROC
PROCreadMultiReg(num regAdd,num regCount,inout num data{*}\switch bSiemens) ! funNo: 0x03: read multi holding register ! device send: 0000 0000 0006 01 03 0001 0001 ! ttl data len slaveID funNo add data_num ! robot feedback: 0000 0000 0005 01 03 02 0001 ! ttl data len slaveID funNo rest_data_len dataVARnum b{100};VARnum dataByteLen;checkSocket;b{1}:=0x00;b{2}:=0x00;b{3}:=0x00;b{4}:=0x00;b{5}:=0x00;b{6}:=0x06;b{7}:=slave_ID;b{8}:=0x03;
ClearRawBytessend_raw;FORi FROM 1 TO 8 DOPackRawBytesb{i},send_raw,i\IntX:=1;ENDFORPackRawBytesregAdd,send_raw\Network,9\IntX:=2;PackRawBytesregCount,send_raw\Network,11\IntX:=2;sendAndReceive;
UnPackRawBytesrecv_raw\Network,9,dataByteLen\IntX:=UsINT;FORi FROM 1 TO dataByteLen/2 DOIFpresent(bSiemens) THENUnPackRawBytesrecv_raw,9+(2*i-1),data{i}\IntX:=UINT;ELSEUnPackRawBytesrecv_raw\Network,9+(2*i-1),data{i}\IntX:=UINT;ENDIFENDFORENDPROC
PROCwriteMultiReg(num regAdd,num regCount,num data{*}\Switch bSiemens) ! funNo: 0x10: write multi holding register ! device send: 0000 0000 000B FF 10 0002 0002 04 0021 002A ! ttl_data_len id funNo add data_num rest_data_len data1 data2 ! robot feedback: 0000 0000 0006 FF 10 0002 00 02 ! ttl_data_len id funNo add data_num
VARnum b{100};VARnum value;VARnum dataByteLen;checkSocket;b{1}:=0x00;b{2}:=0x00;b{3}:=0x00;b{4}:=0x00; ! b{5}:=0x00; ! b{6}:=0x06;b{7}:=slave_ID;b{8}:=0x10;
ClearRawBytessend_raw;FORi FROM 1 TO 8 DOPackRawBytesb{i},send_raw,i\IntX:=1;ENDFORPackRawBytesregAdd,send_raw\Network,9\IntX:=2;PackRawBytesregCount,send_raw\Network,11\IntX:=2;PackRawBytesregCount*2,send_raw\Network,13\IntX:=1;
FORi FROM 1 TO regCount DOIFPresent(bSiemens) THENPackRawBytesdata{i},send_raw,13+(2*i-1)\IntX:=2;ELSEPackRawBytesdata{i},send_raw\Network,13+(2*i-1)\IntX:=2;ENDIF
ENDFORPackRawBytes7+regCount*2,send_raw\Network,5\IntX:=2;sendAndReceive;ENDPROC
PROCwriteSingReg(num regAdd,num data\switch bSiemens) ! funNo: 0x06: write single holding register ! device send: 0000 0000 0006 01 06 0001 0001 ! ttl data len slaveID funNo add data ! robot feedback: 0000 0000 0006 01 06 0001 0001 ! ttl data len slaveID funNo add dataVARnum b{100};VARnum value;VARnum dataByteLen;checkSocket;b{1}:=0x00;b{2}:=0x00;b{3}:=0x00;b{4}:=0x00;b{5}:=0x00;b{6}:=0x06;b{7}:=slave_ID;b{8}:=0x06;
ClearRawBytessend_raw;FORi FROM 1 TO 8 DOPackRawBytesb{i},send_raw,i\IntX:=1;ENDFORPackRawBytesregAdd,send_raw\Network,9\IntX:=2;IFPresent(bSiemens) THENPackRawBytesdata,send_raw,11\IntX:=2;ELSEPackRawBytesdata,send_raw\Network,11\IntX:=2;endifsendAndReceive;ENDPROCENDMODULE
********************************
如何获取更多经典文章?
关注公众号 ABB机器人实战技巧,点击页面底部的往期经典和配置,查看更多经典内容
点击阅读原文,学习robotstudio仿真,获取完整教学视频
更多内容
★ 如何搜索历史文章
★基于pcsdk传输文件到HOME及加载
通过总线发送实数及负整数
★使用定时中断向PLC发送机器人位置
★信号的准确提早触发
★变位机校准
★ABB机器人零位校准的那些秘密
★创建UDP通讯
★旋转姿态的左乘与右乘
★通过socket控制机器人启停
上位机仪表盘实时显示机器人速度
★机器人画哆啦A梦
上位机实时控制机器人运动之EGM
Python控制ABB机器人运动
通过Excel批量修改EIO文件
带连杆的机器人正运动学计算
制作四连杆机构
机器人PROFINET同时做CONTROLLER和DEVICE
★语音控制ABB机器人
★手机访问web控制机器人
★自定义伺服焊枪
★制作输送链抓取搬运码垛工作站
★随机物料产生与抓取
★四轴机器人定义TCP
★自定义外部轴-变位机
★示教四点完成码垛
★multimove之双机器人与变位机
Robotware6.08碰撞预测启用与关闭
SMB板针脚解释
四六关节耦合限制
求两点间距离
新I/O DSQC1030配置
ABB机器人配置伺服焊枪
转角路径故障不提示设置
外部PLC选择机器人程序
一键回HOME程序
机器人各轴上下限位修改
Wobjdata数据解释
输送链跟踪与视觉的联系
急停与自动停止接线
更多大牛讲解视频,可以微信搜索ABB机器人实战技巧,或者扫描以下二维码关注
|