Go Down

Topic: debugging a serial communication tool (Read 990 times) previous topic - next topic

hey guys, i need some help debugging this code:
Code: [Select]
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

robtillaart

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 ...
Rob Tillaart

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

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.

robtillaart

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)
Rob Tillaart

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

Go Up
 


Please enter a valid email to subscribe

Confirm your email address

We need to confirm your email address.
To complete the subscription, please click the link in the email we just sent you.

Thank you for subscribing!

Arduino
via Egeo 16
Torino, 10131
Italy