Tarasik (Customer) asked a question.

Floating point number transfer between BRX PLC and PC

I am a LabVIEW developer and have just started learning BRX, so don't judge too harshly.

I use Modbus/TCP server Data communication between BRX PLC and PC. According to the documentation, it is not possible to read/write directly to PLC registers, so I use Mxx registers.

For example, to transmit a floating-point value, 1234.56, I have to use two MHR registers. One for the integer part of the number, the second for the fractional part (before transferring, multiplying it by 100 to make it an integer). In addition, I need to make sure that the numbers do not go beyond the Signed Word limit. Everything works, but maybe there is a more elegant solution?

 

PS. Sorry for my English.


  • HOST_franji1 (HOST Engineering)

    Use the SUBCRIBE (not PUBLISH) instruction. It has all the steps to convert the 2 MHR 16 bit registers to an R or RY or whatever IEEE 754 32 bit floating point register

    Selected as Best
  • RBPLC (Customer)

    In LabVIEW there should be function to write the floating point number to two contiguous Modbus registers. At that point, the two registers can be interpreted as a float in the BRX.

  • Tarasik (Customer)

    From Do-more Help

    M RegistersI use LabVIEW ModBus library, and I have access to these registers.

    But for example, if I need to transfer a number, let say 86754.723, then I need two registers for the integer part and two for the fractional part. I have to use four MHR registers for each number, which is not very rational. I'm just interested in how professionals solve such problems.

    Expand Post
    • RBPLC (Customer)

      "I need two registers for the integer part and two for the fractional part"

       

      I don't know what you're doing on the LabVIEW side, but typical Modbus comms only requires two 16-bit registers for floating point numbers. You shouldn't be writing to 4 registers.

       

      In the BRX, the allocated Modbus registers are sandboxed for security purposes.

       

      If you have a BRX PLC on hand, you can connect to the PLC in one instance of DmD and use another instance of DmD to run the simulator. You can communicate between the PLC and the simulator to see how the comms works with Modbus and then adapt the LabVIEW to do the same.

      Expand Post
  • Tarasik (Customer)

    Thank you, you pointed me in the right direction. I'll lose a little bit in accuracy, but it's not that important.

    LabVIEW side, everything is very simple.

    FP to MHR On the BRX side, how to convert two registers to a floating point and floating point to two registers is a big question for me...

    Expand Post
  • HOST_franji1 (HOST Engineering)

    Use the SUBCRIBE (not PUBLISH) instruction. It has all the steps to convert the 2 MHR 16 bit registers to an R or RY or whatever IEEE 754 32 bit floating point register

    Selected as Best
    • HOST_franji1 (HOST Engineering)

      Both the PC and PLC utilize Little Endian memory layout, so you should not need to swap any WORDs, but you never know. SUBSCRIB offers those options (BYTE and/or WORD swapping), if needed.

  • Tarasik (Customer)

    Thanks a lot, everything works!

    PLC to PC

    BRX PLC to PC

    • HOST_franji1 (HOST Engineering)

      Ha! I thought LabView was providing the INPUT value TO the PLC. Glad you got it figured out.

  • Tarasik (Customer)

    I need a both way communication. So I use SUBSCRIB function as well. Thanks again.