[fpc-pascal] Serial to TCP gateway in FPC?

Mark Morgan Lloyd markMLl.fpc-pascal at telemetry.co.uk
Wed Jun 21 10:02:00 CEST 2017


On 21/06/17 05:30, Bo Berglund wrote:
> On Wed, 21 Jun 2017 01:57:36 +0200, José Mejuto<joshyfun at gmail.com> wrote:
>>> The problem I have is that it seems only to work for COM1 or COM3, as>> soon as I use a higher numbered port like COM33 then it fails.>> What have I missed here?>> Is serial only able to work with the low numbered ports (single>> digit)?>>COM ports in windows can only be 1-9, to open high numbered COM ports >you must use the extended name syntax (without quotes) "\\.\COM99" you >can also use "\\.\COM1" for COM1-9.
> It turns out that I also must not use the trailing colon in the namewhich is present in the wiki example...But then I get a non-zero handle. I have yet to verify that data canflow.

> Is there a way to enumerate the available com ports so that they canbe listed in a combobox for selection? This would have the advantagethat it would work on both Windows and Linux and it limits thepossible errors by the user. Of course the enumerator must know aboutthe differences in syntax between Windows and Linux!

Not reliably in unix. You have to know the various potential name 
patterns, i.e. /dev/ttyS*, /dev/ttyAMA* and so on, and then enumerate 
what's currently visible in the filesystem. It might be possible to get 
"hints" as to the device type from the /sys filesystem, but I'm not sure 
it's safe to rely on this.

> What about Linux (Raspberry Pi)? Is the com port name simply ttyUSB1or do I have to use the full /dev/ttyUSB1?

You *definitely* have to use the name as given. You're opening a file in 
the filesystem tree, not an internally-reserved name.

-- 
Mark Morgan Lloyd
markMLl .AT. telemetry.co .DOT. uk

[Opinions above are the author's, not those of his employers or colleagues]



More information about the fpc-pascal mailing list