Serial Programming trouble



Hello,

I'm writing an application that reads data from a 'glucometer'
(onetouch ultra from lifescan).

I connected the serial cable included with the device to a USB port
with a serial2usb cable, resulting in /dev/ttyUSB0.

In minicom, i use these settings:
# Machine-generated file - use "minicom -s" to change parameters.
pu port /dev/ttyUSB0
pu baudrate 9600
pu bits 8
pu parity N
pu stopbits 1

Also i set it with no flow control. When I type 'DM' without any CR or
LF the PC-connection status shows on the device, meaning it's ready to
communicate.

My problem is, i can't even reconstruct this in C, so i definitely
cannot read data.

If anyone knows issues on the topic, any help is welcome since i'm
pretty new at the subject.

Here's my app:

#include <unistd.h>
#include <string.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <termios.h>
#include <stdio.h>
#include <stdlib.h>



int main(int argc, char **argv) {
int fd;
fd = open("/dev/ttyUSB0", O_RDWR | O_NOCTTY);
if (fd == -1){perror("Error opening port...");}
else
fcntl(fd, F_SETFL, FNDELAY); /* Configure port reading */

struct termios options;
tcgetattr(fd, &options); /* Get the current options for the port
*/
cfsetispeed(&options, B9600); /* Set the baud rates to 9600 */
cfsetospeed(&options, B9600);
options.c_cflag |= (CLOCAL | CREAD); /* Enable the receiver and set
local mode */
options.c_cflag &= ~PARENB; /* Mask character size to 8 bits, no
parity */
options.c_cflag &= ~CSTOPB;
options.c_cflag &= ~CSIZE;
options.c_cflag |= CS8;
options.c_cflag &= ~CRTSCTS; /* Disable hardware flow control */
options.c_lflag &= ~(ICANON | ECHO | ISIG); /* RAW mode */
tcsetattr(fd, TCSANOW, &options); /* Set the new options for the
port */

int n = write(fd, "DM", 2);
if (n < 0)
fputs("write failed!\n", stderr);
sleep(3);
close(fd);
}

thanks for your help,

Dieter

.