PC (Delphi)
var
Form1: TForm1;
i, n : integer;
procedure TForm1.Button1Click(Sender: TObject); //Click button to start
begin
if timer1.enabled = true then
begin
Vacomm1.Close; //Disconnect
timer1.enabled := false; //Disable timer
end
else
begin
Vacomm1.Open; //Connect
timer1.enabled := true; //Enable Timer
end;
timer1.interval := StrToInt(edit1.text); //Set Timer Interval as needed
i := 0; //PC is node 0
n := 0;
end;
procedure TForm1.Timer1Timer(Sender: TObject); //On Timer Event
var
s : string;
begin
VaComm1.ControlRts := rtsDisabled; //Enable Transmitter
inc(i); //increase i to next lock number
if i > 5 then i := 0; //Only using 5 Locks
s := '#' + IntToStr(i);
VaComm1.WriteText(s); //Sends '#0' lock numbers 0 - 4
VaComm1.ControlRts := rtsEnabled; //Disable Transmitter
Sleep(10);
end;
procedure TForm1.VaComm1RxChar(Sender: TObject; Count: Integer);
var
datain : string;
match : boolean;
id : array[0..7] of byte;
begin
datain := VaComm1.readtext; //Receive '#' or ID from PIC
if datain <> '#' then //If not '#' must be ID
begin
timer1.enabled := false; //Stop sending to other locks
id[n] := datain; //Add PIC id's to PC id's
inc(n);
end;
if datain = '#' then //Got '#' PIC finished sending
begin
VaComm1.ControlRts := rtsDisabled; //Enable Transmitter
//check data base for lock i for match to id
//(if found match is true, if not match is false)
if match = true then
VaComm1.WriteText('#$') //Send '$' to open lock
else
VaComm1.WriteText('#?'); //Send '?' to not ot open lock
timer1.enabled := true; //Start poling PICs again
n := 0;
end;
end;
---------------------------------------------------------------------------------------
'PIC
Define LOADER_USED 1
@ DEVICE XT_OSC
define OSC 4
Include "MODEDEFS.BAS"
CMCON=7
ADCON1=7
ANSEL=0
TRISA=%00100000
TRISB=%00000101
DP VAR PORTB.0
SERRX VAR PORTB.2
SERTX VAR PORTB.5
Relay VAR PORTB.1
TR VAR PORTB.4
ID VAR BYTE[8]
I VAR Byte
N VAR Byte
LOW TR 'Enable Receiver, Disable Transmitter
Main_Loop:
OWOUT DP, 1, [$33] 'Issue Read ROM command
OWIN DP, 0, [str ID\8] 'Read data into the 8-byte array "ID"
If ID[0] = $01 Then gosub Send 'If ID found then goto Send loop (Familiy Code)
goto Main_Loop 'Repeat until DS1990A read
Send:
LOW TR 'Enable Receiver, Disable Transmitter
Serin SERRX,T2400,["#"],i 'Wait for PC to pole this lock
if i <> 1 then goto Send '1 - 5 Five locks - This is lock 1
HIGH TR 'Enable Transmitter, Disable Receiver
For N = 0 To 7
Serout SERTX,T2400,[#ID[N]] 'Send ID
Next
Serout Sertx, T2400,["#"] 'Done sending ID, now send #
LOW TR 'Enable Receiver, Disable Transmitter
Serin SERRX, T2400,["#"],i 'Wait to see if open lock or not
if i = "$" then 'Pc sends $ if ID matchs PC database
High Relay 'Open lock
Pause 5000 'For 5 seconds
Low Relay 'Close lock
Return 'Go back to Main_Loop
endif
if i = '?' then Return 'Don't open lock and go back to Main_Loop
Bookmarks