汇川AM600与基恩士DL-EN1的TCPIP通讯
硬件
汇川AM600中型PLC
基恩士DL-EN1通讯模块+1L-1000(放大器)+1L-1050(放大器)
基恩士
1、连接网线,可直接DL-EN1连接至AM600的EtherNET接口,或者通过交换机连接
2、通过IP Setting Tool工具设置DL-EN1的网路地址,先扫描出硬件,再设置IP,本例设置192.168.1.20
IP Setting Tool工具可通过基恩士下载
3、设置完成后最好通过CMD 测试一下
WIN+R 输入CMD 回车输入ping 192.168.1.20
基恩士命令格式
程序
AM600不需要进行任何硬件配置,默认网址192.168.1.88 直接上程序
1、添加程序组织单元,创建TCPIP程序
2、建立变量编写程序
变量,可直接复制
PROGRAM TCPIP
c tcpip协议VAR
TCP_Client1:TCP_Client;
TCP_Client1_xEnale:BOOL;
TCP_Client1_strIpAddrDst: STRING;
TCP_Client1_uiPortDst: UINT;
TCP_Client1_xDone:BOOL;
TCP_Client1_xBusy:BOOL;
TCP_Client1_xError:BOOL;
TCP_Client1_dwErrorID:DWORD;
TCP_Client1_xActive:BOOL;
TCP_Client1_hConnection: __XWORD;
TCP_Send1:TCP_Send;
TCP_Send1_xExecute:BOOL;
TCP_Send1_uiSize: UINT;
TCP_Send1_pbyData1:STRING;
TCP_Send1_pbyData: POINTER TO BYTE;
TCP_Send1_xDone: BOOL;
TCP_Send1_xBusy: BOOL;
TCP_Send1_xError: BOOL;
TCP_Send1_dwErrorID: DWORD;
TCP_Receive1:TCP_Receive;
TCP_Receive1_xEnable: BOOL;
TCP_Receive1_uiSize: UINT;
TCP_Receive1_pbyData1:STRING;
TCP_Receive1_pbyData: POINTER TO BYTE;
TCP_Receive1_xDone: BOOL;
TCP_Receive1_xBusy: BOOL;
TCP_Receive1_xError: BOOL;
TCP_Receive1_dwErrorID: DWORD;
TCP_Receive1_xReady: BOOL;
TCP_Receive1_uiCount: __UXINT;
DanceFeedBack1:REAL;
数据起始结束位置:INT;
DanceFeedBack2:REAL;
通讯建立成功:BOOL;
传输开始沿检测:R_TRIG;
数据传输步骤:INT;
END_VAR
程序,可直接复制
T TCP_Client1_strIpAddrDst:='192.168.1.20'; //*服务器IP地址
TCP_Client1_uiPortDst:=64000; //*基恩士服务器端口号,可通过基恩士手册查看
TCP_Client1_xEnale:=TRUE;
TCP_Client1( //调用客户端功能块
xEnable:= TCP_Client1_xEnale, //上升沿重新触发,正常工作需常为TRUE
strIpAddrDst:= TCP_Client1_strIpAddrDst, //*服务器IP地址
uiPortDst:=TCP_Client1_uiPortDst, //*服务器端口号
udiTimeOut:= 500000,
xDone=> TCP_Client1_xDone,
xBusy=> TCP_Client1_xBusy,
xError=> TCP_Client1_xError,
dwErrorID=> TCP_Client1_dwErrorID,
xActive=> TCP_Client1_xActive, //正常工作时,TCP_Client1_xBusy与TCP_Client1_xBusy为TRUE
hConnection=> TCP_Client1_hConnection);
IF TCP_Client1_xActive AND
TCP_Client1_xBusy AND
NOT TCP_Client1_xDone AND
NOT TCP_Client1_xError THEN
通讯建立成功:=TRUE;
TCP_Receive1_xEnable:=TRUE; //通讯建立成功,直接使能接收功能块
ELSE
通讯建立成功:=FALSE;
TCP_Send1_xExecute:=FALSE;
TCP_Receive1_xEnable:=FALSE;
数据传输步骤:=0;
END_IF;
传输开始沿检测(CLK:= 通讯建立成功AND TCP_Receive1_xBusy, Q=> ); //TCP_Receive1_xBusy为TRUE 接收功能块已启动
IF 传输开始沿检测.Q THEN
数据传输步骤:=1; //在通讯建立且接收功能块已启动后,进入数据读取循环END_IF;
CASE 数据传输步骤OF
0:
TCP_Send1_xExecute:=FALSE;
1:
TCP_Send1_xExecute:=TRUE;
数据传输步骤:=2;
2:
IF TCP_Send1_xDone THEN
TCP_Send1_xExecute:=FALSE;
数据传输步骤:=3;
END_IF;
3:
IF TCP_Receive1_xReady THEN
数据传输步骤:=1;
END_IF;
END_CASE
TCP_Send1_pbyData1:='M0$R$N'; //格式‘M 0 CR LF’,CR ‘$R’,LF ‘$N’固定格式可通过基恩士手册查询
TCP_Send1_uiSize:=4;
TCP_Send1(
xExecute:= TCP_Send1_xExecute,
hConnection:= TCP_Client1_hConnection,
uiSize:= TCP_Send1_uiSize,
pbyData:= ADR(TCP_Send1_pbyData1),
udiTimeOut:= 500000,
xDone=> TCP_Send1_xDone,
xBusy=> TCP_Send1_xBusy,
xError=> TCP_Send1_xError,
dwErrorID=> TCP_Send1_dwErrorID);
TCP_Receive1_uiSize:=30;
TCP_Receive1(
xEnable:= TCP_Receive1_xEnable,
hConnection:= TCP_Client1_hConnection,
uiSize:= TCP_Receive1_uiSize,
pbyData:= ADR(TCP_Receive1_pbyData1),
xDone=> TCP_Receive1_xDone,
xBusy=> TCP_Receive1_xBusy,
xError=>TCP_Receive1_xError,
dwErrorID=> TCP_Receive1_dwErrorID,
xReady=> TCP_Receive1_xReady,
uiCount=>TCP_Receive1_uiCount );
数据起始结束位置:=FIND(STR1:=TCP_Receive1_pbyData1,STR2:='$R');//返回数据格式M0,±000000000,±000000000$R$N 26byte
DanceFeedBack2:=STRING_TO_REAL(MID(STR:=TCP_Receive1_pbyData1,LEN:=10,POS:=4))/100.0; //查阅指令手册,MID指令
DanceFeedBack1:=STRING_TO_REAL(MID(STR:=TCP_Receive1_pbyData1,LEN:=10,POS:=15))/100.0; //截取从第15byte开始的长度为10byte的字符串测试结果连续变化的测量值,提醒一下需要在主程序中调用TCPIP
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。
发表评论