Hallo zusammen
ich habe hier vor mir einen RFID-Reader liegen der per USB mit dem PC
(OPENSuse 11.1) verbunden ist, allerdings ist das dann ein virtueller
COM-Port. Zum testen und auslesen der Daten haben ich ein C-Programm
geschrieben. Es sind viele Ausgaben drin um die Konfiguration zu
überprüfen und um erstmal zu sehen ob es auch klappt. Hier mal der
Quelltext:
/*
* File: main.c
* Author: Christian
*
* Created on 15. Juni 2009, 16:27
*/
#include <fcntl.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <sys/ioctl.h>
#include <sys/time.h>
#include <termios.h>
void ausgabe_konfiguration(struct termios config) {
printf("c_iflag: %d\n", config.c_iflag);
printf("c_oflag: %d\n", config.c_oflag);
printf("c_cflag: %d\n", config.c_cflag);
printf("c_lflag: %d\n", config.c_lflag);
printf("c_line: %d\n", config.c_line);
printf("c_ispeed: %d\n", config.c_ispeed);
printf("c_ospeed: %d\n", config.c_ospeed);
printf("c_cc[VMIN]: %d\n\n", config.c_cc[VMIN]);
}
void konfiguration_setzen(struct termios *new_config) {
if(new_config->c_cflag == PARENB) {
new_config->c_cflag = new_config->c_cflag & ~(PARENB);
}
new_config->c_cflag = new_config->c_cflag & ~(CSIZE);
new_config->c_cflag = new_config->c_cflag | CS8;
if(new_config->c_cflag == CRTSCTS) {
new_config->c_cflag = new_config->c_cflag & ~(CRTSCTS);
}
if(new_config->c_cflag == CSTOPB) {
new_config->c_cflag = new_config->c_cflag & ~(CSTOPB);
}
new_config->c_cflag = new_config->c_cflag | CREAD;
};
/*
*
*/
int main(int argc, char** argv) {
int port, bytes;
char buffer[1];
port = open("/dev/ttyUSB0", O_RDWR);
printf("Port: %d\n", port);
if ( port == -1 )
{
// FEHLER: Port konnte nicht geöffnet werden!
printf("FEHLER: Port konnte nicht geöffnet werden\n");
} else {
struct termios old_config; //original Konfiguration des
RFID-Readers
struct termios new_config; //selbst erstellte Konfiguration
// int tcgetattr ( int fd, struct termios *termios_p );
// Konfiguration auslesen
if ( tcgetattr( port, &old_config ) == -1 )
{
// error
printf("Fehler beim lesen der config\n");
} else {
new_config = old_config; //original Konfiguration sichern
printf("Ausgabe alte Konfiguratio\n");
ausgabe_konfiguration(old_config);
printf("Ausgabe kopierte Konfiguratio\n");
ausgabe_konfiguration(new_config);
konfiguration_setzen(&new_config);
cfsetispeed(&new_config, B4800);
cfsetospeed(&new_config, B4800);
printf("Ausgabe neue Konfiguratio\n");
ausgabe_konfiguration(new_config);
if ( tcsetattr( port, TCSANOW, &new_config ) == -1 ) {
printf("Fehler beim lesen der neuen Konfiguration\n");
} else {
bytes = read(port, buffer, sizeof(buffer));
printf("%d", bytes);
int i=0;
for(i; i<bytes; i++) {
printf("%d", buffer[i]);
}
}
}
//original Konfiguration zurÌcksetzen
if(tcsetattr(port, TCSANOW, &old_config) == -1) {
// Fehler beim setzern der original Konfiguration
printf("Fehler beim setzen der original Konfiguration\n");
}
}
close(port);
return (EXIT_SUCCESS);
}
Dieser Quelltext liefert mir die Ausgabe in der angehängten Datei. Mein
Problem ist das das Programm ab der read-Zeile nichts mehr macht das es
auf Eingaben wartet die nicht kommen. Als Einstellungen braucht der
Reader 4800Baud 8N1. Vom System wird der Reader erkannt und Treiber
werden auch geladen. Hat jemand vlt. eine Idee ob und was nicht stimmen
kann?
Ciao
Chris
Bitte melde dich an um einen Beitrag zu schreiben. Anmeldung ist kostenlos und dauert nur eine Minute.
Bestehender Account
Schon ein Account bei Google/GoogleMail? Keine Anmeldung erforderlich!
Mit Google-Account einloggen
Mit Google-Account einloggen
Noch kein Account? Hier anmelden.
