Pages: [1]   Go Down
Author Topic: debugging a serial communication tool  (Read 874 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 2
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

hey guys, i need some help debugging this code:
Code:
int open_portandprint(char* load){
int fd; /* File descriptor for the port */
fd = open("/dev/ttyACM0", O_RDWR | O_NDELAY);
    fcntl(fd, F_SETFL, 0);
struct termios options,oldtios;
if (tcgetattr(fd, &oldtios) != 0) return(-1);
cfsetispeed(&options, B9600);            /* setze 9600 bps */
cfsetospeed(&options, B9600);
options.c_cflag &= ~PARENB;               /*  kein Paritybit */
options.c_cflag &= ~CSTOPB;               /* 1 Stopbit */
  options.c_cflag &= ~CSIZE;                /* 8 Datenbits */
  options.c_cflag |= CS8;
options.c_oflag &= ~OPOST;
tcsetattr(fd, TCSANOW, &options);

int n = 0;
int m = strlen(load);
n =  write(fd, load, m);
return (fd);
    }
it should initialize the virtual com port on my computer and write some bytes of code. but in only works, while i have telnet up an running. so i think some of my flags are wrong.
can somebody see what my problem is?
thank so far,
erik
Logged

Global Moderator
Netherlands
Offline Offline
Shannon Member
*****
Karma: 170
Posts: 12462
In theory there is no difference between theory and practice, however in practice there are many...
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

This does not look like arduino code ...

what I see is that the fd is nowhere closed

n =  write(fd, load, m);
what is n after the statement, it should be equal to m ...
Logged

Rob Tillaart

Nederlandse sectie - http://arduino.cc/forum/index.php/board,77.0.html -
(Please do not PM for private consultancy)

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

it is code that runs on my netbook.
ive done some experimenting and it seems, that when i run the code with the arduino connectet, the arduino reboots. on the arduino runs the SerialDisplay example, wich puts everything from the serial input off the arduino to a lcd (and this works, ive testet it with the serial monitor).
this code works, as long as i have the serial monitor open.
Logged

Global Moderator
Netherlands
Offline Offline
Shannon Member
*****
Karma: 170
Posts: 12462
In theory there is no difference between theory and practice, however in practice there are many...
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

opening a serial port does set some HW handshake lines high/low.
I don't recall the details but they are discussed more on this forum -> search in the upper right for 'serial open reset Arduino' or so)
Logged

Rob Tillaart

Nederlandse sectie - http://arduino.cc/forum/index.php/board,77.0.html -
(Please do not PM for private consultancy)

Pages: [1]   Go Up
Jump to: