Recent

Author Topic: TLazSerial : serial port component for Lazarus (windows and linux).  (Read 368136 times)

tetrastes

  • Hero Member
  • *****
  • Posts: 610
Re: TLazSerial : serial port component for Lazarus (windows and linux).
« Reply #465 on: December 05, 2024, 12:26:29 pm »
Actually, I am not sure if LazSerial1.FlowControl := fcHardware; is usable at all, it seems to me it does too many things that it should not do.
Sincerely, I know nothing about Serial communication so I might be wrong, but I have compared the behaviour of several other serial terminals and they do not behave this way.
It sets RTS/CTS handshaking flow control, nothing else.
If you set other terminals to this flow control, they should behave the same way.
« Last Edit: December 05, 2024, 12:30:28 pm by tetrastes »

CM630

  • Hero Member
  • *****
  • Posts: 1211
  • Не съм сигурен, че те разбирам.
    • http://sourceforge.net/u/cm630/profile/
Re: TLazSerial : serial port component for Lazarus (windows and linux).
« Reply #466 on: December 06, 2024, 03:30:51 pm »
I am trying to set the most common configuration (see image attached).
But I cannot find a way to set XonXoff_and_DTR_DSR. I found no way to set SERIAL_RTS_CONTROL to 1. Any clue about that?


The other settings seem to be fine, but I intend to recheck once or twice again.


Code: Pascal  [Select][+][-]
  1.  
  2. type
  3.   THandFlow = (hfNone,hfXonXoff,hfRTS_CTS,hfXonXoff_and_RTS_CTS,hfDTR_DSR,hfXonXoff_and_DTR_DSR);
  4.  
  5.  
  6. ....
  7.  
  8.  
  9. procedure SetHandFlow(HandFlow: THandFlow; var aLazSerial: TLazSerial);
  10. begin
  11.   with aLazSerial.SynSer.DCB do
  12.   begin
  13.     Flags := dcb_Binary; //$00000001;
  14.     case HandFlow of
  15.       hfNone    : Flags := Flags and not dcb_RtsControlEnable;
  16.       hfXonXoff : begin Flags := Flags or dcb_OutX or dcb_InX; Flags := Flags or dcb_DtrControlEnable; end;
  17.       hfDTR_DSR : Flags := Flags or dcb_DtrControlEnable;
  18.       hfRTS_CTS : Flags := Flags or dcb_OutxCtsFlow or dcb_RtsControlHandshake; //aka Hardware
  19.       hfXonXoff_and_RTS_CTS : begin Flags := Flags or dcb_OutX or dcb_InX; Flags := Flags or dcb_DtrControlEnable; Flags := Flags or dcb_OutxCtsFlow or dcb_RtsControlHandshake; end;
  20.       hfXonXoff_and_DTR_DSR : begin {Flags := Flags or dcb_DtrControlHandshake; Flags := Flags or dcb_OutX or dcb_InX {or dcb_DtrControlMask} or $22;} Flags := Flags or $322  end;
  21.     end; //case
  22.   end; //with
  23.   aLazSerial.SynSer.SetCommState;
  24. end;  
  25.  

Лазар 4,0RC1 32 bit (sometimes 64 bit); FPC3,2,2

mas steindorff

  • Hero Member
  • *****
  • Posts: 553
Re: TLazSerial : serial port component for Lazarus (windows and linux).
« Reply #467 on: December 06, 2024, 10:05:31 pm »
if your using windows ...
SetDTRf(value)
GetDSR()

not sure about if the library automatically handles the hold and release chars
windows 10 &11, Ubuntu 21+ IDE 3.4 general releases

tetrastes

  • Hero Member
  • *****
  • Posts: 610
Re: TLazSerial : serial port component for Lazarus (windows and linux).
« Reply #468 on: December 06, 2024, 10:20:10 pm »
I am trying to set the most common configuration (see image attached).
Your image looks weird to me. You confused with terminology. F.e., DTR_CONTROL is the name of line (signal). It can be set to one of three states: DTR_CONTROL_DISABLE (0), DTR_CONTROL_ENABLE (1), and DTR_CONTROL_HANDSHAKE (auto switching). You have to read about RS232 control lines and flow controls, and this https://learn.microsoft.com/en-us/windows/win32/api/winbase/ns-winbase-dcb.

But I cannot find a way to set XonXoff_and_DTR_DSR. I found no way to set SERIAL_RTS_CONTROL to 1. Any clue about that?

Code: Pascal  [Select][+][-]
  1. port.Config(baud, bits, parity, stop, true, false);      // set Xon/Xoff and enable RTS control line (dcb.Flags := dcb.Flags or dcb_RtsControlEnable;). Also note that in port.Connect() there is RTS:=True already.        
  2. port.GetCommState;
  3. port.dcb.Flags := port.dcb.Flags and not (dcb_DtrControlEnable or dcb_DsrSensivity);
  4. port.dcb.Flags := port.dcb.Flags or dcb_OutxDsrFlow or dcb_DtrControlHandshake;    // add DTR/DSR handshaking
  5. port.SetCommState;
  6.  


« Last Edit: December 06, 2024, 10:45:31 pm by tetrastes »

tetrastes

  • Hero Member
  • *****
  • Posts: 610
Re: TLazSerial : serial port component for Lazarus (windows and linux).
« Reply #469 on: December 06, 2024, 10:33:38 pm »
if your using windows ...
SetDTRf(value)
GetDSR()

These functions are protected, you cannot use them directly. They are for properties
Code: Pascal  [Select][+][-]
  1.     {:Use this property to set the value of the DTR signal.}
  2.     property DTR: Boolean write SetDTRF;
  3.  
  4.     {:Exposes the status of the DSR signal.}
  5.     property DSR: boolean read GetDSR;
  6.  
  7. . . .
  8.     port.DTR := false;
  9.     boolVar := port.DSR;

And they these properties can be used not only in windows.
« Last Edit: December 06, 2024, 10:41:12 pm by tetrastes »

CM630

  • Hero Member
  • *****
  • Posts: 1211
  • Не съм сигурен, че те разбирам.
    • http://sourceforge.net/u/cm630/profile/
Re: TLazSerial : serial port component for Lazarus (windows and linux).
« Reply #470 on: December 09, 2024, 12:39:36 pm »

Your image looks weird to me. You confused with terminology. F.e., DTR_CONTROL is the name of line (signal). It can be set to one of three states: DTR_CONTROL_DISABLE (0), DTR_CONTROL_ENABLE (1), and DTR_CONTROL_HANDSHAKE (auto switching). You have to read about RS232 control lines and flow controls, and this https://learn.microsoft.com/en-us/windows/win32/api/winbase/ns-winbase-dcb.
That is what the sniffer shows. My cunning plan is to make those routines once and forget about them. Anyway, here https://learn.microsoft.com/en-us/windows-hardware/drivers/ddi/ntddser/ns-ntddser-_serial_handflow the listed values are SERIAL_DTR_CONTROL and SERIAL_DTR_HANDSHAKE. But I assume SERIAL_DTR_CONTROL  and SERIAL_DTR_HANDSHAKE cannot both be equal to zero at the same time.


Your help worked, I have now:


Code: Pascal  [Select][+][-]
  1. procedure SetHandFlow(HandFlow: THandFlow; var aLazSerial: TLazSerial);
  2. begin
  3.   with aLazSerial.SynSer.DCB do
  4.   begin
  5.     Flags := dcb_Binary; //$00000001;
  6.     case HandFlow of
  7.       hfNone    : Flags := Flags and not dcb_RtsControlEnable;
  8.       hfXonXoff : begin Flags := Flags or dcb_OutX or dcb_InX; Flags := Flags or dcb_DtrControlEnable; end;
  9.       hfDTR_DSR : Flags := Flags or dcb_DtrControlEnable;
  10.       hfRTS_CTS : Flags := Flags or dcb_OutxCtsFlow or dcb_RtsControlHandshake; //aka Hardware
  11.       hfXonXoff_and_RTS_CTS : begin Flags := Flags or dcb_OutX or dcb_InX; Flags := Flags or dcb_DtrControlEnable; Flags := Flags or dcb_OutxCtsFlow or dcb_RtsControlHandshake; end;
  12.       hfXonXoff_and_DTR_DSR : begin Flags := Flags or dcb_DtrControlHandshake or dcb_OutxDsrFlow or dcb_OutX or dcb_InX or dcb_RtsControlToggle; Flags := Flags and not dcb_RtsControlHandshake; end;
  13.     end; //case
  14.   end; //with
  15.   aLazSerial.SynSer.SetCommState;
  16. end;
  17.  
   




But it seems that everyone has a different idea about what DTR/DSR shall be.
I sniffed several terminal apps, two of them set it as:
SERIAL_DTR_HANDSHAKE = 1; SERIAL_DSR_HANDSHAKE =1; SERIAL_RTS_CONTROL = 1; everything else = 0.


One of them sets different values each time.
And another one sets SERIAL_DTR_CONTROL = 1; SERIAL_CTS_HANDSHAKE = 1; everything else = 0.


In order to connect to the multimeter I need SERIAL_DTR_CONTROL = 1; SERIAL_CTS_HANDSHAKE = *; everything else = 0;
Most terminal apps do not have this mode (once is named DTR/DSR, once is RS485, the multimeter is actually a regular RS232 on 9V).
« Last Edit: December 09, 2024, 01:27:02 pm by CM630 »
Лазар 4,0RC1 32 bit (sometimes 64 bit); FPC3,2,2

tetrastes

  • Hero Member
  • *****
  • Posts: 610
Re: TLazSerial : serial port component for Lazarus (windows and linux).
« Reply #471 on: December 09, 2024, 03:12:30 pm »
Anyway, here https://learn.microsoft.com/en-us/windows-hardware/drivers/ddi/ntddser/ns-ntddser-_serial_handflow the listed values are SERIAL_DTR_CONTROL and SERIAL_DTR_HANDSHAKE.
This link is for drivers writers. Synaser doesn't use this. But the sense of fields is the same. If you want to use this, you are on your own. First of all you have to understand how RS-232 lines work.

Quote
But I assume SERIAL_DTR_CONTROL  and SERIAL_DTR_HANDSHAKE cannot both be equal to zero at the same time.
Of course they can, because the whole member ControlHandShake can be zero: "This member is set to zero or to the bitwise-OR or one or more of the following flags." from your link.

Quote
But it seems that everyone has a different idea about what DTR/DSR shall be.
I sniffed several terminal apps, two of them set it as:
SERIAL_DTR_HANDSHAKE = 1; SERIAL_DSR_HANDSHAKE =1; SERIAL_RTS_CONTROL = 1; everything else = 0.
This is what I have written you.

Quote
And another one sets SERIAL_DTR_CONTROL = 1; SERIAL_CTS_HANDSHAKE = 1; everything else = 0.
Code: Pascal  [Select][+][-]
  1. port.Config(baud, bits, parity, stop, false, false);
  2. // RTS and DTR are set at this moment
  3. port.RTS := false;    // as everything else = 0  
  4. port.GetCommState;
  5. port.dcb.Flags := port.dcb.Flags and not dcb_RtsControlEnable;   // as everything else = 0
  6. port.dcb.Flags := port.dcb.Flags or dcb_OutxCtsFlow;  
  7. port.SetCommState;
  8.  
This is something not standard, and of course it is not DTR/DSR handshaking.

Quote
In order to connect to the multimeter I need SERIAL_DTR_CONTROL = 1; SERIAL_CTS_HANDSHAKE = *; everything else = 0;
Are you sure that RTS must be OFF? If not, and "*" means "do not care", simply
Code: Pascal  [Select][+][-]
  1. port.Config(baud, bits, parity, stop, false, false);
otherwise use the above.

CM630

  • Hero Member
  • *****
  • Posts: 1211
  • Не съм сигурен, че те разбирам.
    • http://sourceforge.net/u/cm630/profile/
Re: TLazSerial : serial port component for Lazarus (windows and linux).
« Reply #472 on: December 09, 2024, 04:05:20 pm »
...
Quote
But I assume SERIAL_DTR_CONTROL  and SERIAL_DTR_HANDSHAKE cannot both be equal to zero at the same time.
Of course they can, because the whole member ControlHandShake can be zero: "This member is set to zero or to the bitwise-OR or one or more of the following flags." from your link.
...
Ooops, I meant 1, but wrote 0. %)
Лазар 4,0RC1 32 bit (sometimes 64 bit); FPC3,2,2

 

TinyPortal © 2005-2018