muppets
30 Mar 08, 11:55 PM
This has some stolen code from others in the code examples I hope they don't mind - Darren and Dave
contants:
SerialDataTimer = 7;
variables:
a, ModuleCheckString : string;
b, NudgeValue : integer;
c, NudgeValueString : string;
d, DLTActualTemp : string;
e, DLTSetPoint : string;
f, SkipLineNo : integer;
i, TemperatureString : string;
j, Temperature, LastCommaPosition : integer;
k, TemperatureString2 : string;
l, Temperature2 : integer;
m, OutdoorCoilTempString : string;
n, OutdoorCoilTemp : integer;
o, UnloaderString : string;
p, Unloader : integer;
q, Zone0Status : string;
r, Zone1Status : string;
s, Zone2Status : string;
t, Zone3Status : string;
initialisation:
OpenSerial(1, 1, 9600, 8, 1, 0, 0);
TimerStart(SerialDataTimer);
module 1:
{A/C Control And Data Aquisition only send a request once each second - this stops the serial
port from missing signals.....it also means we only get states each 8 seconds though. Note
I only do some of the statements (serial writes) if page 3 is showing - this is the only page
that will represent the data that will be in the response.....this should reduce the traffic a little.}
once TimerTime(SerialDataTimer)= "00:00:01"
then begin
WriteSerial(1, 'Q0,0,-,-'#13);
end;
once TimerTime(SerialDataTimer)= "00:00:02"
then if ShowingPage("Page 3") then
begin
WriteSerial(1, 'Q0,1,-,-'#13);
end;
once TimerTime(SerialDataTimer)= "00:00:03"
then if ShowingPage("Page 3") then
begin
WriteSerial(1, 'Q0,2,-,-'#13);
end;
once TimerTime(SerialDataTimer)= "00:00:04"
then if ShowingPage("Page 3") then
begin
WriteSerial(1, 'Q0,3,-,-'#13);
end;
{these were just in case I find out what these zones represent}
{once TimerTime(SerialDataTimer)= "00:00:07"
then begin
WriteSerial(1, 'Q0,4,-,-'#13);
end;}
{once TimerTime(SerialDataTimer)= "00:00:08"
then begin
WriteSerial(1, 'Q0,5,-,-'#13);
end;}
once TimerTime(SerialDataTimer)= "00:00:05"
then if ShowingPage("Page 3") then
begin
WriteSerial(1, 'Q0,6,-,-'#13);
end;
{read the serial and find the position of the last comma - this was stolen from Darren thanx btw}
ReadSerial(1, i, #13);
for j := 1 to length(i) do
begin
if i[j] = ',' then
LastCommaPosition := j;
end;
Copy(ModuleCheckString, i, LastCommaPosition - 9, 4);
{if zone 0 responds on the serial gather the data}
if ModuleCheckString = 'R0,0' then
if i <> 'Q0,0,-,-' then
begin
{ copy the text from the character after the last comma }
Copy(TemperatureString, i, LastCommaPosition + 1, 2);
{ copy the text from the character before the last comma }
Copy(TemperatureString2, i, LastCommaPosition - 2, 2);
{ copy the text from the character before the 2nd last comma }
Copy(Zone0Status, i, LastCommaPosition - 4, 1);
{ extract the temperature from the string }
Temperature := StringToInt(TemperatureString);
Temperature2 := StringToInt(TemperatureString2);
{zone 0 Status is the a/c's current state (on or off)}
if Zone0Status = '1' then SetStringSystemIO(23, 'On');
if Zone0Status = '0' then SetStringSystemIO(23, 'Off');
{the current temperature of the thermostat}
SetIntSystemIO(21, Temperature);
{the current set point on the OEM interface}
SetIntSystemIO(22, Temperature2);
{send the current temperature of the thermostat to the DLT for display}
Format(DLTActualTemp, 'Temp ',GetIntSystemIO(21)/2:0);
SetStringIBSystemIO("Label Group Text", 254, 136, 0, 0, DLTActualTemp);
end;
{DLT in bedroom alter label so that it represents the current set point}
if SkipLineNo = 5 then
begin
Format(DLTSetPoint, 'SetPt ',GetIntSystemIO(30)/2:0);
SetStringIBSystemIO("Label Group Text", 254, 136, 1, 0, DLTSetPoint);
SkipLineNo := 0
end
else
SkipLineNo := SkipLineNo + 1 ;
{if line is correct for the data we want to extract ie. zone 1 data}
if ModuleCheckString = 'R0,1' then
if i <> 'Q0,1,-,-' then
begin
{ copy the text from the character before the 2nd last comma }
Copy(Zone1Status, i, LastCommaPosition - 4, 1);
{ extract the temperature from the string }
if Zone1Status = '1' then SetStringSystemIO(24, 'On');
if Zone1Status = '0' then SetStringSystemIO(24, 'Off');
end;
{if line is correct for the data we want to extract ie. zone 2 data}
if ModuleCheckString = 'R0,2' then
if i <> 'Q0,2,-,-' then
begin
{ copy the text from the character before the 2nd last comma }
Copy(Zone2Status, i, LastCommaPosition - 4, 1);
{ extract the temperature from the string }
if Zone2Status = '1' then SetStringSystemIO(25, 'On');
if Zone2Status = '0' then SetStringSystemIO(25, 'Off');
end;
{if line is correct for the data we want to extract ie. zone 3 data}
if ModuleCheckString = 'R0,3' then
if i <> 'Q0,3,-,-' then
begin
{ copy the text from the character before the 2nd last comma }
Copy(Zone3Status, i, LastCommaPosition - 4, 1);
{ extract the temperature from the string }
if Zone3Status = '1' then SetStringSystemIO(26, 'On');
if Zone3Status = '0' then SetStringSystemIO(26, 'Off');
end;
{if line is correct for the data we want to extract ie. zone 6 (current unit) data -
outdoor coil temperature and unloading system (digital scroll)}
if ModuleCheckString = 'R0,6' then
if i <> 'Q0,0,-,-' then
begin
{ copy the text from the character after the last comma }
Copy(OutdoorCoilTempString, i, LastCommaPosition - 2, 2);
{ copy the text from the character before the last comma }
Copy(UnloaderString, i, LastCommaPosition + 1, 3);
{ extract the temperature from the string }
OutdoorCoilTemp := StringToInt(OutdoorCoilTempString);
Unloader := StringToInt(UnloaderString);
SetIntSystemIO(27, OutdoorCoilTemp);
SetIntSystemIO(28, Unloader);
end;
{restart the timer to loop the queries}
once TimerTime(SerialDataTimer)= "00:00:08"
then begin
TimerStart(SerialDataTimer);
end;
{if c-touch input is to start the unit}
Once GetTriggerLevel(004) = 255 then
begin
WriteSerial(1, 'Q0,0,1,-'#13);
end;
{if c-touch input is to stop the unit}
Once GetTriggerLevel(004) = 0 then
begin
WriteSerial(1, 'Q0,0,0,-'#13);
end;
{if DLT input requests increase set point - increase by 1 when on}
if GetCBusState(254, "Heating", 0) = ON then
SetIntSystemIO(30, GetIntSystemIO(30)+1);
{if DLT input requests decrease set point - decrease by 1 when on}
if GetCBusState(254, "Heating", 1) = ON then
SetIntSystemIO(30, GetIntSystemIO(30)-1);
{when page 3 is selected make displayed set point = the units current set point. This is mainly used
when the unit is started for the first time after download}
once ShowingPage("Page 3") then
if ModuleCheckString = 'R0,0' then
SetIntSystemIO(30, Temperature2);
module 2:
{if the unit set point differs from the set point as displayed on the c-touch and dlt and is the same
as the checking i/o (30=31) which means ....if 30 and 31 are the same then the change occured on the
OEM interface and not the DLT or c-touch. note I use a delay to stop jitters on the c-touch when it
displays I/O 30 which is the c-touch's/dlt's setpoint. 22 is the current OEM set point. 31 is the
set point that is used to check against - it only gets updated after 30 = or <> it. for this
statement to be true becuase 30=31 it means someone altered the set point on the OEM interface and not either
the c-touch or dlt}
if GetIntSystemIO(22) <> GetIntSystemIO(30)
then begin
if GetIntSystemIO(30) = GetIntSystemIO(31) then
if ModuleCheckString = 'R0,0' then
if i <> 'Q0,0,-,-' then
SetIntSystemIO(30, GetIntSystemIO(22));
SetIntSystemIO(31, GetIntSystemIO(22));
Delay(2);
end;
Module 3:
{note from previous module that 22 and 30 are different however in this module 30 and 31 are
checked and are different is the statement is to continue - this means someone altered the set
point on either the c-touch or dlt and not on the OEM interface}
if GetIntSystemIO(22) <> GetIntSystemIO(30)
then begin
if GetIntSystemIO(30) <> GetIntSystemIO(31) then
Delay(1);
Format(NudgeValueString, 'Q0,0,*,',GetIntSystemIO(30):0, #13);
WriteSerial(1, NudgeValueString);
SetIntSystemIO(31, GetIntSystemIO(30));
end;
contants:
SerialDataTimer = 7;
variables:
a, ModuleCheckString : string;
b, NudgeValue : integer;
c, NudgeValueString : string;
d, DLTActualTemp : string;
e, DLTSetPoint : string;
f, SkipLineNo : integer;
i, TemperatureString : string;
j, Temperature, LastCommaPosition : integer;
k, TemperatureString2 : string;
l, Temperature2 : integer;
m, OutdoorCoilTempString : string;
n, OutdoorCoilTemp : integer;
o, UnloaderString : string;
p, Unloader : integer;
q, Zone0Status : string;
r, Zone1Status : string;
s, Zone2Status : string;
t, Zone3Status : string;
initialisation:
OpenSerial(1, 1, 9600, 8, 1, 0, 0);
TimerStart(SerialDataTimer);
module 1:
{A/C Control And Data Aquisition only send a request once each second - this stops the serial
port from missing signals.....it also means we only get states each 8 seconds though. Note
I only do some of the statements (serial writes) if page 3 is showing - this is the only page
that will represent the data that will be in the response.....this should reduce the traffic a little.}
once TimerTime(SerialDataTimer)= "00:00:01"
then begin
WriteSerial(1, 'Q0,0,-,-'#13);
end;
once TimerTime(SerialDataTimer)= "00:00:02"
then if ShowingPage("Page 3") then
begin
WriteSerial(1, 'Q0,1,-,-'#13);
end;
once TimerTime(SerialDataTimer)= "00:00:03"
then if ShowingPage("Page 3") then
begin
WriteSerial(1, 'Q0,2,-,-'#13);
end;
once TimerTime(SerialDataTimer)= "00:00:04"
then if ShowingPage("Page 3") then
begin
WriteSerial(1, 'Q0,3,-,-'#13);
end;
{these were just in case I find out what these zones represent}
{once TimerTime(SerialDataTimer)= "00:00:07"
then begin
WriteSerial(1, 'Q0,4,-,-'#13);
end;}
{once TimerTime(SerialDataTimer)= "00:00:08"
then begin
WriteSerial(1, 'Q0,5,-,-'#13);
end;}
once TimerTime(SerialDataTimer)= "00:00:05"
then if ShowingPage("Page 3") then
begin
WriteSerial(1, 'Q0,6,-,-'#13);
end;
{read the serial and find the position of the last comma - this was stolen from Darren thanx btw}
ReadSerial(1, i, #13);
for j := 1 to length(i) do
begin
if i[j] = ',' then
LastCommaPosition := j;
end;
Copy(ModuleCheckString, i, LastCommaPosition - 9, 4);
{if zone 0 responds on the serial gather the data}
if ModuleCheckString = 'R0,0' then
if i <> 'Q0,0,-,-' then
begin
{ copy the text from the character after the last comma }
Copy(TemperatureString, i, LastCommaPosition + 1, 2);
{ copy the text from the character before the last comma }
Copy(TemperatureString2, i, LastCommaPosition - 2, 2);
{ copy the text from the character before the 2nd last comma }
Copy(Zone0Status, i, LastCommaPosition - 4, 1);
{ extract the temperature from the string }
Temperature := StringToInt(TemperatureString);
Temperature2 := StringToInt(TemperatureString2);
{zone 0 Status is the a/c's current state (on or off)}
if Zone0Status = '1' then SetStringSystemIO(23, 'On');
if Zone0Status = '0' then SetStringSystemIO(23, 'Off');
{the current temperature of the thermostat}
SetIntSystemIO(21, Temperature);
{the current set point on the OEM interface}
SetIntSystemIO(22, Temperature2);
{send the current temperature of the thermostat to the DLT for display}
Format(DLTActualTemp, 'Temp ',GetIntSystemIO(21)/2:0);
SetStringIBSystemIO("Label Group Text", 254, 136, 0, 0, DLTActualTemp);
end;
{DLT in bedroom alter label so that it represents the current set point}
if SkipLineNo = 5 then
begin
Format(DLTSetPoint, 'SetPt ',GetIntSystemIO(30)/2:0);
SetStringIBSystemIO("Label Group Text", 254, 136, 1, 0, DLTSetPoint);
SkipLineNo := 0
end
else
SkipLineNo := SkipLineNo + 1 ;
{if line is correct for the data we want to extract ie. zone 1 data}
if ModuleCheckString = 'R0,1' then
if i <> 'Q0,1,-,-' then
begin
{ copy the text from the character before the 2nd last comma }
Copy(Zone1Status, i, LastCommaPosition - 4, 1);
{ extract the temperature from the string }
if Zone1Status = '1' then SetStringSystemIO(24, 'On');
if Zone1Status = '0' then SetStringSystemIO(24, 'Off');
end;
{if line is correct for the data we want to extract ie. zone 2 data}
if ModuleCheckString = 'R0,2' then
if i <> 'Q0,2,-,-' then
begin
{ copy the text from the character before the 2nd last comma }
Copy(Zone2Status, i, LastCommaPosition - 4, 1);
{ extract the temperature from the string }
if Zone2Status = '1' then SetStringSystemIO(25, 'On');
if Zone2Status = '0' then SetStringSystemIO(25, 'Off');
end;
{if line is correct for the data we want to extract ie. zone 3 data}
if ModuleCheckString = 'R0,3' then
if i <> 'Q0,3,-,-' then
begin
{ copy the text from the character before the 2nd last comma }
Copy(Zone3Status, i, LastCommaPosition - 4, 1);
{ extract the temperature from the string }
if Zone3Status = '1' then SetStringSystemIO(26, 'On');
if Zone3Status = '0' then SetStringSystemIO(26, 'Off');
end;
{if line is correct for the data we want to extract ie. zone 6 (current unit) data -
outdoor coil temperature and unloading system (digital scroll)}
if ModuleCheckString = 'R0,6' then
if i <> 'Q0,0,-,-' then
begin
{ copy the text from the character after the last comma }
Copy(OutdoorCoilTempString, i, LastCommaPosition - 2, 2);
{ copy the text from the character before the last comma }
Copy(UnloaderString, i, LastCommaPosition + 1, 3);
{ extract the temperature from the string }
OutdoorCoilTemp := StringToInt(OutdoorCoilTempString);
Unloader := StringToInt(UnloaderString);
SetIntSystemIO(27, OutdoorCoilTemp);
SetIntSystemIO(28, Unloader);
end;
{restart the timer to loop the queries}
once TimerTime(SerialDataTimer)= "00:00:08"
then begin
TimerStart(SerialDataTimer);
end;
{if c-touch input is to start the unit}
Once GetTriggerLevel(004) = 255 then
begin
WriteSerial(1, 'Q0,0,1,-'#13);
end;
{if c-touch input is to stop the unit}
Once GetTriggerLevel(004) = 0 then
begin
WriteSerial(1, 'Q0,0,0,-'#13);
end;
{if DLT input requests increase set point - increase by 1 when on}
if GetCBusState(254, "Heating", 0) = ON then
SetIntSystemIO(30, GetIntSystemIO(30)+1);
{if DLT input requests decrease set point - decrease by 1 when on}
if GetCBusState(254, "Heating", 1) = ON then
SetIntSystemIO(30, GetIntSystemIO(30)-1);
{when page 3 is selected make displayed set point = the units current set point. This is mainly used
when the unit is started for the first time after download}
once ShowingPage("Page 3") then
if ModuleCheckString = 'R0,0' then
SetIntSystemIO(30, Temperature2);
module 2:
{if the unit set point differs from the set point as displayed on the c-touch and dlt and is the same
as the checking i/o (30=31) which means ....if 30 and 31 are the same then the change occured on the
OEM interface and not the DLT or c-touch. note I use a delay to stop jitters on the c-touch when it
displays I/O 30 which is the c-touch's/dlt's setpoint. 22 is the current OEM set point. 31 is the
set point that is used to check against - it only gets updated after 30 = or <> it. for this
statement to be true becuase 30=31 it means someone altered the set point on the OEM interface and not either
the c-touch or dlt}
if GetIntSystemIO(22) <> GetIntSystemIO(30)
then begin
if GetIntSystemIO(30) = GetIntSystemIO(31) then
if ModuleCheckString = 'R0,0' then
if i <> 'Q0,0,-,-' then
SetIntSystemIO(30, GetIntSystemIO(22));
SetIntSystemIO(31, GetIntSystemIO(22));
Delay(2);
end;
Module 3:
{note from previous module that 22 and 30 are different however in this module 30 and 31 are
checked and are different is the statement is to continue - this means someone altered the set
point on either the c-touch or dlt and not on the OEM interface}
if GetIntSystemIO(22) <> GetIntSystemIO(30)
then begin
if GetIntSystemIO(30) <> GetIntSystemIO(31) then
Delay(1);
Format(NudgeValueString, 'Q0,0,*,',GetIntSystemIO(30):0, #13);
WriteSerial(1, NudgeValueString);
SetIntSystemIO(31, GetIntSystemIO(30));
end;