Recent

Author Topic: Read RTS and DTR pin logic states with Synaser (on Windows)  (Read 726 times)

Kepsz

  • New Member
  • *
  • Posts: 36
Read RTS and DTR pin logic states with Synaser (on Windows)
« on: September 15, 2025, 10:23:57 am »
Hi,

In Synaser, we can read the logic states of DSR and CTS pins, but not RTS and DTR.
RTS and DTR pin logic states can only be written by using the EscapeCommFunction, that is declared in redef.inc

In redef.inc, we have this: DeviceIoControl, that in theory can access to the logic states of RTS and DTR pins.


I tried to test it in this very basic code:
Code: Pascal  [Select][+][-]
  1. function TBlockSerial.GetRTSF;
  2. var
  3.   iostatus, tmp: DWORD;
  4.   testlw: longword;
  5.   olp: POVERLAPPED;
  6.  
  7. begin
  8. {$IFNDEF MSWINDOWS}
  9.  
  10. {$ELSE}
  11.   DeviceIoControl(FHandle, 1769592{IOCTL_SERIAL_GET_DTRRTS}, @testlw, 0, @iostatus, sizeof(iostatus), @tmp, @olp);
  12.   result := true;
  13. {$ENDIF}
  14. end;

But the problem is IOCTL_SERIAL_GET_DTRRTS is a macro, that is only defined in ntddser.h header file. https://doxygen.reactos.org/d5/d2e/ntddser_8h_source.html#l00056 1769592 is a value for that according to chatgpt, but it is deffinitly wrong.

Is there a way to get use that macro? Or is it defined in some unit?
Or is there a better way to get the logic states of those pins?

More info:
https://stackoverflow.com/questions/59408368/getting-dtr-and-rts-pin-of-serial-port-in-c-on-windows-platform
https://learn.microsoft.com/en-us/windows/win32/devio/calling-deviceiocontrol

marcov

  • Administrator
  • Hero Member
  • *
  • Posts: 12536
  • FPC developer.
Re: Read RTS and DTR pin logic states with Synaser (on Windows)
« Reply #1 on: September 15, 2025, 10:42:01 am »
My own calculation comes out on 2064384.

Parameterized compiletime macros can't be used as is, but sometimes you can write a function for them to calculate them.

Kepsz

  • New Member
  • *
  • Posts: 36
Re: Read RTS and DTR pin logic states with Synaser (on Windows)
« Reply #2 on: September 15, 2025, 10:55:57 am »
Both values have the same result in iostatus. I guess it is simpler to store the RTS / DTR IO logic values in variables when the write function sets them.

MarkMLl

  • Hero Member
  • *****
  • Posts: 8505
Re: Read RTS and DTR pin logic states with Synaser (on Windows)
« Reply #3 on: September 15, 2025, 11:57:22 am »
In Synaser, we can read the logic states of DSR and CTS pins, but not RTS and DTR.
RTS and DTR pin logic states can only be written by using the EscapeCommFunction, that is declared in redef.inc

FPC is cross-platform, and in the general case those pins are output-only.

MarkMLl
MT+86 & Turbo Pascal v1 on CCP/M-86, multitasking with LAN & graphics in 128Kb.
Logitech, TopSpeed & FTL Modula-2 on bare metal (Z80, '286 protected mode).
Pet hate: people who boast about the size and sophistication of their computer.
GitHub repositories: https://github.com/MarkMLl?tab=repositories

Jurassic Pork

  • Hero Member
  • *****
  • Posts: 1290
Re: Read RTS and DTR pin logic states with Synaser (on Windows)
« Reply #4 on: September 15, 2025, 05:18:12 pm »
 ;D
Jurassic computer : Sinclair ZX81 - Zilog Z80A à 3,25 MHz - RAM 1 Ko - ROM 8 Ko

Kepsz

  • New Member
  • *
  • Posts: 36
Re: Read RTS and DTR pin logic states with Synaser (on Windows)
« Reply #5 on: September 16, 2025, 08:34:30 am »
;D

It is done with LazSerial? LazSerial has the mentioned functionality but I had to implement this in a quite complex app that built around synaser.

Jesterday I was able to implement this into synaser, it is working.

Jurassic Pork

  • Hero Member
  • *****
  • Posts: 1290
Re: Read RTS and DTR pin logic states with Synaser (on Windows)
« Reply #6 on: September 16, 2025, 01:19:55 pm »
It is done with LazSerial? LazSerial has the mentioned functionality but I had to implement this in a quite complex app that built around synaser.
Hello,
if your project is a GUI project may be you can use LazSerial because TBlockSerial  is a part of the TLazSerial component :
Code: Pascal  [Select][+][-]
  1.  TLazSerial = class(TComponent)
  2.   private
  3.     FActive: boolean;
  4.     FSynSer: TBlockSerial;
  5.     FDevice: string;  

but if your project is a console project use synaser.   TLazserial is an event driven component.

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

Kepsz

  • New Member
  • *
  • Posts: 36
Re: Read RTS and DTR pin logic states with Synaser (on Windows)
« Reply #7 on: September 17, 2025, 09:02:14 am »
It is done with LazSerial? LazSerial has the mentioned functionality but I had to implement this in a quite complex app that built around synaser.
Hello,
if your project is a GUI project may be you can use LazSerial because TBlockSerial  is a part of the TLazSerial component :
Code: Pascal  [Select][+][-]
  1.  TLazSerial = class(TComponent)
  2.   private
  3.     FActive: boolean;
  4.     FSynSer: TBlockSerial;
  5.     FDevice: string;  

but if your project is a console project use synaser.   TLazserial is an event driven component.

Friendly, J.P

Yeah, it is a quite complex gui app with threading for the best possible serial troughput.
But storing RTS and DTR IO states locally in Synaser works great, I will recommend them to implement this feature.

 

TinyPortal © 2005-2018