EmbeddedRelated.com
Forums

BX-24 to and from Delphi problem

Started by William Keith March 22, 2004
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



Whoops

The comments seem to cause a problem so here is the code again.

Delphi
Program----------

procedure TForm1.Button1Click(Sender: TObject);
var
b : integer
begin
listbox1.clear;
b := 255;
ComPort.Write(b, 2);
end;

procedure TForm1.Button2Click(Sender: TObject);
var
b : integer;
begin
If edit5.text <> '' then
begin
b := 254;
ComPort.Write(b, 2);
b := StrToInt(edit5.text);
ComPort.Write(b, 2);
end;
end;

procedure TForm1.ComPortRxChar(Sender: TObject; Count: Integer);
var
str : string;
begin
ComPort.ReadStr(Str, Count);
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

If StatusQueue(ICom) then
Call GetQueue(ICom, b, 1)
If b = 255 then
Dat = SPIEEPROMRead(0)
Str = CStr(Dat)
Call PutQueueStr(OCom, Str)
Call ClearQueue(ICom)
End If
If b = 254 then
Call ClearQueue(ICom)
Do
If StatusQueue(ICom) then
Call GetQueue(ICom, Dat, 1)
If Dat > 0 then
Call SPIEEPROMWrite(0, Dat)
Exit Do
End If
End If
Loop
End If
End If

Loop

End Sub

Thank you
William



Hi.

I haven't used Delfi, but...

What does the following statement do?

ComPort.Write(b, 2);

As b is defined as integer (normally 2 bytes) I wouldn't be suprised
if it sends 00 FF (or FF 00) for 255 and 00 FE (or FE 00) for 254.

Just a guess where the zero comes from.

Rgds
Ingvar


Ingvar

Talk about sleeping at the wheel!
You hit it right on the head!

Thanks very much!

William

----- Original Message -----
From: "Ingvar Esk" <>
To: <>
Sent: Monday, March 22, 2004 1:37 PM
Subject: [BasicX] Re: BX-24 to and from Delphi problem > Hi.
>
> I haven't used Delfi, but...
>
> What does the following statement do?
>
> ComPort.Write(b, 2);
>
> As b is defined as integer (normally 2 bytes) I wouldn't be suprised
> if it sends 00 FF (or FF 00) for 255 and 00 FE (or FE 00) for 254.
>
> Just a guess where the zero comes from.
>
> Rgds
> Ingvar >
>
> Yahoo! Groups Links