serial port

How can I use the serial port?

Yet I used open():
fd_serout = open ("/dev/ser1", O_RDWR);

I 've also set the IO speed for the serial port.
But yet it doesn’t work.

Do I have to activate the serial device?
How can it be done?

Tobi.

Tobias Moeglich <Tobias.Moeglich@web.de> wrote:

How can I use the serial port?

Yet I used open():
fd_serout = open ("/dev/ser1", O_RDWR);

I 've also set the IO speed for the serial port.
But yet it doesn’t work.

Do I have to activate the serial device?
How can it be done?

Tobi.

You can set the speed, etc. of the serial port with the stty command.
stty 19200 < /dev/ser1
You can also set the bits/byte and parity, etc with stty.

You don’t ned to “activate” the serial port, but you may alsio want to
look at soem of the flow control options. Again, use stty.

I 've also set the IO speed for the serial port.
But yet it doesn’t work.

Do I have to activate the serial device?
How can it be done?

stty

or

With C, you may use the POSIX terminal control definitions.

For example :

#include <termios.h> /* POSIX terminal control definitions
/
/
**************************************************************************
/
//
// ConfigureSerialPort - Configure serial port with specified baud rate
// Params : File descriptor, baud rate (9600, 4800…)
// Returns : If an error occur, the function returns -1
//
/
**************************************************************************
*/
int ConfigureSerialPort (int iFileDescriptor, int iBaudRate)
{
struct termios tConf;
long lVitesse;
int iReturn;

/* Initialise */
iReturn = 0;

/* Get the current options for the port /
if ((iReturn = tcgetattr(iFileDescriptor, &tConf)) != -1)
{
/
Set the baud rates to specified parameter, default=9600 */
switch (iBaudRate)
{
case 0 : {lVitesse = B0; break;}
case 50 : {lVitesse = B50; break;}
case 75 : {lVitesse = B75; break;}
case 110 : {lVitesse = B110; break;}
case 134 : {lVitesse = B134; break;}
case 150 : {lVitesse = B150; break;}
case 200 : {lVitesse = B200; break;}
case 300 : {lVitesse = B300; break;}
case 600 : {lVitesse = B600; break;}
case 1200 : {lVitesse = B1200; break;}
case 2400 : {lVitesse = B2400; break;}
case 4800 : {lVitesse = B4800; break;}
case 9600 : {lVitesse = B9600; break;}
case 19200 : {lVitesse = B19200; break;}
case 38400 : {lVitesse = B38400; break;}
default : {lVitesse = B9600; break;}
}

tConf.c_ispeed = lVitesse;
tConf.c_ospeed = lVitesse;

/* Enable the receiver and set local mode */
tConf.c_cflag |= (CLOCAL | CREAD);

/* Set 8N1 */
tConf.c_cflag &= ~PARENB;
tConf.c_cflag &= ~CSTOPB;
tConf.c_cflag &= ~CSIZE;
tConf.c_cflag |= CS8;

/* Disable hardware flow control - Not supported /
/
tConf.c_cflag &= ~CNEW_RTSCTS; /
/
Select raw input/output */
tConf.c_lflag &= ~(ICANON | ECHO | ISIG);
tConf.c_oflag &= ~OPOST;

/* Set the new options for the port */
if ((iReturn = tcsetattr(iFileDescriptor, TCSANOW, &tConf)) != -1) {}

}
/* All done */
return iReturn;
}


Romain PETIT
(mailto:rompetit_chez_ifrance.com)

Thank you for your help.
There is another problem with the serial device:
It is possible to read from the serial port. But it is not possible for
me to write properly.
I’m uesing the “write” function and it returns the amount of written
bytes (as expected). But I can’t see them at the receiving PC. Sometimes
only two bytes arive sometimes 8 bytes. To configure the serial device I
used the code below. Do I have to set some other flags?
I don’t want to use the handshake signals (RTS, etc). Do I have to
disable them? Could this be a problem?
Do I have to clear the output buffer with tcflush()? I already do this.

Do you hav an advise?

Tobi.



Romain PETIT wrote:

I 've also set the IO speed for the serial port.
But yet it doesn’t work.

Do I have to activate the serial device?
How can it be done?


stty

or

With C, you may use the POSIX terminal control definitions.

For example :

#include <termios.h> /* POSIX terminal control definitions
/
/
**************************************************************************
/
//
// ConfigureSerialPort - Configure serial port with specified baud rate
// Params : File descriptor, baud rate (9600, 4800…)
// Returns : If an error occur, the function returns -1
//
/
**************************************************************************
*/
int ConfigureSerialPort (int iFileDescriptor, int iBaudRate)
{
struct termios tConf;
long lVitesse;
int iReturn;

/* Initialise */
iReturn = 0;

/* Get the current options for the port /
if ((iReturn = tcgetattr(iFileDescriptor, &tConf)) != -1)
{
/
Set the baud rates to specified parameter, default=9600 */
switch (iBaudRate)
{
case 0 : {lVitesse = B0; break;}
case 50 : {lVitesse = B50; break;}
case 75 : {lVitesse = B75; break;}
case 110 : {lVitesse = B110; break;}
case 134 : {lVitesse = B134; break;}
case 150 : {lVitesse = B150; break;}
case 200 : {lVitesse = B200; break;}
case 300 : {lVitesse = B300; break;}
case 600 : {lVitesse = B600; break;}
case 1200 : {lVitesse = B1200; break;}
case 2400 : {lVitesse = B2400; break;}
case 4800 : {lVitesse = B4800; break;}
case 9600 : {lVitesse = B9600; break;}
case 19200 : {lVitesse = B19200; break;}
case 38400 : {lVitesse = B38400; break;}
default : {lVitesse = B9600; break;}
}

tConf.c_ispeed = lVitesse;
tConf.c_ospeed = lVitesse;

/* Enable the receiver and set local mode */
tConf.c_cflag |= (CLOCAL | CREAD);

/* Set 8N1 */
tConf.c_cflag &= ~PARENB;
tConf.c_cflag &= ~CSTOPB;
tConf.c_cflag &= ~CSIZE;
tConf.c_cflag |= CS8;

/* Disable hardware flow control - Not supported /
/
tConf.c_cflag &= ~CNEW_RTSCTS; /
/
Select raw input/output */
tConf.c_lflag &= ~(ICANON | ECHO | ISIG);
tConf.c_oflag &= ~OPOST;

/* Set the new options for the port */
if ((iReturn = tcsetattr(iFileDescriptor, TCSANOW, &tConf)) != -1) {}

}
/* All done */
return iReturn;
}


Romain PETIT
(mailto:rompetit_chez_ifrance.com)

Tobias Moeglich <Tobias.Moeglich@web.de> wrote:
TM > Thank you for your help.
TM > There is another problem with the serial device:
TM > It is possible to read from the serial port. But it is not possible for
TM > me to write properly.
TM > I’m uesing the “write” function and it returns the amount of written
TM > bytes (as expected). But I can’t see them at the receiving PC. Sometimes
TM > only two bytes arive sometimes 8 bytes. To configure the serial device I
TM > used the code below. Do I have to set some other flags?
TM > I don’t want to use the handshake signals (RTS, etc). Do I have to
TM > disable them? Could this be a problem?
TM > Do I have to clear the output buffer with tcflush()? I already do this.

TM > Do you hav an advise?

TM > Tobi.

Does stty show that the device is paged?

Note: paging involves stopping output becuase of HW or SW flow control?
If so, correct the flow control issue.

The device is not paged.
But I found a function called “tcdrain”.
Has it to do with the serial communication?

Tobi.


“Bill Caroselli” <qtps@earthlink.net> schrieb im Newsbeitrag
news:b8bsd0$gbp$1@inn.qnx.com

Does stty show that the device is paged?

Note: paging involves stopping output becuase of HW or SW flow control?
If so, correct the flow control issue.

Tobias Moeglich <> Tobias.Moeglich@web.de> > wrote:
TM > Thank you for your help.
TM > There is another problem with the serial device:
TM > It is possible to read from the serial port. But it is not possible
for
TM > me to write properly.
TM > I’m uesing the “write” function and it returns the amount of written
TM > bytes (as expected). But I can’t see them at the receiving PC.
Sometimes
TM > only two bytes arive sometimes 8 bytes. To configure the serial
device I
TM > used the code below. Do I have to set some other flags?
TM > I don’t want to use the handshake signals (RTS, etc). Do I have to
TM > disable them? Could this be a problem?
TM > Do I have to clear the output buffer with tcflush()? I already do
this.

TM > Do you have an advise?

TM > Tobi.

“Tobias Moeglich” <Tobias.Moeglich@tu-bs.de> wrote in message
news:b8oir0$r35$1@inn.qnx.com

The device is not paged.
But I found a function called “tcdrain”.
Has it to do with the serial communication?
tcdrain waits for the data to be transmitted. If a signal is received then

it returns with -1. I used it with a timer that signals the process when
timeout occurs and the data has not been transmitted.
Padraig

Tobi.


“Bill Caroselli” <> qtps@earthlink.net> > schrieb im Newsbeitrag
news:b8bsd0$gbp$> 1@inn.qnx.com> …
Does stty show that the device is paged?

Note: paging involves stopping output becuase of HW or SW flow control?
If so, correct the flow control issue.

Tobias Moeglich <> Tobias.Moeglich@web.de> > wrote:
TM > Thank you for your help.
TM > There is another problem with the serial device:
TM > It is possible to read from the serial port. But it is not possible
for
TM > me to write properly.
TM > I’m uesing the “write” function and it returns the amount of
written
TM > bytes (as expected). But I can’t see them at the receiving PC.
Sometimes
TM > only two bytes arive sometimes 8 bytes. To configure the serial
device I
TM > used the code below. Do I have to set some other flags?
TM > I don’t want to use the handshake signals (RTS, etc). Do I have to
TM > disable them? Could this be a problem?
TM > Do I have to clear the output buffer with tcflush()? I already do
this.

TM > Do you have an advise?

TM > Tobi.

\