Recent

Author Topic: "Help"on Lazserial (list of methods, events etc)?  (Read 2687 times)

741

  • New Member
  • *
  • Posts: 17
"Help"on Lazserial (list of methods, events etc)?
« on: March 03, 2024, 11:35:34 am »
I've spent some time looking (without success) for a list of methods and events, hierarchy etc for LazSerial.

Is there a structured list of these things?

For example, with some classes like TBufStream, I can simply use F1 | Help. I'm looking for a similar collection information for TLazSerial.

dsiders

  • Hero Member
  • *****
  • Posts: 1282
Re: "Help"on Lazserial (list of methods, events etc)?
« Reply #1 on: March 03, 2024, 08:32:44 pm »
I've spent some time looking (without success) for a list of methods and events, hierarchy etc for LazSerial.

Is there a structured list of these things?

For example, with some classes like TBufStream, I can simply use F1 | Help. I'm looking for a similar collection information for TLazSerial.

The attached has skeleton topics for help. No real content, but the structure is there. 

LazSerial is a third party component hosted at: https://github.com/JurassicPork/TLazSerial with an active issue tracker. Ask the maintainer to provide proper Help files.


Preview the next Lazarus documentation release at: https://dsiders.gitlab.io/lazdocsnext

741

  • New Member
  • *
  • Posts: 17
Re: "Help"on Lazserial (list of methods, events etc)?
« Reply #2 on: March 10, 2024, 12:30:35 pm »
OK Thank you.

At least now I am pretty certain there are no "official" help files.

Dzandaa

  • Sr. Member
  • ****
  • Posts: 392
  • From C# to Lazarus
Re: "Help"on Lazserial (list of methods, events etc)?
« Reply #3 on: March 11, 2024, 10:11:57 am »
Hi,

This is a little template I wrote to test RS232 communications with ESP32 using 5DP0 Library:

Dezip and put the whole folder in your Template directory (Tool->Project templates options).
Run Lazarus then New project from template->RS232 5DP0 Form
Fill the Dialog with your values and compile.

It Works in Windows and Linux.

You must install SdpoSerialLaz (sdpo) and LazSerial from OPM

B->
Regards,
Dzandaa

wp

  • Hero Member
  • *****
  • Posts: 12471
Re: "Help"on Lazserial (list of methods, events etc)?
« Reply #4 on: March 11, 2024, 11:26:48 am »
I've spent some time looking (without success) for a list of methods and events, hierarchy etc for LazSerial.

Is there a structured list of these things?

For example, with some classes like TBufStream, I can simply use F1 | Help. I'm looking for a similar collection information for TLazSerial.
The best and ultimately up-to-date help information can be found in the source code itself. Learn to navigate the source code. If you need information on TLazSerial, CTLR+click on the word "TLazSerial" in the source editor --> the IDE will open the unit in which "TLazSerial" is declared and implemented. Depending on how your IDE is set up you may land in the interface or implementation part of the unit --> press SHIFT+CTRL+Up or Down to switch to the other part of the unit. In the interface then you see all the properties, methods and events of TLazSerial. If you then, for example, want to learn what the type TFlowControl of the property FlowControl is, repeat the same: CTRL-Click on "TFlowControl", and the IDE jumps to the line "TFlowControl=(fcNone,fcXonXoff,fcHardware)".

Of course, there are no describing words in this method, but - sincerely - most help files do not provide much more information.

PeterX

  • Sr. Member
  • ****
  • Posts: 422
Re: "Help"on Lazserial (list of methods, events etc)?
« Reply #5 on: November 16, 2024, 03:11:33 pm »
This is a little template I wrote to test RS232 communications with ESP32 using 5DP0 Library:
Good example !


Do You know what this parameter does + means ?

Published    property InterPacketTimeout
By default (True) is all timeouts used as timeout between two packets in reading operations. If you set this to False, then Timeouts is for overall reading operation!
usually using latest Lazarus release version with Windows 10

Dzandaa

  • Sr. Member
  • ****
  • Posts: 392
  • From C# to Lazarus
Re: "Help"on Lazserial (list of methods, events etc)?
« Reply #6 on: November 16, 2024, 04:52:34 pm »
Hi,
@Peterx:

From LazSynaSer:

{:If @true (default), then all timeouts is timeout between two characters.
     If @False, then timeout is overall for whole reading operation.}

That's all I know.

B->
Regards,
Dzandaa

PeterX

  • Sr. Member
  • ****
  • Posts: 422
Re: "Help"on Lazserial (list of methods, events etc)?
« Reply #7 on: November 16, 2024, 05:47:36 pm »
Okay, looks like property InterPacketTimeout only is for TBlockSerial.RecvBufferEx()
usually using latest Lazarus release version with Windows 10

PeterX

  • Sr. Member
  • ****
  • Posts: 422
Re: "Help"on Lazserial (list of methods, events etc)?
« Reply #8 on: November 17, 2024, 11:42:15 am »
LazSerial does not work for me.
So I try to understand what's the difference
between my "handmade code" and  LazSerial.

So here a question to CreateFile() which is used in
procedure TBlockSerial.Connect(comport: string); / unit LazSynaSer.pas line 1004

Code: Pascal  [Select][+][-]
  1.   FHandle := THandle(CreateFile(PChar(FDevice), GENERIC_READ or GENERIC_WRITE,
  2.     0, nil, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL or FILE_FLAG_OVERLAPPED, 0));
  3.  

What does this FILE_FLAG_OVERLAPPED in connection with a SerialPort / COM ?
usually using latest Lazarus release version with Windows 10

Dzandaa

  • Sr. Member
  • ****
  • Posts: 392
  • From C# to Lazarus
Re: "Help"on Lazserial (list of methods, events etc)?
« Reply #9 on: November 17, 2024, 12:33:45 pm »
Hi,

Here is the documentation from Microsoft:

Overlapped mode is enabled. If this mode is enabled, functions performing read, write, and connect operations that may take a significant time to be completed can return immediately. This mode enables the thread that started the operation to perform other operations while the time-consuming operation executes in the background. For example, in overlapped mode, a thread can handle simultaneous input and output (I/O) operations on multiple instances of a pipe or perform simultaneous read and write operations on the same pipe handle. If overlapped mode is not enabled, functions performing read, write, and connect operations on the pipe handle do not return until the operation is finished. The ReadFileEx and WriteFileEx functions can only be used with a pipe handle in overlapped mode. The ReadFile, WriteFile, ConnectNamedPipe, and TransactNamedPipe functions can execute either synchronously or as overlapped operations.

Hope that help.

What is the problem with LazSerial?

B->
Regards,
Dzandaa

PeterX

  • Sr. Member
  • ****
  • Posts: 422
Re: "Help"on Lazserial (list of methods, events etc)?
« Reply #10 on: November 17, 2024, 01:02:04 pm »
What is the problem with LazSerial?
I read in serial data from a Manufacturer specific RS485 protocoll.
I use a WaveShare RS485 to ETH device. TCP works fine (I use lnet).

There's software out there, that simulates COM devices from a TCP connection.
For testing I can only simulate a COM this way. Some users of my software
instead use a RS485 To USB device, for example DTECH DT-5019C.


When I read the SerialPort with a TTimer from the Main Thread (bad design .. :( ) every 80ms, I get full "packages".
They start with $32 and last byte is $34. The "filter" (=> TCheckBox) cuts off "trash" bytes coming ahead.

So - with a software simulated COM (data from TCP) - the packages are complete and readable.
But I read in these COM data in the main Thread, this slows down the GUI.
This was the reason why I tried LazSerial.
« Last Edit: November 17, 2024, 01:24:26 pm by PeterX »
usually using latest Lazarus release version with Windows 10

PeterX

  • Sr. Member
  • ****
  • Posts: 422
Re: "Help"on Lazserial (list of methods, events etc)?
« Reply #11 on: November 17, 2024, 01:04:06 pm »
Instead, with a real RS485 To USB device (which also simulates a COM under Windows),
for example DTECH DT-5019C, the data packages are cut into pieces, with LazSerial ..

In the screenshot You can find first byte $32 (below $ F9 FD FD FD)
and last byte $34.
But the full Manufacturer specific Message is spread over several line breaks  :(


In my "bad design" code I use a buffer of 128 bytes, for receiving the Data.
And in my "bad design" code the data packages are not trashed.
Code: Pascal  [Select][+][-]
  1. d : array[1..128] of char;
« Last Edit: November 17, 2024, 01:56:40 pm by PeterX »
usually using latest Lazarus release version with Windows 10

Dzandaa

  • Sr. Member
  • ****
  • Posts: 392
  • From C# to Lazarus
Re: "Help"on Lazserial (list of methods, events etc)?
« Reply #12 on: November 17, 2024, 02:45:02 pm »
Hi,
With Synarer and sdpoSerial, I use OnRxData to Capture Data

Code: Pascal  [Select][+][-]
  1. // ******************************
  2. // ***** RS232 Receive Data *****
  3. // ******************************
  4. procedure TTestRS232Form.RS232RxData(Sender: TObject);
  5. begin
  6.  if(not RS232.DataAvailable) then
  7.  begin
  8.   RXData := '';
  9.   Exit;
  10.  end;
  11.  RXData := RS232.ReadData;
  12.  
  13.  
  14.  TBRS232Rx.Append(RXData); // TMemo
  15. end;
  16.  

B->

P.S. I code only for windowed programs.
Regards,
Dzandaa

PeterX

  • Sr. Member
  • ****
  • Posts: 422
Re: "Help"on Lazserial (list of methods, events etc)?
« Reply #13 on: November 17, 2024, 06:55:45 pm »
Code: Pascal  [Select][+][-]
  1. // ******************************
  2. // ***** RS232 Receive Data *****
  3. // ******************************
  4. procedure TTestRS232Form.RS232RxData(Sender: TObject);
  5. begin
  6.  if(not RS232.DataAvailable) then
  7.  begin
  8.   RXData := '';
  9.   Exit;
  10.  end;
  11.  RXData := RS232.ReadData;
  12.  
  13.  TBRS232Rx.Append(RXData); // TMemo
  14. end;
  15.  

This piece of code was very helpful for me, thanks a lot !

In TLazSerial I went down the tree of sub-sub-sub functions
(TLazSerial.DataAvailable => TBlockSerial.CanReadEx / CanRead => TBlockSerial.WaitingData => TBlockSerial.SerialCheck)

and I extracted the following code for me (TSimpleSerialPort is my "trash code"):

Code: Pascal  [Select][+][-]
  1. function TSimpleSerialPort.DataAvailable: boolean;
  2. var
  3.   stat : TComStat;
  4.   err  : DWORD = 0;
  5. begin
  6.   if ComFileHandle = INVALID_HANDLE_VALUE then
  7.     begin
  8.       result:= false;
  9.       exit;
  10.     end;
  11.  
  12.   //result:= FSynSer.CanReadEx(0);
  13.   if ClearCommError( ComFileHandle, err, @stat)
  14.     then
  15.       begin
  16.         //SetSynaError(sOK);
  17.         Result := stat.cbInQue > 0;
  18.       end
  19.     else result:= false;
  20. end;  

Even without a separate Thread it starts going smoother, in the GUI.   :)
usually using latest Lazarus release version with Windows 10

PeterX

  • Sr. Member
  • ****
  • Posts: 422
Re: "Help"on Lazserial (list of methods, events etc)?
« Reply #14 on: November 22, 2024, 02:07:29 pm »
@Dzandaa

I found a solution for my needs.

This works even in the Main Thread, with a TTimer of 20ms  :D

Code: Pascal  [Select][+][-]
  1. var
  2.   SerialIsBusy : boolean = FALSE;
  3.  
  4. function TSimpleSerialPort.ReadDataCore:string;
  5. var
  6.   BytesRead : dword = 0;
  7.   status    : TComStat;
  8.   error     : DWORD = 0;
  9. begin
  10.   result:= '';
  11.   if SerialIsBusy then exit;
  12.   if ComFileHandle = INVALID_HANDLE_VALUE then exit;
  13.  
  14.   SerialIsBusy:= TRUE;
  15.   ClearCommError( ComFileHandle, error, @status);
  16.   // a Return value of Non-zero is = Success
  17.   // DRAGONS: result of ClearCommError() not handled here !
  18.  
  19.   if error = 0
  20.     then
  21.       begin
  22.         if status.cbInQue > 0 then
  23.           begin
  24.             // cbInQue = The number of bytes received by the serial provider but not yet read by a ReadFile operation.
  25.             SetLength( result, status.cbInQue);
  26.             ReadFile( ComFileHandle, result[1], status.cbInQue, BytesRead, nil);
  27.  
  28.             if BytesRead <> status.cbInQue then
  29.               begin
  30.                 // not jet handled
  31.               end;
  32.       end
  33.     ;//else  ... case Error of  ...
  34.  
  35.   SerialIsBusy:= FALSE;
  36. end;
  37.  
usually using latest Lazarus release version with Windows 10

 

TinyPortal © 2005-2018