SFC Grafcet changes cause Modbus TCP slave driver to swap bytes in the communication

hlandaluce
2020-11-26
2020-11-27
  • hlandaluce - 2020-11-26

    I'm using a simulation software communicated with a Control Win V3 using by ModbusTCP as a slave. I'm reading two bytes %IB0 and %IB1, and writing one byte at %QB0. All signals are read and written from a POU using SFC language. The problem comes when I create a bifurcation in the grafcet. When the simulation software modifies my %IB0 nothing happens, and if it modifies %IB1, changes are applied also to %IB0. And if I remove again the bifurcation of the SFC grafcet, it starts to work correctly again.

    It seems like a bug on the ModbusTCP slave driver, or am I doing something wrong?

     
  • dFx

    dFx - 2020-11-26

    SFC is not the language I would choose for processing any communication like modbusTCP is.

    Correct me if I'm wrong: the Controlwin PLC is the modbusTCP slave (so, the server awainting for client to connect and issue requests).
    You are trying to read 2 bytes, namely %IB0 and %IB1, and to write 1 other (%QB0).

    First of all, be aware that modbus is a 16bit (word) oriented protocol. So, writing a byte is totally wrong. You are either writing some coils (bits), one by one, or writing a multiple of words (n times 16bits). So you first issue may come from this.

    Then, modbus addresses and byte endiantness my give you a headhache.
    In modbus, addresses are starting from 0 protocol wise, but, the first available address is 1(translated as 0 in the protocol). Make sure you are writing the right address. Exemple : write 16#0110 to your address, and verify that the plc sees 16#0110.
    If the PLC is reading 16#0001 or 16#1000, then you have a wrong addressing, offseted by 1.
    If the PLC is reading 16#1001, then you have a byte swap between your two systems (Controlwin PLC and simulation software)

    About SFC, you should make sure, the modbusTCP server functionblock is correctly called every scan cycle.
    If my previous tips didn't help, please consider sending some screenshots or sources about your SFC.
    Also, while speaking about SFC, is your branch an OR or AND branch ?

    Kind regards,
    dFx

     
  • hlandaluce - 2020-11-26

    Hi!

    Thank you for the response dFx. I think i didn't explain myself very well.
    SFC is processing a sequence of a process that is simulated by a software called VirtualmakTCP, reading the %IW0 and writing the %QW0 that the ModbusTCPslave is exchanging with the process simulator. I'm not using any modbus blocks, just using the ModbusTCP_Slave_Device added to the project.
    The issue is that, depending on what I program on an FB written in SFC, the ModbusTCP device swaps the inputs from %IB0 to %IB1. And if I undo, for example, the branch of the SFC (that apparently has nothing to do with the modbus device), it works correctly. But I can't identify what is generating the problem.

    I attach my codesys project, just in case you could tell me if I'm doing something wrong with the Modbus device.
    Thank you!

    Hugo

     

    Last edit: hlandaluce 2020-11-26
  • dFx

    dFx - 2020-11-27

    I'm running 3.5 SP12 and I can't open your project.

    If you are using a slave device, then just make sure the refresh task is correctly set (bus cycle task).
    Still, the addressing offsets may apply.
    Maybe your troubles are related to online edits and are solved with a download ? This could be pointers related stuff.

     
    πŸ‘
    1
  • hlandaluce - 2020-11-27

    Oh! Thank you dFX, I needed to update variables with the bus cycle task. Now it seems to work perfectly.

    Thanks! =D

     

Log in to post a comment.