"Christmas - the time to fix the computers of your loved ones" « Lord Wyrm

Serial port unter Linux

linux99 15.03.2003 - 11:13 1057 1
Posts

linux99

Bloody Newbie
Registered: Aug 2002
Location: Villach
Posts: 1
Ich hab da ein kleines Problem:

Weis vielleicht jemand, wie man unter Linux
den TxD Pin der seriellen Schnittstelle setzt?

Programmiersprache: c/c++

Die anderen beiden Pins (RTS, DTR) hab ich mit der
Funktion ioctl() gesetzt.

Eat my shorts

Little Overclocker
Avatar
Registered: Dec 2002
Location: Österreich
Posts: 56
vielleicht hilft das dir weiter
[QUOTE]
/*************************************************************************
* OpenPort () - Attempts to open the serial port, and set the parameters
* on the port. NMEA states port settings should be 8N1, 4800 BPS
* If the port is open a lock file is created in /var/lock.
* **NOTE** Some of the code in this function was taken from
* Thomas Schank's gpspoint GPL software.
*************************************************************************/
int OpenPort (char *port)
{int err,
len = 0;
char Tmp[MAXLEN],
InChar,
*TmpPtr;
struct termios options;
struct stat devstat;

len = strlen (port);
TmpPtr = strrchr (port, '/');
TmpPtr++;
strcpy (lockfile, "/var/lock/");
strcat (lockfile, TmpPtr);
strcat (lockfile, ".lock");

if (stat(lockfile, &devstat) != -1) { //Lock file exists!!!
lockfile[0] = '\0';
return -1;
} /*End of if*/

// Serial = open(port, O_RDWR | O_NOCTTY | O_NDELAY);
Serial = open(port, O_RDWR | O_NOCTTY);
if (Serial < 1) {
return -1;
} /*End of if*/
else {
fcntl(Serial,F_SETFL,0);
tcgetattr(Serial,&old_options);
memset (&options, 0,sizeof(options));
options.c_cflag &= ~PARENB; // no parity
options.c_cflag &= ~CSTOPB; // one stopbit
// options.c_cflag |= CRTSCTS; // hadware flow on

#if defined (CRTSCTS)
options.c_cflag &= ~CRTSCTS; // No hardware flow control.
#endif
options.c_cflag &= CSIZE;
options.c_cflag |= CS8; // 8N1
options.c_cflag |= (CLOCAL | CREAD); // enable Localmode, receiver
options.c_cc[VMIN] = 0; // set min read characters if 0
// VTIME takes over
options.c_cc[VTIME] = V_TIME; // wait V_TIME ms for character

err = cfsetospeed(&options, B4800);
if (err < 0) {
printf ("Could not set output speed! Error = %d\n", err);
close (Serial);
return -1;
} /*End of if*/

err = cfsetispeed(&options, B4800);
if (err < 0) {
printf ("Could not set input speed! Error = %d\n", err);
close (Serial);
return -1;
} /*End of if*/

if (tcsetattr(Serial,TCSANOW, &options) < 0) {
printf ("Failed to set Serial port options!\n");
close (Serial);
return -1;
} /*End of if*/
} /*End of else*/

Lock = open (lockfile, O_WRONLY | O_CREAT);
sprintf (Tmp, "%d %s %d\n", getpid(), PROJNAME, geteuid());
write (Lock, Tmp, strlen (Tmp));
close (Lock);
InChar = ' ';

tcflush (Serial, TCIOFLUSH);

return 0;
} /*End of OpenPort ()*/
#endif //ifdef LINUX

[/QUOTE]

das is von gpsutil http://www.cs.uakron.edu/~hennings/gpsutil/ in der serial.c steht eigentlich alles drinnen um den seriell port anzusteuern, vieleicht hilfts was.
Kontakt | Unser Forum | Über overclockers.at | Impressum | Datenschutz