Avatar of naseeam
naseeamFlag for United States of America asked on

How to retrieve ascii characters from modbus registers?

Twenty ascii characters are in Ten Modbus Registers.  Data in modbus registers is stored in little-endian.  Another words, Most Significant Byte(MSB) is farthest to the right (or last) and the Least Significant Byte(LSB) is farthest to the left (or first).

Example:  "Designate" is stored as follows in modbus registers:

Modbus Register 1:    e    D
Modbus Register 2:    i      s
Modbus Register 3:    n    g

unsigned short response_buffer[128];

/* The data in respone_buffer array should appear as follows:
response_buffer[0] = 'e'
response_buffer[1] = 'D'
response_buffer[2] = 'i'
response_buffer[3] = 's'
response_buffer[4] = 'n'
response_buffer[5] = 'g'                            */

/* Does following code retrieve the string properly  ?  Can this code be improved ?    */
char sco1[20];

for (short    i   =   0;     i    <    10;    i++)
   sco1 [ i ]  =   ( char )  ( ( response_buffer[  i  ]    &    0xFF);
   sco1 [ i ] =   ( char )  ( ( response_buffer [  i  ]    >>  8)  &   0xFF );

Avatar of undefined
Last Comment

8/22/2022 - Mon

Log in or sign up to see answer
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform
Sign up - Free for 7 days
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
See how we're fighting big data
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
ask a question
Experts Exchange is like having an extremely knowledgeable team sitting and waiting for your call. Couldn't do my job half as well as I do without it!
James Murphy