Hello
I am having a problem with the code below.
The Delphi & BX-24 codes appears to work ok except for the following.
I seem to be getting 0's sent to the BX-24 (or the BX-24 is picking up
false
data somewhere) which causes false data readings. I inserted "If Dat >
0
then" into the BX-24 code and all seemed to be ok.
Here's the problem with the "If Dat > 0 then" in the BX-24
code when I need
to send a legitimate 0 to the BX-24 I can no longer receive the 0
Does anyone know what is going on here and can you advise on a better way of
doing this or cleaning up the code?
Delphi
Program---------------------------------
---------------------
procedure TForm1.Button1Click(Sender: TObject);
var
b : integer
begin
listbox1.clear;
b := 255;
ComPort.Write(b, 2); // Sent 255 to BX-24 - BX-24 sends back data
end;
procedure TForm1.Button2Click(Sender: TObject);
var
b : integer;
begin
If edit5.text <> '' then
begin
b := 254;
ComPort.Write(b, 2); //Send 254 to BX-24, BX-24
waits for following data
b := StrToInt(edit5.text);
ComPort.Write(b, 2); //Data send to BX-24 stored
in external eeprom
end;
end;
procedure TForm1.ComPortRxChar(Sender: TObject; Count: Integer);
var
str : string;
begin
ComPort.ReadStr(Str, Count); //Data from BX-24
ListBox1.Items.Add(Str);
end;
BX-24
Program---------------------------------
--------------------
Dim ICom(1 to 30) As Byte
Dim OCom(1 to 30) As Byte
Dim Str As String
Sub Main()
Dim b as Byte
'Dim n as Integer
Dim Dat as Byte
Call OpenQueue(ICom, 30)
Call OpenQueue(OCom, 30)
Call OpenCom(1, 4800, ICom, OCom)
Do 'BX-24 loops looking for
254 or 255
If StatusQueue(ICom) then 'data in ICom
Call GetQueue(ICom, b, 1) 'get the data from
ICom
If b = 255 then '255 found
Dat = SPIEEPROMRead(0) 'read data at ext
eeprom address 0 into Dat
Str = CStr(Dat) 'convert
Dat to Str
Call PutQueueStr(OCom, Str) 'send data (OCom) to
PC (Delphi)
Call ClearQueue(ICom) 'clear ICom
End If
If b = 254 then '254
found
Call ClearQueue(ICom) 'clear ICom
Do
'loop looking for next data
If StatusQueue(ICom) then 'data in ICom
Call GetQueue(ICom, Dat, 1) 'get the data from
ICom
If Dat > 0 then
'Inserted this to stop false 0's
Call SPIEEPROMWrite(0, Dat) 'write Dat to ext
eeprom at address 0
Exit Do 'data
found and written, get out of loop
End If
End If
Loop
End If
End If
Loop
End Sub
Thank you
William
|