Welcome to our new forum
All users of the legacy CODESYS Forums, please create a new account at account.codesys.com. But make sure to use the same E-Mail address as in the old Forum. Then your posts will be matched. Close

Sending Sequential Modbus TCP Packets

Edward
2024-03-06
2024-03-08
  • Edward - 2024-03-06

    I have a Modbus TCP slave device where I need to do sequential writes to the same register.
    The register I'm writing to is kind of like a command line, each packet is a command word encoded in Hexadecimal.

    I am having difficulty implementing this system in CoDeSys 3.5 SP19. I feel like the structure of the program should be something along the lines of (Pseudocode):

    ModbusTCPSend(Command Register, Command1)
    ModbusTCPSend(Command Register, Command2)
    ModbusTCPSend(Command Register, Command3)
    

    I have tried to implement this with a rising edge trigger

    wMot1OPCode := 16#E1; //Stop Motor & Kill Program
    xMot1SendOP := TRUE; //Send OP on rising edge
    xMot1SendOP := FALSE; //Reset
    wMot1OPCode := 16#9E; //Disable Motor
    xMot1SendOP :=TRUE; //Send OP on rising edge
    xMot1SendOP := FALSE; //Reset
    

    Where "wMot1OPCode" is the IO map for writing to the command register, and "xMot1SendOP" is the rising edge trigger for that modbus channel.
    However, this doesn't work. The device never responds to the modbus commands. It seems like the trigger variable is switched too quickly for modbus to send the packet.

    I know the modbus register is working, because I can set the channel to cyclic and the device will respond. However, I can't use this reliably because I need each command to be sent once, in order. Cyclic keeps re-sending the commands and seems like it could miss a command as well if one was sent in-between cycle time.

    I have also trying using the Application trigger as described by https://faq.codesys.com/pages/viewpage.action?pageId=24510480, but this is also not working for me. See attached picture for my FBD code.

    This seems like a simple function, I can't tell what I'm doing wrong here. Thanks for the help.

     
  • ph0010421 - 2024-03-08

    Hello
    You'll need to write a proper sequence to send, then wait for confirmation, and then move on to the next step.
    Use the CASE statement in ST. It's perfect for creating a sequence.

     

Log in to post a comment.