Hello
I am beginner and I have a job with controller BC9000 of Beckhoff. I must read data on rs-485. I use module KL6021. I load example program from help of beckhoff, but I change my parameters. But it,s not working. I throw DOUBT on module KL6021. Its 3 leads glisten always. It is normal?
I add to program KL6configuration and my code is show down. State Busy of KL6configuration and ModbusRtuMaster_KL6x5B is already busy. Why?
and the code:
Globul variables is:
And variable configuration is
I am beginner and I have a job with controller BC9000 of Beckhoff. I must read data on rs-485. I use module KL6021. I load example program from help of beckhoff, but I change my parameters. But it,s not working. I throw DOUBT on module KL6021. Its 3 leads glisten always. It is normal?
I add to program KL6configuration and my code is show down. State Busy of KL6configuration and ModbusRtuMaster_KL6x5B is already busy. Why?
PROGRAM pr
VAR
flag: BOOL := TRUE;
Conf: KL6configuration;
MBdataMy: UINT;
tempData: INT;
MBdata: ARRAY[0..99] OF WORD; (* The size of this array can be adapted to the modbus slaves register area *)
MBd: WORD;
ModbusAddress: ARRAY[1..23] OF BYTE := 1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23; (* for 23 slaves *)
MB: ModbusRtuMaster_KL6x5B;
timeoutvalue: TIME := T#300ms;
busy: BOOL;
state: INT;
tick: DWORD; (* statistical data *)
lasttick: DWORD; (* statistical data *)
ModbusCycle: TIME;
Unit: BYTE;
temp: UINT;
tempo: BYTE;
doneKL: BOOL;
errorKL: BOOL;
busyKL: BOOL;
donewrite: BOOL;
busywrite: BOOL;
END_VAR
VAR CONSTANT
Mode : MBserialLineMode_t := MBSERIALLINEMODE_KL6_5B_STANDARD;
END_VAR
and the code:
MB.ReadRegs(Execute:= FALSE);
IF flag THEN
Conf(
Execute:= TRUE,
Mode := SERIALLINEMODE_KL6_5B_STANDARD,
Baudrate := 9600,
NoDatabits := 8,
Parity := PARITY_NONE,
Stopbits := 1,
Handshake := RS485_HALFDUPLEX,
ContinousMode := TRUE,
pComIn := ADR( pr.MB.InData),
pComOut := ADR(pr.MB.OutData ),
SizeComIn :=SIZEOF(pr.MB.InData),
Done => doneKL,
Busy => busyKL,
Error => errorKL);
MB.ReadRegs(
UnitID:= ModbusAddress[23], (* station address *) (*UnitID:= ModbusAddress[Unit], *)
Quantity:= 1, (* WORDs *)
MBAddr:= 2306, (*Adres na registara, koito 6te se 4ete ot slave-a*)
cbLength:=2 , (* 1 words (cbLength>=Quantity*2)*)
pMemoryAddr:= ADR(MBd),
Execute:= TRUE,
Timeout:= timeoutvalue,
Busy => busy );
flag := FALSE;
END_IF
IF NOT busy THEN
MB.ReadRegs(Execute:= FALSE);
state := 0;
flag := TRUE;
END_IF
Globul variables is:
VAR_GLOBAL
Term_2_KL6021_S_State AT %IB0: USINT;
Term_2_KL6021_S_Data_In_0 AT %IB1: USINT;
Term_2_KL6021_S_Data_In_1 AT %IB2: USINT;
Term_2_KL6021_S_Data_In_2 AT %IB3: USINT;
Term_2_KL6021_S_Data_In_3 AT %IB4: USINT;
Term_2_KL6021_S_Data_In_4 AT %IB5: USINT;
Term_2_KL6021_S_Ctrl AT %QB0: USINT;
Term_2_KL6021_S_Data_Out_0 AT %QB1: USINT;
Term_2_KL6021_S_Data_Out_1 AT %QB2: USINT;
Term_2_KL6021_S_Data_Out_2 AT %QB3: USINT;
Term_2_KL6021_S_Data_Out_3 AT %QB4: USINT;
Term_2_KL6021_S_Data_Out_4 AT %QB5: USINT;
END_VAR
And variable configuration is
pr.MB.InData AT %IB1 : ModbusKL6inData5B;
pr.MB.OutData AT %QB1 : ModbusKL6outData5B;
END_VAR
You could try posting this question on the TwinCAT Developers forum on LinkedIn http://www.linkedin.com/groups?gid=1860933
Thank you for the link
Have you set the KL6021 card up in KS2000. By default the KL6021 card is in 3 byte alternate mode with 9600 baud rate. You need to change this to 5 byte mode with standard (Uncheck the alternate mode check box). Then I see you are using modbus, but you have created 2 sets of link variables. You only need the variable in the variable configuration. So delete your global variable items. Once you have those done then your busy light should only come on when the Function block is busy. Hope that helps.
Your use of this site is subject to the terms and conditions set forth under Legal Notices and the Privacy Policy. Please read those terms and conditions carefully. Subject to the rights expressly reserved to others under Legal Notices, the content of this site and the compilation thereof is © 1999-2010 Nerds in Control, LLC. All rights reserved.
Users of this site are benefiting from open source technologies, including PHP, MySQL and Apache. Be happy.
Fortune
"An ounce of prevention is worth a pound of purge."







