Hexa value from MODBUS in xbee frame

Wireless communications in Waspmote, topologies, node types...
Post Reply
david_saiani
Posts: 4
Joined: Wed Jun 21, 2017 12:03 pm

Hexa value from MODBUS in xbee frame

Post by david_saiani » Mon Apr 09, 2018 4:49 pm

Hi,

I'm trying to put an hexadecimal value from an inclinometre in modbus mode in a frame to send it with xbe module.

So , I have my value on 4 bytes in : nodeFrame.getResponseBuffer(0),HEX

I was try to put this value in the frame with the variable SENSOR_RB (because it's once of the rarely string) But it's doesn't work and I don't know why .

This is my code

Code: Select all

#include <WaspXBee802.h>
#include <WaspFrame.h>
#include <WaspGPS.h>
#include <WaspUART.h>
#include <ModbusMaster.h>
#include <Wasp485.h>

// Instantiate ModbusMaster object as slave ID 1, ID 3
ModbusMaster nodeFrame(RS485_COM, 1);
ModbusMaster nodeTool(RS485_COM, 3);

// Define one address for reading
#define address 0x02

// Define the number of bytes to read
#define bytesQty 0x02

//Define adresse Xbee computer
char RX_ADDRESS[] = "0013A20041678B59";
char WASPMOTE_ID[] = "";
#define TIMEOUT 1


uint8_t error;
bool status;
WaspUART uart=WaspUART();
char TOOL ;


void setup()
{USB.ON();
 GPS.ON();
 xbee802.ON(SOCKET1);
 frame.setID( WASPMOTE_ID );
 uart.setUART(SOCKET1);
 nodeFrame.begin(9600);
  nodeTool.begin(9600);
  W485.parityBit(ENABLED);
}


void loop()
{  USB.println("connect to gps");
    Utils.setMuxGPS();
    beginSerial(4800,SOCKET1);
    status = GPS.waitForSignal(TIMEOUT);

     nodeFrame.readHoldingRegisters(address, bytesQty);
    delay(200);
    nodeTool.readHoldingRegisters(address, bytesQty);
    
    if( status == true )
       {
        GPS.getPosition();
        frame.createFrame(ASCII);  
        frame.addSensor(SENSOR_GPS,GPS.convert2Degrees(GPS.latitude,GPS.NS_indicator),GPS.convert2Degrees(GPS.longitude,GPS.EW_indicator));
        closeSerial(SOCKET1);
       }
 //   beginSerial(9600,SOCKET1);
 //RES =(double)(TOOL[3]+((long int)CMMD_RXD[4]<<8)+((long int)CMMD_RXD[5]<<16)+((long int)CMMD_RXD[6]<<24)-m_xmin*100)*0.01;
 TOOL = (nodeFrame.getResponseBuffer(0),HEX);
 USB.println(TOOL);
 frame.createFrame(ASCII);
        frame.addSensor(SENSOR_GPS,GPS.convert2Degrees(GPS.latitude,GPS.NS_indicator),GPS.convert2Degrees(GPS.longitude,GPS.EW_indicator));
   frame.addSensor(SENSOR_BAT, PWR.getBatteryLevel()); 
       frame.addSensor(SENSOR_RB,(nodeFrame.getResponseBuffer(0),HEX));
      //  closeSerial(SOCKET1);
        Utils.setMuxSocket1();
        //delay(100);
        beginSerial(115200,SOCKET1);
        USB.println( nodeFrame.getResponseBuffer(0),HEX);
        

   
    
    error = xbee802.send( RX_ADDRESS, frame.buffer, frame.length );   
           
    if( error == 0 )
         {
           USB.println(F("send ok"));
           closeSerial(SOCKET1);
         }
         else 
         {
          USB.println(F("send error"));
          closeSerial(SOCKET1);
         }
       USB.println(frame.buffer, frame.length );

        nodeFrame.clearResponseBuffer();
        nodeTool.clearResponseBuffer();

    
   }




libelium-dev
Posts: 27967
Joined: Mon Sep 28, 2009 1:06 pm

Re: Hexa value from MODBUS in xbee frame

Post by libelium-dev » Tue Apr 10, 2018 9:09 am

Hi,

getResponseBuffer returns an uint16_t value, so you could add it to the frame with the SENSOR_ULTRASOUND sensor tag.

Code: Select all

frame.addSensor(SENSOR_ULTRASOUND, nodeFrame.getResponseBuffer(0));
Hope this helps.
Regards

Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest