floating point values on modbus.

Go To Last Post
2 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

For my project I am using modbus in slave mode. And to replay mater I want to transmit floating point no like 123.456 or 9958.32. So what is correct way to transmit float values on modbus.

 

I having function to break float value in char. but I don't know weather it is correct or not for MODBUS.

 

unsigned char outbox[5];

void breakDown(void)
{
  int index=78.295;
  
  float member=1;

  unsigned long d = *(unsigned long *)&member;
 
  outbox[0] = d & 0x00FF;
  outbox[1] = (d & 0xFF00) >> 8;
  outbox[2] = (d & 0xFF0000) >> 16;
  outbox[3] = (d & 0xFF000000) >> 24;
  
  transmit(outbox[0]);

  transmit(outbox[1]);

  transmit(outbox[2]);

  transmit(outbox[3]);

}

 

 

 

Last Edited: Sat. Feb 24, 2018 - 01:48 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Clearly, this is not a tutorial. So why post here?

Firstly, your masks will probably need a type associated with them. Eg: 0xff0000UL
You’ve got four possibilities of byte order. One works. Read the modbus spec to find this out.