# debugging a serial communication tool

hey guys, i need some help debugging this 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;
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

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

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.

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)