Reading from the /dev/ttyUSB1
hi guys,
i working on school project right , working arduino board mega.
i set arduino board sense when there connection closed on board. when connection closed, arduino board executes command "serial.println(sensorvalue, dec);" , prints 1 serial monitor.
from understand, when command executed arduino board writing virtual serial port. "1" shows on serial monitor, when try read in c code receive 0.
my code posted below. insight how read output arduino board?
this c code:
i working on school project right , working arduino board mega.
i set arduino board sense when there connection closed on board. when connection closed, arduino board executes command "serial.println(sensorvalue, dec);" , prints 1 serial monitor.
from understand, when command executed arduino board writing virtual serial port. "1" shows on serial monitor, when try read in c code receive 0.
my code posted below. insight how read output arduino board?
this c code:
code: [select]
#include <stdio.h> /* standard input/output definitions */
#include <string.h> /* string function definitions */
#include <unistd.h> /* unix standard function definitions */
#include <fcntl.h> /* file control definitions */
#include <errno.h> /* error number definitions */
#include <termios.h> /* posix terminal control definitions */
int main(void)
{
int fd; /* file descriptor port */
int get;
get = 5;
fd = open("/dev/ttyusb1", o_rdwr | o_noctty | o_ndelay);
if (fd == -1)
{
//could not open port.
perror("open_port: unable open /dev/ttys0 - ");
}
else
{
struct termios options;
//get current options port...
tcgetattr(fd, &options);
//set baud rates 19200...
cfsetispeed(&options, b9600);
cfsetospeed(&options, b9600);
//enable receiver , set local mode...
options.c_cflag |= (clocal | cread);
//set new options port...
tcsetattr(fd, tcsanow, &options);
while(1){
delay(500);
get = fcntl(fd, f_setfl, 0);
//get = fcntl(fd, f_setfl, fndelay);
printf("read: %d\n",get);
}
}
return (fd);
}
try usb0
Arduino Forum > Forum 2005-2010 (read only) > Software > Syntax & Programs > Reading from the /dev/ttyUSB1
arduino
Comments
Post a Comment