Send a real number to PLC (siemens) connected by Profinet

  • Place your Ad here!
  • Hi,


    if the values are rather small the sender may, for example, multiply them by 100 and cut off the remaining fractions before sending and the receiver simply divides them by 100:


    sender:

    out = to_int(value*100)


    receiver:

    value = in/100


    Most PLCs I know of can handle negative values from scratch. FANUC only allows integer from 0 to 65536 to be sent/received via IO and handles them as two's complement, thus this way, and for this example, you can send/receive values from -367,68 to 367,68. If you increase or decrease the divider / multiplier just the decimal point moves. If the values are bigger you may use separate inputs and outputs for decimals and fractions. For example:


    sender:

    out_decimals = to_int(value)

    out_fractions = to_int((value - to_int(value))*100)


    receiver:

    value = in_decimals + ((in_fractions)/100)


    This way you can send and receive values from -36768,99 to 36768,99. Increasing or decreasing the divider / multiplier results in less or more digits for the fraction. The decimals are limited to +-32768 anyway.


    If the values are even bigger you have to tinker a lot using bit masks and logical operations.

    Never EVER again fanuc!

    Edited 4 times, last by HalbesYoyo: Some corrections and additional infos ().

  • Some programmers also using digital inputs and outputs to differntiate between positive and negative values. Below is a simplified example to show the basic principle:

    Code
    ! Send value from robot to PLC ;
    R[1]=1.23 ;
    R[1]=R[1]*100 ;
    IF R[1]>=0 THEN ;
    DO[1:Value is positive]=ON ;
    ELSE ;
    DO[2:Value is negative]=ON ;
    R[1]=R[1]*(-1) ;
    ENDIF ;
    GO[1]=R[1] ;

    There is much more to do to make the conversion more robust, e.g. make sure that there are no decimal places left, make sure that the value is within the maximum range of the group input/output (the maximum is 16 bit), sign check, etc.


    I'm using a whole different solution for the conversion of Real2Int and Int2Real on my FANUCs.


    Unfortunately, I cannot provide you with my code because I'm out of the office and I don't know the whole code by heart.

    Edited once, last by DS186: Added another line of code. ().

  • I'm using a whole different solution for the conversion of Real2Int and Int2Real on my FANUCs.


    Unfortunately, I cannot provide you with my code because I'm out of the office and I don't know the whole code by heart.

    I am interested in your solution, is it possible to you to share it when you get back to your office?
    Thank you again

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

Advertising from our partners