Pages: [1]   Go Down
Author Topic: help for serial/usb PC-ARduino  (Read 315 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 25
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hello, could someone tell me why I am obliged to start a terminal emulation program (eg minicom)
  to communicate with my arduino board (using a C program and a serial connection / usb)

Thank you for your help
Logged

Seattle, WA USA
Offline Offline
Brattain Member
*****
Karma: 614
Posts: 49372
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
Hello, could someone tell me why I am obliged to start a terminal emulation program (eg minicom)
  to communicate with my arduino board (using a C program and a serial connection / usb)
Because you are not opening the serial port correctly in your C program. Fix line 28.
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 25
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Thanks for your response
Quote
Fix line 28.
i'am not understand what you mean.

I open the port in this way
Code:
uart0_filestream = open("/dev/ttyACM0",O_RDWR | O_NOCTTY);
if (uart0_filestream == -1)
{
//ERROR - CAN'T OPEN SERIAL PORT
printf("Error - Unable to open UART. Ensure it is not in use by another application\n");
}
struct termios options;
tcgetattr(uart0_filestream, &options);
cfsetispeed(&options, B9600); //<Set baud rate
cfsetospeed(&options, B9600); //<Set baud rate
options.c_cflag = B9600 | CS8 | CLOCAL | CREAD; //<Set baud rate
options.c_iflag = IGNPAR | ICRNL;
options.c_oflag = 0;
tcflush(uart0_filestream, TCIFLUSH);
tcsetattr(uart0_filestream, TCSANOW, &options);
fcntl(uart0_filestream, F_SETFL, 0);

and i read
Code:
for ( count=0; count<5;){
rx_length = -1;
char recevchar;
while (rx_length < 1){
errno = 0;
rx_length = read(uart0_filestream,&recevchar,1);
printf("rx_length : %d\n", rx_length);
printf("errno : %d\n", errno);
printf("caractere : %c\n",recevchar);
if (errno == EAGAIN){
//printf("%d\n", errno);
rx_length = -1;
sleep(1);
  }
}
rx_buffer[count] = recevchar;
++count
}
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 25
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

when the emulator is open my program ( C programme) returns the byte read
Logged

Seattle, WA USA
Offline Offline
Brattain Member
*****
Karma: 614
Posts: 49372
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
i'am not understand what you mean.
Sure you did. You posted (some of) your code.
Logged

Pages: [1]   Go Up
Jump to: