Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

USB serial and Ubuntu

Status
Not open for further replies.

Cheetos

Member level 3
Joined
May 26, 2011
Messages
57
Helped
1
Reputation
2
Reaction score
1
Trophy points
1,288
Activity points
1,700
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::pARITY_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 :(
 

Check the permissions of the /dev/ttyUSB0. Usually the port has owner root and group owner "dialout" for example. You must be member of the group. I'm not pretty sure if in Ubuntu the group owner is "dialout" (in Fedora) but you can check this by your self.
 

Just to elaborate on that, the file you need to edit is /etc/group. In it you'll find a line similar to:

Code:
dialout::20:root

Simply add a comma and then your username to the end of that line and next time you login you'll be a member of that group.
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top