CP341模块做MODBUS主站通信不用硬件狗程序应该怎么来写,看见网上有好多人说是可以的,就是不知道怎么来做一个模块下有7个欧姆龙的E5EC仪表怎么来进行通信485的接口
问题补充:
哪位大神有CP341的免狗程序我的邮箱1418357061@qq.com不胜感激
最佳答案
安装CP341驱动包,用ASCLL方式通讯,调用FB8、FB7。
把数据放送缓冲区,往数据缓冲区,根据周期时间上升沿触发。
在接受数据块中,设置计数轮询,触发时间计数到几,就发送那部分数据。
//-------------------------------------------------------------------------------------------------------------------------------------------
FUNCTION FC75 : VOID //数据收发
VAR
R_CPU_NO:INT;
R_TYP:CHAR;
R_NO:INT;
R_OFFSET:INT;
R_CF_BYT:INT;
R_CF_BIT:INT;
SET_OUT:BOOL;
N:INT;
END_VAR
BEGIN
FB8.DB75(SF := ''S'' // IN: CHAR
,REQ :=DB80.MC_OUT1 // IN: BOOL
,R := DB80.MC_OUT1=FALSE // IN: BOOL
,LADDR :=416 // IN: INT
,DB_NO :=90 // IN: INT
,DBB_NO :=0 // IN: INT
,LEN :=8 // IN: INT
,R_CPU_NO :=R_CPU_NO // IN: INT
,R_TYP :=R_TYP // IN: CHAR
,R_NO :=R_NO // IN: INT
,R_OFFSET :=R_OFFSET // IN: INT
,R_CF_BYT :=R_CF_BYT // IN: INT
,R_CF_BIT :=R_CF_BIT // IN: INT
);
FB7.DB76(EN_R :=DB80.MC_OUT1 OR DB80.MC_OUT1=FALSE // IN: BOOL
,R := FALSE // IN: BOOL
,LADDR :=416 // IN: INT
,DB_NO :=91 // IN: INT
,DBB_NO :=DB92.JS // IN: INT
);
END_FUNCTION
DATA_BLOCK DB80
STRUCT
ZD_TIME:INT;
MC_OUT1:BOOL;
MC_OUT2:BOOL;
MC_PN:BOOL;
MC_IN:BOOL;
SENT_OUT: BOOL;
END_STRUCT
BEGIN
END_DATA_BLOCK
//--------------------------------------------------------------------------------------------------------------------------------------------------------------
FUNCTION FC80 : VOID //轮询计时
VAR
TIME_BCD1,TIME_BCD2:S5TIME;
OUT_PUT1,OUT_PUT2:BOOL;
N:INT;
END_VAR
BEGIN
TIME_BCD1:= S_ODT (T_NO := T254,S :=DB80.MC_OUT2=FALSE,TV := T#0.2S,Q := DB80.MC_OUT1);
TIME_BCD2:= S_ODT (T_NO := T255,S :=DB80.MC_OUT1,TV := T#0.1S,Q := DB80.MC_OUT2);
DB80.MC_PN:=DB80.MC_OUT1 AND NOT DB80.MC_IN;
DB80.MC_IN:=DB80.MC_OUT1;
IF DB80.MC_PN THEN
DB80.ZD_TIME:=DB80.ZD_TIME+1;
END_IF;
IF DB80.ZD_TIME>4 THEN
DB80.ZD_TIME:=0;
END_IF;
END_FUNCTION
DATA_BLOCK DB90 //发送
STRUCT
SENT:ARRAY[1..8] OF BYTE;
END_STRUCT
BEGIN
END_DATA_BLOCK
DATA_BLOCK DB91 //接收
STRUCT
RCV1:ARRAY[1..30] OF BYTE;
RCV2:ARRAY[1..30] OF BYTE;
RCV3:ARRAY[1..30] OF BYTE;
RCV4:ARRAY[1..30] OF BYTE;
END_STRUCT
BEGIN
END_DATA_BLOCK
DATA_BLOCK DB92//
STRUCT
JS:INT;
END_STRUCT
BEGIN
END_DATA_BLOCK
FUNCTION FC95 : VOID //发送区
IF DB80.ZD_TIME=1 THEN
DB90.SENT[1]:=B#16#01;
DB90.SENT[2]:=B#16#03;
DB90.SENT[3]:=B#16#05;
DB90.SENT[4]:=B#16#00;
DB90.SENT[5]:=B#16#00;
DB90.SENT[6]:=B#16#04;
DB90.SENT[7]:=B#16#44;
DB90.SENT[8]:=B#16#C5;
DB92.JS:=0;
ELSIF DB80.ZD_TIME=2 THEN
DB90.SENT[1]:=B#16#02;
DB90.SENT[2]:=B#16#03;
提问者对于答案的评价:
谢谢,我试一下
原创文章,作者:more0621,如若转载,请注明出处:https://www.zhaoplc.com/plc130678.html