0

I need Help in two thing Here. 1)My main project is i have 23 hallsensors with analog output. There are connected to arduino UNO analog pins using 16:1 Mux or 8:1 mux circuit. The currently i can receive data properly with proper switching. Which are floating point values. Second stage: Now this has to communicate via MODbus protocol .(here only transmission is pending)

2) Now I am in to transmission data. Here i am using basic library downloaded from [Download link modbus library][1]

Now my setup is like this I have arduino Board. RS485 sheild and USB to RS485 converter. Qmodbus software to view data.

I have uploaded the below code.

#include <ModbusRtu.h>

// data array for modbus network sharing
uint16_t au16data[16] = {
  3, 1415, 9265, 4, 2, 7182, 28182, 8, 0, 0, 0, 0, 0, 0, 1, -1 };

/**
 *  Modbus object declaration
 *  u8id : node id = 0 for master, = 1..247 for slave
 *  u8serno : serial port (use 0 for Serial)
 *  u8txenpin : 0 for RS-232 and USB-FTDI 
 *               or any pin number > 1 for RS-485
 */
Modbus slave(1,0,0); // this is slave @1 and RS-232 or USB-FTDI

void setup() {
  slave.begin( 9600 ); // baud-rate at 19200
}

void loop() {
  slave.poll( au16data, 16 );
}

so i am expecting this answer if i am not wrong.

uint16_t au16data[16] = {
  3, 1415, 9265, 4, 2, 7182, 28182, 8, 0, 0, 0, 0, 0, 0, 1, -1 };

But i am getting data as below.

questions:

1) Whats making wrong to get below data?? 2)If i want to store float values how can name uint16_t au16data[16] or changes to be made 3) Is there any working code ON modbus![OUTPUt of MODBUS][2]

Finally i got it working i can read The values. Now i am in second part. I have totally 20 values . currently i stored them as integer only. But my values are flaoting point.How to split real & floating value store in au16data[16] register.???

Assume i got my Sensor value converted as *

CS=30.10
Int_CS=int(CS)
FLOAT_CS=(Int_CS-CS)*100
How to store the Int_CS & FLOAT_CS values in au16data[0]??

*

1

In Modbus protocol, coils are bits and registers are 16-bit unsigned integers.

Hence if you ask Modbus to read your au16data array as coils, and not as registers (which is what they actually are), then you'll get the binary representation for them with QModbus:

Your first register is 3 which is 0000 0000 0000 0011 in binary. Then when you read it as an array of 16 cils, you get these bit values, in reverse order (bit 0 is the lowest order bit and bit 15 is the highest order bit of your register); this is exactly what QModbus shos you:

  • First 2 bits are 1
  • All other bits are 0

Now regarding float values, if I remember correctly this is just not possible with Modbus protocol, hence you cannot do it out of the box.

What you can do, however, is to cast one float as 2 registers and transmit it this way, then it is up to the Modbus client to cast it back to a float; but QModbus will not do that for you as it strictly follows Modbus standard.

  • what i need to alter in above code to get like as array buffer.Is there any software avialble to view data as it is.**uint16_t au16data[16]** is register and save data in the form of bits. – AMPS Oct 30 '14 at 6:32
  • When you choose a protocol (modbus) you need to comply with its limitations, or select another protocol! – jfpoilpret Oct 30 '14 at 16:49
  • If you want to see your array values as words not bits, then just tell QModbus to "read registers" instead of "read coils" that is all. – jfpoilpret Oct 30 '14 at 16:51
  • Ya it worked When i comment Read coil function to run only read register function In program. Now my question in second part How to keep real value and floating value in register of word au16data[16] – AMPS Oct 31 '14 at 5:05

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.