PDA

View Full Version : RTI to PAC Interface via serial


richy
29 Sep 06, 12:38 AM
For any of you guys out there using RTI controls to talk to C-bus.
Here is a snipet of code that works very well, just follow the protocol.

Cheers.

Global Variables
Global Variables
s, ss, si : string;
i, GA, SCENE, TG, PER, Level : integer;

Module
{ To use this, communicate with COM2 using BillSerialMonitor or a similar program.
Please follow examples below for full functionality.
To turn a Group Address on :- (ON_"Group Address")
ON 32
ON 123
ON 1
To turn a Group Address off:- (OFF_"Group Address")
OFF 34
OFF 99
OFF 134
To turn toggle a Group Address :- (TG_"Group Address")
TG 12
TG 124
To trigger a Scene:- (SC_"Scene Number")
SC 0
SC 3
SC 70
To Dim a Group Address to a Specific level :- (DIM_"Level%"_"Group Address")
DIM 34 23 = Dim Group Address 23 to percentage level 34%
DIM 50 23
To Increment the level of a particular Group Address :- (INC_"Group Address")
INC 34
INC 145
To Decrement the level of a particular Group Address :- (DEC_"Group Address")
DEC 34
DEC 145
NOTE:
-All underscores are actual spaces, please refer to examples.
-The Default Application, is the Lighting Application.
-The Increment and Decrement functions, add or subtract 5% from the current level respectively.
-The Dim function is refering to percentage levels.}

ReadSerial(1, s, #13);
LowerCase(s);
if pos('on', s) = 1 then
begin
copy(ss, s, 4, 4);
WriteLn('ON : ', ss);
GA := StringToInt(ss);
SetLightingState(GA, ON);
end
else if pos('off', s) = 1 then
begin
copy(ss, s, 5, 4);
WriteLn('OFF : ', ss);
GA := StringToInt(ss);
SetLightingState(GA, OFF);
end
else if pos('sc', s) = 1 then
begin
copy(ss, s, 4, 4);
WriteLn('SCENE : ', ss);
SCENE := StringToInt(ss);
SetScene(SCENE);
end
else if pos('tg', s) = 1 then
begin
copy(ss, s, 4, 4);
WriteLn('TOGGLE : ', ss);
TG := StringToInt(ss);
if (GetCbusLevel("Local Network", "Lighting", TG) > 0%) then
begin
SetLightingState(TG, OFF);
end
else if (GetCbusLevel("Local Network", "Lighting", TG) < 100%) then
begin
SetLightingState(TG, ON);
end
end
else if pos('dim', s) = 1 then
begin
copy(si, s, 5, 2);
copy(ss, s, 8, 4);
WriteLn('PERCENTAGE : ', si, 'GA : ', ss);
PER := StringToInt(si);
GA := StringToInt(ss);
SetLightingLevel(GA, PercentToLevel(PER), 0);
end
else if pos('inc', s) = 1 then
begin
copy(ss, s, 5, 4);
WriteLn('INCREMENT : ', ss);
GA := StringToInt(ss);
PER := GetLightingLevel(GA);
Level := LevelToPercent(PER) + 5;
SetLightingLevel(GA, PercentToLevel(Level), 0);
end
else if pos('dec', s) = 1 then
begin
copy(ss, s, 5, 4);
WriteLn('DECREMENT : ', ss);
GA := StringToInt(ss);
PER := GetLightingLevel(GA);
Level := LevelToPercent(PER) - 5;;
SetLightingLevel(GA, PercentToLevel(Level), 0);
end


************************************************
Thanks to the help from the some of the CIS guys, I tweaked there serial example, and now I have my RTI units commanding C-Bus with ease.