Sign in Join

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

Mailing lists / fpc-pascal / 2007-10

serial ports under Unix using Freepascal

6 messages · 5 people · –

Reply by email Subscribe to this list Your subscription

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

Unknown author

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).

josepascual
to Unknown author

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

Jose Pascual

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

De:
En nombre de

Enviado el: miércoles, 03 de octubre de 2007 21:54 Para:
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).

Luca Olivetti
to Unknown author: Hi! I'm creating a component that handles serial port in windows/unix. Under Windows I…

En/na ha escrit:

Show quoted text 15 lines
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
Marc Santhoff
to Unknown author: Hi! I'm creating a component that handles serial port in windows/unix. Under Windows I…

Am Mittwoch, den 03.10.2007, 16:53 -0300 schrieb

Show quoted text 13 lines
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

Stephano
to Unknown author: Hi! I'm creating a component that handles serial port in windows/unix. Under Windows I…

The Linux serial unit was ported to windows.

Refer to

Earlier message 12 lines
----- Original Message ----- From: To: 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.
Unknown author
to josepascual: Have you taken a look to synaser inside synapse packet software http://synapse.ararat.cz/?

Yes, I'm studing the synaser objects...

Thank's :D

2007/10/4, josepascual :

Show quoted text 50 lines
Have you taken a look to synaser inside synapse packet software http://synapse.ararat.cz/? Jose Pascual p.d. bonito nombre "papel higienico" ;-) *De:* [mailto: *En nombre de * *Enviado el:* miércoles, 03 de octubre de 2007 21:54 *Para:* *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 - http://lists.freepascal.org/mailman/listinfo/fpc-pascal