Results 1 to 2 of 2
Hi,
I've a problem with a serial port adapter. This is what i've done:
lsusb
PHP Code:
Bus 001 Device 005 : ID 05d1 : 5001 Brainboxes , Ltd
PHP Code:
sudo modprobe usbserial vendor = 0x05d1 product = ...
Enjoy an ad free experience by logging in. Not a member yet? Register.
- 11-10-2012 #1Just Joined!
- Join Date
- Nov 2012
- Posts
- 5
C/C++ Serial port programming
Hi,
I've a problem with a serial port adapter. This is what i've done:
lsusb
PHP Code:Bus 001 Device 005: ID 05d1:5001 Brainboxes, Ltd
and the adapter is attached to /dev/ttyUSB0 and /dev/ttyUSB1PHP Code:sudo modprobe usbserial vendor=0x05d1 product=0x5001
sudo chmod o+rw /dev/ttyUSB0
Now, this is the code for comunicationPHP Code:[ 1596.261797] usb 1-1.4: new full-speed USB device number 5 using ehci_hcd
[ 1596.368458] usbserial_generic 1-1.4:1.0: generic converter detected
[ 1596.368667] usb 1-1.4: generic converter now attached to ttyUSB0
[ 1596.371816] usbserial_generic 1-1.4:1.1: generic converter detected
[ 1596.371982] usb 1-1.4: generic converter now attached to ttyUSB1
The adapter is for a nexys2 card, whitch read a start byte (AA hex) and send 32byte of data for 100 times.PHP Code:void SerialPort::openPort(char *port){
struct termios options;
this->fd = open("/dev/ttyUSB0", O_RDWR | O_NOCTTY | O_NDELAY);
if(this->fd == -1){
std::cout << "Error open port" << std::endl;
std::cout << "-" << strerror( errno ) << "-" << std::endl;
}
fcntl(this->fd, F_SETFL, FNDELAY);
tcgetattr(this->fd, &options);
cfsetispeed(&options, B115200);
cfsetospeed(&options, B115200);
options.c_cflag &= ~PARENB;
options.c_cflag &= ~CSTOPB;
options.c_cflag &= ~CSIZE;
options.c_cflag |= CS8;
options.c_lflag &= ~(ICANON | ECHO | ECHOE | ISIG);
options.c_cflag |= (CLOCAL | CREAD);
options.c_iflag &= ~(IXON | IXOFF | IXANY);
tcflush(this->fd, TCIFLUSH);
tcsetattr(this->fd, TCSANOW, &options);
}
void SerialPort::t_readData(){
int len = 1;
char byte[10] = {0};
long long count = 0;
if(this->fd == -1) return;
//tcflush(this->fd, TCIFLUSH);
len = write(this->fd, "\xAA", sizeof(char));
if(len < 0){
std::cout << "Error write serial port" << std::endl;
return;
}
std::ofstream tmpf("/tmp/data.txt", ios_base::out | ios_base::binary);
sleep(1);
std::cout << "Reading" << std::endl;
while (len > 0){
len = read(this->fd, byte, sizeof(byte));
if(len > 0)
//std::cout << byte << std::endl;
tmpf.write(byte, sizeof(byte));
count++;
}
std::cout << "End Reading" << std::endl;
tmpf.close();
std::cout << count << std::endl;
close(this->fd);
}
My problem is that the program read a variable number of byte, mostly a sequence of 01 60 (hex)
And this happens even with the card turned off !!
On terminal (with the card turn off) if I do
cat /dev/ttyUSB0
It starts to print binary symbols...
Someone know its happens?
My distro is mint 13 (Maya)
Thanks
- 11-11-2012 #2Just Joined!
- Join Date
- Nov 2012
- Posts
- 5
Hi
Finally i've a solution:
I've to use ftdi_sio module instead usbserial to make work Brainboxes adapter !
Last edited by grumpos; 11-11-2012 at 10:24 AM.



