Dear all,
I have two angle Desired and actual. which are negative . I am using qmodbus software to read below data from modbus slave. If value of desired i put it has + value master read data properly in +ve value. if value assigned is -ve . then it reading as in image. If that value selecting word -43 is read. How to convert it to readable format. Instead of printing 65543 how to make it print either in +ve value or in -ve value
In below code i checked if no is negative multiply by -1 else display as it is. But for -ve value displaying zero.
If it hexadecimal , I could subtract FF from value i got then add 1 to get actual no. SInce it is decimal no i dint how to do it.
#include "glob.h"
#include "rtc.h"
#include "config.h"
#include"timecalc.h"
#define ID 1
static int local_day=10;
static int local_month=4;
static int local_year=2014;
static int local_s=2;
static int local_h=13;
static int local_m=14;
int Wind_Speed=30;
int Wind_Kmph=67;
float desired_angle=-45.0;
float actual_angle=-43.0;
Modbus slave(ID, 0, 0);
boolean led;
int8_t state = 0;
unsigned long tempus;
// data array for modbus network sharing
uint16_t au16data[14];
void setup() {
// start communication
slave.begin( 9600 );
rtcSetup();
tempus = millis() + 100;
digitalWrite(13, HIGH );
}
void loop() {
// poll messages
// blink led pin on each valid message
state = slave.poll( au16data, 14);
if (state > 4) {
tempus = millis() + 50;
digitalWrite(13, HIGH);
}
if (millis() > tempus) digitalWrite(13, LOW );
calcTime();
convertUTCtoLocal();
au16data[0]=local_year;
au16data[1]=local_month;
au16data[2]=local_day;
au16data[3]=wkDay;
au16data[4]=local_h;
au16data[5]=local_m;
au16data[6]=local_s;
au16data[7]=Wind_Speed;
au16data[8]=Wind_Kmph;
if(desired_angle<0)
{
au16data[9]=(int)desired_angle*-1;
au16data[10]=(int)actual_angle*-1;
}else
{
au16data[9]=(int)desired_angle;
au16data[10]=(int)actual_angle;
}
au16data[11] = slave.getInCnt();
au16data[12] = slave.getOutCnt();
au16data[13] = slave.getErrCnt();
}