Archiv verlassen und diese Seite im Standarddesign anzeigen : Serielle Ports scannen mit C++
Welche Möglichkeiten gibt es um festzustellen, welche seriellen Ports tatsächlich existieren.
Ein open auf sämtliche Device-Dateien /dev/ttyS0.../dev/ttyS23 ist ebenso erfolgreich wie ein (write-)select auf zugehörige Dateideskriptoren. Physisch sind jedoch nur ttyS0 und ttyS1 serielle Schnittstellen. Wie kann ich diese mit Mitteln von C/C++ identifizieren?
Vielen Dank
thommy
hallo,
ein schneller hack
sollte helfen
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <linux/serial.h>
#include <unistd.h>
#include <sys/ioctl.h>
#include <errno.h>
#include <string.h>
int main()
{
int a,error;
struct serial_struct serial_info;
a=open("/dev/ttyS0",O_RDWR);
if(a==-1)
perror(NULL);
error=ioctl(a,TIOCGSERIAL,&serial_info);
if (error==-1)
perror(NULL);
if (serial_info.type!=0)
printf("Type ist %i\n" ,serial_info.type);
else
printf("Kein bekanter Typ\n");
return 1;
}
Typen aus serial.h
/*
* These are the supported serial types.
*/
#define PORT_UNKNOWN 0
#define PORT_8250 1
#define PORT_16450 2
#define PORT_16550 3
#define PORT_16550A 4
#define PORT_CIRRUS 5 /* usurped by cyclades.c */
#define PORT_16650 6
#define PORT_16650V2 7
#define PORT_16750 8
#define PORT_STARTECH 9 /* usurped by cyclades.c */
#define PORT_16C950 10 /* Oxford Semiconductor */
#define PORT_16654 11
#define PORT_16850 12
#define PORT_RSA 13 /* RSA-DV II/S card */
#define PORT_MAX 13
tschüss
Klasse!
Herzlichen Dank;-) Auf ioctl wäre ich nicht gekommen.
Gruß thommy
Powered by vBulletin® Version 4.2.5 Copyright ©2025 Adduco Digital e.K. und vBulletin Solutions, Inc. Alle Rechte vorbehalten.