Serial Programming trouble
- From: dieter.verslype@xxxxxxxxx
- Date: 12 Sep 2006 09:52:04 -0700
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
.
- Follow-Ups:
- Re: Serial Programming trouble
- From: Patrick
- Re: Serial Programming trouble
- Prev by Date: Re: Permission denied, even for root
- Next by Date: Re: howto convert rm to mp3?
- Previous by thread: howto convert rm to mp3?
- Next by thread: Re: Serial Programming trouble
- Index(es):