Cheetos
Member level 3
greetings, i don't know how to fix this error in my code "Could not open serial port /dev/ttyUSB0". i've checked the dmesg
and got this one:
[40981.672423] ch341 2-1:1.0: device disconnected
[40999.408876] usb 2-1: new full speed USB device using uhci_hcd and address 13
[40999.678973] ch341 2-1:1.0: ch341-uart converter detected
[40999.829371] usb 2-1: ch341-uart converter now attached to ttyUSB0
this is my code:
#include <iostream>
#include <fstream>
#include <SerialStream.h>
#include <cstdlib>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
using namespace LibSerial;
main(){
SerialStream serialPort;
serialPort.Open("/dev/ttyUSB0");
serialPort.SetBaudRate( SerialStreamBuf::BAUD_9600) ;
serialPort.SetCharSize( SerialStreamBuf::CHAR_SIZE_8 ) ;
serialPort.SetNumOfStopBits(1) ;
serialPort.SetParity( SerialStreamBuf:
ARITY_NONE ) ;
serialPort.SetFlowControl( SerialStreamBuf::FLOW_CONTROL_NONE ) ;
if ( ! serialPort.good() )
{
std::cerr << "Error: Could not open serial port "
<< "/dev/ttyUSB0"
<< std::endl ;
exit(1) ;
}
serialPort<<'1';
serialPort.Close();
return (0);
}
Please help me. This is the last step for me to finish my project
and got this one:
[40981.672423] ch341 2-1:1.0: device disconnected
[40999.408876] usb 2-1: new full speed USB device using uhci_hcd and address 13
[40999.678973] ch341 2-1:1.0: ch341-uart converter detected
[40999.829371] usb 2-1: ch341-uart converter now attached to ttyUSB0
this is my code:
#include <iostream>
#include <fstream>
#include <SerialStream.h>
#include <cstdlib>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
using namespace LibSerial;
main(){
SerialStream serialPort;
serialPort.Open("/dev/ttyUSB0");
serialPort.SetBaudRate( SerialStreamBuf::BAUD_9600) ;
serialPort.SetCharSize( SerialStreamBuf::CHAR_SIZE_8 ) ;
serialPort.SetNumOfStopBits(1) ;
serialPort.SetParity( SerialStreamBuf:
serialPort.SetFlowControl( SerialStreamBuf::FLOW_CONTROL_NONE ) ;
if ( ! serialPort.good() )
{
std::cerr << "Error: Could not open serial port "
<< "/dev/ttyUSB0"
<< std::endl ;
exit(1) ;
}
serialPort<<'1';
serialPort.Close();
return (0);
}
Please help me. This is the last step for me to finish my project