Problem with Beckhoff BC9000 + KL6021

M

Thread Starter

mr24

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?

<i>
<pre>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</pre></i>
<b>and the code:</b>
<i><pre>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</pre></i>

<b>Globul variables is:</b>
<pre><i>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</pre></i>

<b>And variable configuration is</b>

<pre><i>
pr.MB.InData AT %IB1 : ModbusKL6inData5B;
pr.MB.OutData AT %QB1 : ModbusKL6outData5B;
END_VAR</pre></i>
 
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.
 
Top