J'ai une montre Garmin 310XT. J'ai également un embout qu'on branche au port USB ANT+.
Lorsque je le branche, j'ai /dev/ttyUSB0 qui apparait.
J'essaie donc de lire ce qu'il y a dessus :
Code : Tout sélectionner
#include <stdio.h>
#include <stdlib.h>
#include <termios.h>
#include <sys/fcntl.h>
#include <unistd.h>
#include <errno.h>
#include <string.h>
int readMessage(int file, unsigned int nCountMax)
{
int i,j;
ssize_t bytes_read;
if(file != -1)
{
i = 0;
char data[1] = "";
while(i<nCountMax)
{
bytes_read = read(file, data, sizeof(data));
if(bytes_read > 0)
{
printf("%c", data[0]);
i += bytes_read;
}
}
return 1;
}
else
return 0;
};
void read_Serial_Port(const char* DEVICE_PORT)
{
int file;
struct termios options;
unsigned int nCountMax = 60;
int b;
file = open(DEVICE_PORT, O_RDONLY | O_NOCTTY | O_NDELAY);
if(file == -1)
perror("Unable to open the serial port\n");
printf("Serial port open successful !\n");
tcgetattr(file, &options);
cfsetispeed(&options, B9600);
cfsetospeed(&options, B9600);
options.c_cflag |= (CLOCAL | CREAD);
options.c_cflag |= PARENB;
options.c_cflag |= PARODD;
options.c_cflag &= ~CSIZE;
options.c_cflag |= CS8;
printf("Reading serial port ...\n\n");
b = readMessage(file, nCountMax);
if(b == 0)
printf("Error while reading serial port\n");
else
printf("\nSerial port read successful\n");
close(file);
printf("Serial port closed\n");
};
int main()
{
const char port[] = "/dev/ttyUSB0";
read_Serial_Port(port);
return 0;
}
Comment puis-je exporter mes parcours .gpx sur mon PC à partir de ma montre ?