Its been awhile since I looked at this stuff, below is a cut&paste from the FishBowl source that should answer your questions, your on your own, but should help your efforts:
On the byte decoding, Sync mode means its a UPG , meaning the comm stream is scanned and when "XR\UPG" is found that the beginning of the data if its an older XR, then the timeout methode is needed
if (SyncMode == true)
{
MsgBuff[BuffPtr] = TMainForm::COMM->ReadByte();
check[0] = check[1];
check[1] = check[2];
check[2] = check[3];
check[3] = check[4];
check[4] = check[5];
check[5] = MsgBuff[BuffPtr];
if ((check[0] == 'X') &&
(check[1] == 'R') &&
(check[2] == '\\') &&
(check[3] == 'G') &&
(check[4] == 'P'))
{
if (BuffPtr == 33) found_sync = true;
BuffPtr = 0;
}
else BuffPtr++;
}
else
{
MsgBuff[BuffPtr] = TMainForm::COMM->ReadByte();
BuffPtr++;
}
if (((BuffPtr == 32) && (SyncMode == false)) ||
((SyncMode == true) && (found_sync == true))) // received complete message
DECODING OF THE COMM STREAM:
if (fault0 == 0) fault0 = MsgBuff[0];
newmodes = MsgBuff[1];
Version = MsgBuff[2];
VAChigh = MsgBuff[4];
VAClow = MsgBuff[5];
FREQhigh = MsgBuff[6];
FREQlow = MsgBuff[7];
AC_WATTShigh = MsgBuff[8];
AC_WATTSlow = MsgBuff[9];
FAULTTIMER = MsgBuff[10];
DC_VOLTS = MsgBuff[11];
if (SyncMode)
{
DC_AMPS = MsgBuff[12];
DC_AMPS_LO = MsgBuff[15];
mppthi = MsgBuff[3];
mpptlo = MsgBuff[13];
}
else
{
DC_AMPS = 0;
mppthi = 0;
mpptlo = 0;
DC_AMPS_LO = 0;
}
DC_VOLTS_LO = MsgBuff[14];
Power_Limit_Hi = MsgBuff[16];
Power_Limit_Lo = MsgBuff[17];
dp_volts_hi = MsgBuff[19];
dp_volts_lo = MsgBuff[20];
dp_amps_hi = MsgBuff[21];
dp_amps_lo = MsgBuff[22];
dp_peak_hi = MsgBuff[23];
dp_peak_lo = MsgBuff[24];
AmbientTemp = MsgBuff[25];
HeatSinkTemp = MsgBuff[26];
dp_volts_hi_p1 = MsgBuff[27];
dp_volts_lo_p1 = MsgBuff[28];
dp_amps_hi_p1 = MsgBuff[29];
dp_amps_lo_p1 = MsgBuff[30];
// Mains AC Voltage
ac_volts = (VAChigh * 256 ) + VAClow;
// Mains Freq
ffreq = (float)((FREQhigh * 256 ) + FREQlow ) / 10;
//DC Volts
dc_volts = (((DC_VOLTS << 8 ) + DC_VOLTS_LO ) >> 5) * .125;
// Instant power
ac_watts = (AC_WATTShigh * 256 ) + AC_WATTSlow ;
// Dc Amps
dc_amps = (DC_AMPS + ((DC_AMPS_LO >> 4 ) * .0625));
// Dc Watts
if (SyncMode) dc_power = dc_amps * dc_volts;
else dc_power = 0;
// dp stuff is the peak delta power reading , cleared every 24 less power cycles
// volts and amps are the values for the dp_peak reading stored
//dp volts
dp_volts = ((dp_volts_hi << 8 ) + dp_volts_lo) * .0625;
dp_volts_p1 = ((dp_volts_hi_p1 << 8 ) + dp_volts_lo_p1) * .0625;
// dp Amps
dp_amps = ((dp_amps_hi << 8 ) + dp_amps_lo) * .0625;
dp_amps_p1 = ((dp_amps_hi_p1 << 8 ) + dp_amps_lo_p1) * .0625;
// dp peak power
dp_peak = (dp_peak_hi * 256) + dp_peak_lo;
// Mppt
mppt_volts = (((mppthi << 8 ) + mpptlo) >> 5) * .125 ;
// Ambient Temp
AmbientTemp = ((((255 - AmbientTemp) * .01953) / .032) + 10);
AmbientTempF = (AmbientTemp * 1.8 ) + 32;
// Heat Sink
HeatSinkTemp = ((((255 - HeatSinkTemp) * .01953) / .032) + 10);
HeatSinkTempF = (HeatSinkTemp * 1.8 ) + 32;
// do math for efficiency stuff
acp = ac_watts;
dcp = dc_power;
if (dcp > 0 ) eff = acp/dcp * 100;
else eff = 0 ;
if (eff > 99.9 )eff = 99.9;
// peak ac watts
if((ac_watts > ac_watts_peak) && (ac_watts < 2800 )) ac_watts_peak = ac_watts;
// running total math
ac_power_total = ac_power_total + ((AC_WATTShigh << 8 ) + AC_WATTSlow);
ac_kwh = ac_power_total / 3600;
if (FAULTTIMER == 0 )
{
online_seconds++;
}
if (online_seconds == 60 )
{
online_seconds = 0;
online_minutes++;
}
if (online_minutes == 60)
{
online_minutes = 0;
online_hours++;
}
}
FAULT DECODING
if (fault0 == 255) strcpy(fault_text,"AC over 264 vac");
else if(fault0 == 253) strcpy(fault_text,"AC under 211 vac");
else if(fault0 == 251) strcpy(fault_text,"Line freq over 60.5");
else if(fault0 == 249) strcpy(fault_text,"Line freq under 59.3");
else if(fault0 == 247) strcpy(fault_text,"DC input volts over 125 VDC");
else if(fault0 == 245) strcpy(fault_text,"DC input volts under 40VDC");
else if (newmodes & 0x01)
{
strcpy(tempstr,"");
maxpower = (Power_Limit_Hi * 256) + Power_Limit_Lo;
strcpy(fault_text,"Tempature derating enabled , maximum allowed power = ");
itoa(maxpower, tempstr, 10);
strcat(fault_text,tempstr);
strcat(fault_text," Watts");
}
else if(fault0 != 0)
{
strcpy(tempstr,"");
itoa(fault0, tempstr, 10);
strcpy(fault_text,"Fault detected , code = ");
strcat(fault_text,tempstr);
}
else if((fault0 == 0) & (FAULTTIMER != 0 ) )
{
strcpy(tempstr,"");
strcpy(fault_text,"Offline, connect in ");
itoa(FAULTTIMER*2, tempstr, 10);
strcat(fault_text,tempstr);
strcat(fault_text," seconds");
}
else strcpy(fault_text,"Normal operation");
|