Recent

Author Topic: Lazarus Hardware Interruptions  (Read 22709 times)

Jurassic Pork

  • Hero Member
  • *****
  • Posts: 1290
Re: Lazarus Hardware Interruptions
« Reply #30 on: July 16, 2013, 02:59:04 am »
try this :

Code: [Select]
var   buffer : array of Byte;
      x,buffersize: integer;
      msg : String;
begin
    msg:= '2f4a553a6c900195';
    x:= 0;
    bufferSize := Length(msg)div 2;
    SetLength(buffer,bufferSize);
    while x < bufferSize do
    begin
    buffer[x] := StrtoInt('$' + copy(msg,(x*2)+1,2));
    inc(x);
    end;               
« Last Edit: July 16, 2013, 03:01:28 am by Jurassic Pork »
Jurassic computer : Sinclair ZX81 - Zilog Z80A à 3,25 MHz - RAM 1 Ko - ROM 8 Ko

hac3ru

  • Full Member
  • ***
  • Posts: 113
Re: Lazarus Hardware Interruptions
« Reply #31 on: July 16, 2013, 09:25:59 am »
Going to try it right now.
Thanks mate.
Can you explain what's
Code: [Select]
buffer[x] := StrtoInt('$' + copy(msg,(x*2)+1,2)); doing exactly? Thank you
« Last Edit: July 16, 2013, 09:27:39 am by hac3ru »

Jurassic Pork

  • Hero Member
  • *****
  • Posts: 1290
Re: Lazarus Hardware Interruptions
« Reply #32 on: July 16, 2013, 12:30:03 pm »
Code: [Select]
buffer[x] := StrtoInt('$' + copy(msg,(x*2)+1,2));
copy the hex value of 2 characters of the string msg beginning at position (x*2) + 1 ( 1,3,5 etc...)

Jurassic computer : Sinclair ZX81 - Zilog Z80A à 3,25 MHz - RAM 1 Ko - ROM 8 Ko

hac3ru

  • Full Member
  • ***
  • Posts: 113
Re: Lazarus Hardware Interruptions
« Reply #33 on: July 16, 2013, 02:19:56 pm »
Thank you.

Now... I want to read buffer from the RS232... When I try to use LazSerial1.ReadBuffer is telling me that unit1.pas(86,24) Error: identifier idents no member "ReadBuffer"
Any ideas? :D

Actually, I just want to read from RS232... I tried using:
Code: [Select]
procedure TForm1.LazSerial1RxData(Sender: TObject);
var received:string;
begin
received:=LazSerial1.ReadData;
Label1.Caption:=received;
end;
Nothing is received. Even though, the microcontroller sends ff every second...
« Last Edit: July 16, 2013, 03:34:56 pm by hac3ru »

Jurassic Pork

  • Hero Member
  • *****
  • Posts: 1290
Re: Lazarus Hardware Interruptions
« Reply #34 on: July 17, 2013, 12:14:33 am »
hello hac3ru,

1 - If your microcontroller sends datas with no CRLF at the end, you must set the property RcvLineCRLF of the component tlazserial to false. The ReadData function will use RecvPacket in place of RecvString. If the property RcvLineCRLF is set to true, ReadData wait for CRLF.

2 - if your microcontroller sends no alphanumeric datas, you can't display some characters (ex FF 02 etc...)
To display  those datas, you can convert them to  hexa string value.

example for the rxData procedure :
Code: [Select]
procedure TFMain.SerialRxData(Sender: TObject);
var S,HexaS : string;
    i : integer;
begin
  S := Serial.ReadData;
  for i := 1 to Length(S) do begin
    HexaS := HexaS + InttoHex(Ord(S[i]),2)+ ' ';
  end;
Memo.lines.Add(HexaS);
end;

Friendly, J.P
« Last Edit: July 17, 2013, 12:21:36 am by Jurassic Pork »
Jurassic computer : Sinclair ZX81 - Zilog Z80A à 3,25 MHz - RAM 1 Ko - ROM 8 Ko

hac3ru

  • Full Member
  • ***
  • Posts: 113
Re: Lazarus Hardware Interruptions
« Reply #35 on: July 17, 2013, 08:29:29 am »
Thank you :)

How can I check if I have lost the connection with the RS232? :D
« Last Edit: July 17, 2013, 09:26:41 am by hac3ru »

Jurassic Pork

  • Hero Member
  • *****
  • Posts: 1290
Re: Lazarus Hardware Interruptions
« Reply #36 on: July 17, 2013, 10:11:08 am »
No response from me  :P  --> it depends of the hardware ( target, handshake  etc...)
Jurassic computer : Sinclair ZX81 - Zilog Z80A à 3,25 MHz - RAM 1 Ko - ROM 8 Ko

hac3ru

  • Full Member
  • ***
  • Posts: 113
Re: Lazarus Hardware Interruptions
« Reply #37 on: July 17, 2013, 10:52:14 am »
Ohh okay...
Now... I have a TrackBar that has min:=1 and max:=2. The problem is that when I change the position of the trackbar, it sends the data two times. I am using that Trackbar as an on/off switch. If 1 then ON else Off, but it is sending data twice => message gets sent twice.
Any ideas?
Got IT :)
« Last Edit: July 18, 2013, 04:34:19 pm by hac3ru »

hac3ru

  • Full Member
  • ***
  • Posts: 113
Re: Lazarus Hardware Interruptions
« Reply #38 on: August 06, 2013, 02:26:55 pm »
I've got a question: How is LazSerial.ReadData working? If I do:
Code: [Select]
on RXdata
var Receive:string;
Receive:=LazSerial1.ReadData;
Showmessage (Receive);
It shows ???<>:{@$? Characters... The target is sending a hexa string

I have also tried
Code: [Select]

On RXData
recv:='';
recv:=LazSerial1.ReadData;
Receive:=concat(receive,recv);
ShowMessage(receive);
When I tried this, I don't even see wierd characters.... It's just empty...
« Last Edit: August 06, 2013, 03:51:55 pm by hac3ru »

Jurassic Pork

  • Hero Member
  • *****
  • Posts: 1290
Re: Lazarus Hardware Interruptions
« Reply #39 on: August 06, 2013, 04:46:26 pm »
hello hac3ru,

have you read this message    ;D
Jurassic computer : Sinclair ZX81 - Zilog Z80A à 3,25 MHz - RAM 1 Ko - ROM 8 Ko

hac3ru

  • Full Member
  • ***
  • Posts: 113
Re: Lazarus Hardware Interruptions
« Reply #40 on: August 06, 2013, 10:17:30 pm »
Yup... But still... Shouldn't I be able to show SOMETHING? Like... The integer numbers?

I will try it in the morning and see if it works. Thank you for your time mate.


And .... Am I getting the entire message using ReadData? I mean, the target is sending me ff02dcf235618facb8148b for example.
ReadData will get all that in one go?

Code: [Select]

procedure TForm1.LazSerial1RxData(Sender: TObject);
var
  rcv,received: string;
var
  i: integer;
begin
  rcv:='';
  Form2.Label1.Caption := 'Something was received. Check memo1 to see what.';
  rcv :=LazSerial1.ReadData;
  for i:=1 to Length(rcv) do
    received:=received + IntToHex(Ord(rcv[i]),2) + ' ';
  Form2.Memo1.Lines.Add('String received is:' + rcv);
end;     
Still not working :( I am getting those chars .....
If the target machine is sending only 1 character at a time, it is working. If it is sending a hexa string, I can't "decode" it...

Okay. Taking my words back. It is working but .... It's too slow. The target is sending data very fast and I can't get it fast enough .... If the target is sending 1 char at a time, I can see it correctly. If it sends multiple, it won't work :( Any ideas?
« Last Edit: August 07, 2013, 09:51:28 am by hac3ru »

hac3ru

  • Full Member
  • ***
  • Posts: 113
Re: Lazarus Hardware Interruptions
« Reply #41 on: August 07, 2013, 10:21:47 am »
Jurassic Pork thank you for your time.

If you want, you can add the following function in your LazSerial com library:
Code: [Select]
function TLazSerial.ReadByte: Byte;
begin
  if FSynSer.Handle=INVALID_HANDLE_VALUE then
    ComException('can not read from a closed port.');
  result:=FSynSer.RecvByte(0)
end;
Using this function, you get one byte at a time and this seems to have fixed my problem.
It can be used on event OnRXData. I am using it like
Code: [Select]
procedure TForm1.LazSerial1RxData(Sender: TObject);
var
  rcv: string;
  rcvbyte:byte;
begin
  rcvbyte:=LazSerial1.ReadByte;
  rcv:=rcv + IntToStr(rcvbyte);
  Form2.Memo1.Lines.Add('Received: '+rcv);
end;   
I get in Memo1 the correct message. Seems to be all good.
As I said, if you want, you can include it into your library. Maybe it will help someone.

Jurassic Pork

  • Hero Member
  • *****
  • Posts: 1290
Re: Lazarus Hardware Interruptions
« Reply #42 on: August 07, 2013, 10:40:56 am »
have you tried with property RcvLineCRLF of the component tlazserial to false. In this case onrxdata use recvpacket not recvString. For binary datas it is what you need.
Jurassic computer : Sinclair ZX81 - Zilog Z80A à 3,25 MHz - RAM 1 Ko - ROM 8 Ko

hac3ru

  • Full Member
  • ***
  • Posts: 113
Re: Lazarus Hardware Interruptions
« Reply #43 on: August 07, 2013, 03:22:13 pm »
Yup. It was always set to false. Don't know why it wasn't working.
I'm just glad I got it to work :)

Thanks for help mate :)

 

TinyPortal © 2005-2018