HanaH

Beckhoff Twincat 3 Modbus RTU setup help wanted

1 post in this topic

Hi all,

New to the forum. I've been pretty much able to do the things I wanted with Beckhoff, but now I'm finally running into a problem I can't seem to solve alone.

I'm trying to set-up Modbus RTU RS485 communication in Twincat3, using an EL6021. I've implemented a sample program from the Beckhoff website, but can't get it to work. I've got the feeling I need to properly set up the EL6021 but most information on the Beckhoff website is about the KL-series IO. Does anybody have experience with this?

The strange thing is that, when I enable the function to read some slave's registers, BUSY is set and remains set. No timeout is triggered. I don't have a slave connected yet but I would at least expect to see something on the output of the terminal, and then a timeout. I've bridged TxD+ and RxD+, and TxD- and RxD- and set 8000:06 of the EL6021 TRUE, half duplex mode enabled). A scope connected to TxD+ and TxD- shows nothing.

Code added below. I've added a GVL called 'Variable_Configuration' with the following:

VAR_CONFIG
    Main.MB.InData AT %IB0 : MB_KL6inData5B;
    Main.MB.OutData AT %QB0 : MB_KL6outData5B;
END_VAR

And then the MAIN:

PROGRAM MAIN
VAR
    bIoSyncMaster AT %I* : BOOL;
    MB : ModbusRTUmaster_KL6x5B;
    MBLedDriver : ARRAY[1..10] OF WORD;
    tmpExecute : BOOL;
    bError : BOOL;
    bBusy : BOOL;
    iErrorId: MODBUS_ERRORS;
    iNoDatByteRead: UINT;
    count: INT;
    freebyte: INT;
    TxError: INT;
    TxBlocked: BOOL;
END_VAR

MB(
    UnitID:= 41,
    Quantity:= 4,
    MBAddr:= 16#0020,
    cbLength:= SIZEOF(MBLedDriver),
    pMemoryAddr:= ADR(MBLedDriver),
    Execute:= tmpExecute,
    Timeout:= T#5S ,
    BUSY=> bBusy,
    Error=> bError,
    ErrorId=> iErrorId,
    cbRead=> iNoDatByteRead);
    
MB.ReadRegs();

count := MB.MBMaster.com.Buffer.Tx.count;
freebyte := MB.MBMaster.com.Buffer.Tx.FreeByte;
TxError := MB.MBMaster.com.Buffer.Tx.Error;
TxBlocked := MB.MBMaster.com.Buffer.Tx.Blocked;

tmpExecute:=FALSE;

 

 

Edited by HanaH
typo on terminal name

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now