Hallo!
mit "/dev/ttyS0" kann der Code die Schnittstelle öffnen!
Aber mit "/dev/ttyUSB0" friert er immer bei usb_serial.open() ein.
Wenn ich den USB Stecker raus ziehe, gehts weiter und es gibt den Fehler "error opening device". -> Also kriegt schonmal zumindest was mit von dem USB-SERIAL konverter.
Hab jetzt alles durch was ich finden konnte und mir einfällt: sudo, neu starten usw.
Ich habe das Gefühl, es liegt an irgendwelchen Handshakes jedoch finde ich keinen Ansatz, da etwas zu verändern.
Code:/* * main.cc * * Created on: 01.04.2011 * Author: thomas */ #include <iostream> #include <SerialStream.h> #include <cstdlib> #include <string> using namespace LibSerial ; using namespace std; int main () { string port( "/dev/ttyUSB0" ); // string port( "/dev/ttyS0" ); SerialStream usb_serial; cout << "Open Port " << port << endl; usb_serial.Open(port) ; if (!usb_serial) { cout << "Error oppening Port " << port << endl; return 1; } usb_serial.SetBaudRate( SerialStreamBuf::BAUD_19200 ) ; if ( ! usb_serial.good() ) { cerr << "Error: Could not set the baud rate." << endl ; exit(1) ; } usb_serial.SetCharSize( SerialStreamBuf::CHAR_SIZE_8 ) ; if ( ! usb_serial.good() ) { cerr << "Error: Could not set the character size." << endl ; exit(1) ; } usb_serial.SetParity( SerialStreamBuf::PARITY_ODD ) ; if ( ! usb_serial.good() ) { cerr << "Error: Could not disable the parity." << endl ; exit(1) ; } usb_serial.SetNumOfStopBits( 1 ) ; if ( ! usb_serial.good() ) { cerr << "Error: Could not set the number of stop bits." << endl ; exit(1) ; } usb_serial.SetFlowControl( SerialStreamBuf::FLOW_CONTROL_NONE ) ; if ( ! usb_serial.good() ) { cerr << "Error: Could not use hardware flow control." << endl ; exit(1) ; } usb_serial.Close() ; cout << "Port " << port << " closed!"<< endl; return 0; }







Zitieren


Lesezeichen