Tsao,
In function receivePacket try read more then 1 byte at once:
unsigned char temp = read(fd, buffer+i, left_to_read);
i += temp;
left_to_read -= temp;
To avoid hangs add read timeout to this function.
Keep in mind, some date bytes may be lost or corrupted during
transmission, you need error checking mechanism.
---
Best Regards
Alexey Vdovin
-----Original Message-----
From: "tsao.terence" <>
To:
Date: Thu, 04 Mar 2010 08:44:03 -0000
Subject: [ts-7000] TS7260-Reading from /dev/ttyUSB0
> Dear Linux masters,
>
> I am communicating TS7260 with my sensor device using a USB to serial
> FTDI converter. The sensor uses the uart interface, and the TS7260 uses the
> USB interface. The sensor device will send TS7260 a packet of data which
> contains 512 bytes, aka each packet is 512 bytes.
>
>
> I had success reading from ttyUSB0 with 9600 and 38400 baudrate, but when I
> jump to 57600 baud, the program just hangs. I think there might be something
> wrong as I open the USB port, or my receive function has too much software
> overhead. Anyone here had success reading from the ttyUSB0 port?
>
> Here is my open USB function:
> int openUSB()
> {
> int fd = open ("/dev/ttyUSB0", O_RDWR | O_NOCTTY | O_NDELAY | O_FSYNC);
> if (fd==-1)
> {
> fprintf(stderr, "open_port: Unable to open /dev/ttyUSB0 -%s \n",
> strerror(errno));
> }
>
> struct termios options;
>
> /*Configure port reading*/
> fcntl (fd, F_SETFL, FNDELAY);
> /*Get the current options for the port*/
> tcgetattr(fd, &options);
>
> /*Set baudrate to 500000Mb*/
> cfsetispeed(&options, B57600);
> cfsetospeed(&options, B57600);
>
> /*Mark the character size to 8 bits, no parity*/
> options.c_cflag |= (CLOCAL | CREAD);
> options.c_lflag &= ~(ICANON | ECHO | ECHOE | ISIG);
> options.c_oflag &= ~OPOST;
> options.c_iflag &= ~(IXON | ICRNL);
> options.c_cc[VMIN] = 0;
> options.c_cc[VTIME] = 0;
> tcsetattr(fd, TCSANOW, &options);
> return fd;
> }
>
> Here is my read function:.
> unsigned char receivePacket(int fd, unsigned char *buffer)
> {
>
> unsigned int i=0;
> unsigned int left_to_read=520;
> unsigned char byte;
> while(left_to_read>0)
> {
> nsigned char temp = read(fd, &byte, 1);
> if(temp>0)
> {
> left_to_read--;
> buffer[i]=byte;
> printf("%.2x",byte);
> i++;
> }
> }
> return 0;
> }
>
------------------------------------
Yahoo! Groups Links
<*> To visit your group on the web, go to:
http://groups.yahoo.com/group/ts-7000/
<*> Your email settings:
Individual Email | Traditional
<*> To change settings online go to:
http://groups.yahoo.com/group/ts-7000/join
(Yahoo! ID required)
<*> To change settings via email:
<*> To unsubscribe from this group, send an email to:
<*> Your use of Yahoo! Groups is subject to:
http://docs.yahoo.com/info/terms/
|