serial ports under Unix using Freepascal

classic Classic list List threaded Threaded
6 messages Options
Reply | Threaded
Open this post in threaded view
|

serial ports under Unix using Freepascal

papelhigienico@gmail.com
Hi!

I'm creating a component that handles serial port in windows/unix. Under Windows I include in uses the unit windows, that open, close, read, write, test if the configuration of serial port is valid (some set of configurations of baudrate, stop bits and parity is invalid in windows)  and if serial port exists.

Under Unix I found the unit Serial, that open, close, read and write. How to test if serial port exist? Unix accept any set of configurations of  the serial port? I see fpopen that return the handle of serial port but I not found anything that describes error codes returned by this function in fpc rtl documentation.

Somebody have tried to do this?

info: I newbie in FPC Unix (FreeBSD).



_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

RE: serial ports under Unix using Freepascal

josepascual (almudi)

Have you taken a look to synaser inside synapse packet software http://synapse.ararat.cz/?

 

Jose Pascual

 

p.d. bonito nombre "papel higienico" ;-)

 

 

 

De: [hidden email] [mailto:[hidden email]] En nombre de [hidden email]
Enviado el: miƩrcoles, 03 de octubre de 2007 21:54
Para: [hidden email]
Asunto: [fpc-pascal] serial ports under Unix using Freepascal

 

Hi!

I'm creating a component that handles serial port in windows/unix. Under Windows I include in uses the unit windows, that open, close, read, write, test if the configuration of serial port is valid (some set of configurations of baudrate, stop bits and parity is invalid in windows)  and if serial port exists.

Under Unix I found the unit Serial, that open, close, read and write. How to test if serial port exist? Unix accept any set of configurations of  the serial port? I see fpopen that return the handle of serial port but I not found anything that describes error codes returned by this function in fpc rtl documentation.

Somebody have tried to do this?

info: I newbie in FPC Unix (FreeBSD).


_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: serial ports under Unix using Freepascal

Luca Olivetti-2
In reply to this post by papelhigienico@gmail.com
En/na [hidden email] ha escrit:

> Hi!
>
> I'm creating a component that handles serial port in windows/unix. Under
> Windows I include in uses the unit windows, that open, close, read,
> write, test if the configuration of serial port is valid (some set of
> configurations of baudrate, stop bits and parity is invalid in windows)  
> and if serial port exists.
>
> Under Unix I found the unit Serial, that open, close, read and write.
> How to test if serial port exist? Unix accept any set of configurations
> of  the serial port? I see fpopen that return the handle of serial port
> but I not found anything that describes error codes returned by this
> function in fpc rtl documentation.
>
> Somebody have tried to do this?

I'd suggest to take a look at synaser:

http://synapse.ararat.cz (it's included in synasnap.zip)

Bye
--
Luca

_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: serial ports under Unix using Freepascal

Marc Santhoff
In reply to this post by papelhigienico@gmail.com
Am Mittwoch, den 03.10.2007, 16:53 -0300 schrieb
[hidden email]:

> Hi!
>
> I'm creating a component that handles serial port in windows/unix.
> Under Windows I include in uses the unit windows, that open, close,
> read, write, test if the configuration of serial port is valid (some
> set of configurations of baudrate, stop bits and parity is invalid in
> windows)  and if serial port exists.
>
> Under Unix I found the unit Serial, that open, close, read and write.
> How to test if serial port exist? Unix accept any set of
> configurations of  the serial port? I see fpopen that return the
> handle of serial port but I not found anything that describes error
> codes returned by this function in fpc rtl documentation.

Normally the libc function "tcsetattr()" is used to set the ports
parameters, as you can see in the source of serial.pp at the end of
"SetSerParams()". That is the place where a check should evaluate the
return code of tcsetattr and return the OS error code if it is -1. This
is a spot where serial.pp should be improved.

FPC exhibits the systems error code by using GetOSError() and
RaiseOSError(), both in sysutils.

If you want to set up the port directly you can use something like this
with the parameters you need:

  var
        tios: termios;

BEGIN
...

        (*
        SerSetParams(fCom, 1200, 7, NoneParity, 2, []);
        *)
       
        r := 0;
        fillchar(tios, sizeof(tios), #0);

        tios.c_ispeed := B1200;
        tios.c_ospeed := B1200;
       
        tios.c_cflag := CREAD or CLOCAL or CS7 or CSTOPB;
       
        tios.c_oflag := 0;
        tios.c_iflag := IGNBRK OR IGNPAR;
        tios.c_lflag := 0;
       
        r := tcsetattr(fCom, TCSANOW, tios);
        if (r = -1) then begin
                writeln(stderr, 'tcsetattr failed!');
                writeln(stderr, 'errno is ', errno);
                fpClose(fCom);
                halt(1);
        end;

That code is from a program I made and is actually running on FreeBSD
4.11.

One other hint: FreeBSD has very good manpages, try "man sio" and "man
tcsetattr" and so on.

Have fun,
Marc


_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: serial ports under Unix using Freepascal

Stephano-2
In reply to this post by papelhigienico@gmail.com
The Linux serial unit was ported to windows.
 
----- Original Message -----
Sent: Wednesday, October 03, 2007 10:53 PM
Subject: [fpc-pascal] serial ports under Unix using Freepascal

Hi!

I'm creating a component that handles serial port in windows/unix. Under Windows I include in uses the unit windows, that open, close, read, write, test if the configuration of serial port is valid (some set of configurations of baudrate, stop bits and parity is invalid in windows)  and if serial port exists.

Under Unix I found the unit Serial, that open, close, read and write. How to test if serial port exist? Unix accept any set of configurations of  the serial port? I see fpopen that return the handle of serial port but I not found anything that describes error codes returned by this function in fpc rtl documentation.

_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: serial ports under Unix using Freepascal

papelhigienico@gmail.com
In reply to this post by josepascual (almudi)
Yes, I'm studing the synaser objects...


Thank's :D

2007/10/4, josepascual <[hidden email]>:

Have you taken a look to synaser inside synapse packet software <a href="http://synapse.ararat.cz/" target="_blank" onclick="return top.js.OpenExtLink(window,event,this)"> http://synapse.ararat.cz/?

 

Jose Pascual

 

p.d. bonito nombre "papel higienico" ;-)

 

 

 

De: [hidden email] [mailto:[hidden email]] En nombre de [hidden email]
Enviado el: miƩrcoles, 03 de octubre de 2007 21:54
Para: [hidden email]
Asunto: [fpc-pascal] serial ports under Unix using Freepascal

 

Hi!

I'm creating a component that handles serial port in windows/unix. Under Windows I include in uses the unit windows, that open, close, read, write, test if the configuration of serial port is valid (some set of configurations of baudrate, stop bits and parity is invalid in windows)  and if serial port exists.

Under Unix I found the unit Serial, that open, close, read and write. How to test if serial port exist? Unix accept any set of configurations of  the serial port? I see fpopen that return the handle of serial port but I not found anything that describes error codes returned by this function in fpc rtl documentation.

Somebody have tried to do this?

info: I newbie in FPC Unix (FreeBSD).


_______________________________________________
fpc-pascal maillist  -  [hidden email]
<a onclick="return top.js.OpenExtLink(window,event,this)" href="http://lists.freepascal.org/mailman/listinfo/fpc-pascal" target="_blank">http://lists.freepascal.org/mailman/listinfo/fpc-pascal


_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/mailman/listinfo/fpc-pascal