Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / fpc-pascal / 2008-07

Serial Unit for Windows

5 messages · 3 people · –

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Stephano

I posted the same a week ago in FPC-devel, and did not get any feedback. I am posting the same here hoping to get some feedback :)

I have made some modifications to the windows unit of Luis R. Hilario B. in order to pave the way for cross-platform usage.

I would like to have feedback before touching the Unix serial unit.

Any testing and/or input is appreciated.

====================================================================== TSerialFlag has been introduced because the flags should not normally be mixed.

The following flow control options are available:
None
Xon/Xoff
RTS/CTS
DTR/DSR

TSerialFlags was left for compatibility reasons. It could be abolished in the future.

Procedure SerSet was overloaded to use both TSerialFlag and TSerialFlags.

If a port fails to open, SerOpen will return UnusedHandle to have multiplatform compatibility.

There are 2 constants in unit rtl\win\wininc\struct.inc that seem to be wrongly declared:
bm_DCB_fRtsControl = $3000. It should be $2000.
bm_DCB_fDtrControl = $30. It should be $20.

When these are corrected, the -$1000 and -$10 in the code below should be removed accordingly.

Michael Van Canneyt
to Stephano
Stephano wrote 9 lines
I posted the same a week ago in FPC-devel, and did not get any feedback. I am posting the same here hoping to get some feedback :) I have made some modifications to the windows unit of Luis R. Hilario B. in order to pave the way for cross-platform usage. I would like to have feedback before touching the Unix serial unit. Any testing and/or input is appreciated.

I looked at the unit the first time you posted it, but there is little I can do: I don't do serial programming.

I think it is best if you contact someone who does serial programming directly, and ask them to test this unit.

Michael.

Show quoted text 29 lines
====================================================================== TSerialFlag has been introduced because the flags should not normally be mixed. The following flow control options are available: None Xon/Xoff RTS/CTS DTR/DSR TSerialFlags was left for compatibility reasons. It could be abolished in the future. Procedure SerSet was overloaded to use both TSerialFlag and TSerialFlags. If a port fails to open, SerOpen will return UnusedHandle to have multiplatform compatibility. There are 2 constants in unit rtl\win\wininc\struct.inc that seem to be wrongly declared: bm_DCB_fRtsControl = $3000. It should be $2000. bm_DCB_fDtrControl = $30. It should be $20. When these are corrected, the -$1000 and -$10 in the code below should be removed accordingly.
Zaher Dirkey
to Michael Van Canneyt
> bm_DCB_fRtsControl = $3000. It should be $2000. > bm_DCB_fDtrControl = $30. It should be $20.

DtrControl and RtsControl have double bits so it should be as mask

in same struct.inc you can see

  function fDtrControl(var a : DCB) : DWORD;
    begin
       fDtrControl:=(a.flags and bm_DCB_fDtrControl) shr bp_DCB_fDtrControl;
    end;

here fDtrControl return a number 0..3 as DWORD not boolean.

for your code is wrong becuase dtrcontrol/rtscontrol have 4 state not one as you use it

  if DtrDsrFlowControl in Flags then
    DCB.Flags := DCB.Flags or bm_DCB_fOutxDsrFlow or (bm_DCB_fDtrControl -$10);

You can use new constants like as synaser http://synapse.ararat.cz/doku.php

  dcb_DtrControlMask = $00000030;
  dcb_DtrControlDisable = $00000000;
  dcb_DtrControlEnable = $00000010;
  dcb_DtrControlHandshake = $00000020;
  dcb_RtsControlMask = $00003000;
  dcb_RtsControlDisable = $00000000;
  dcb_RtsControlEnable = $00001000;
  dcb_RtsControlHandshake = $00002000;
  dcb_RtsControlToggle = $00003000;
Stephano
to Michael Van Canneyt: I looked at the unit the first time you posted it, but there is little I can do: I don't…
Michael Van Canneyt wrote 9 lines
I looked at the unit the first time you posted it, but there is little I can do: I don't do serial programming. I think it is best if you contact someone who does serial programming directly, and ask them to test this unit. Michael.

I will acquire some serial devices soon for testing. But I was looking as well for general comments on the code if any.

Thanks

Stephano
to Zaher Dirkey: DtrControl and RtsControl have double bits so it should be as mask in same struct.inc you…
Zaher Dirkey wrote 12 lines
>> bm_DCB_fRtsControl = $3000. It should be $2000. >> bm_DCB_fDtrControl = $30. It should be $20. DtrControl and RtsControl have double bits so it should be as mask in same struct.inc you can see function fDtrControl(var a : DCB) : DWORD; begin fDtrControl:=(a.flags and bm_DCB_fDtrControl) shr bp_DCB_fDtrControl; end;

How could I have missed that? I did not seek to interpret what the bm_ and bp_ were. Thanks for pointing that out.
Consequently, bm_DCB_fRtsControl ($3000) and bm_DCB_fDtrControl ($30) are correct.

Show quoted text 5 lines
here fDtrControl return a number 0..3 as DWORD not boolean. for your code is wrong becuase dtrcontrol/rtscontrol have 4 state not one as you use it

True, but we do not need to expose the programmer to all of these states, do we? For example, in the Com port settings (Windows device manager), available options for the flow control (handshaking) are: None
XOn/XOff
Hardware
What does hardware represent in terms of these flags?

Thanks