- Joined
- Oct 20, 2009
- Messages
- 2
- Reaction score
- 0
- Points
- 1
- Location
- France
- Your Mac's Specs
- iMac 17
Hello all,
to control a solar installation, I've made an electronic board based on a PIC which outputs data (temperatures, ...) on a RS232 serial link @9600bps. To log data, I've bought an USB-serial convertor that I connected to my iMac. I've tested this link with a software like "coolTerm", everything is fine !
Now, to store all this data and to provide it on a web site, I want to write a C program on the MAC to read data from USB-serial link and generate some kinds of HTML pages.
My first C lines on MAC (my frist try after several years under Linux) start hardly : this easy program crashes on open function (it seems definitely locked...) ??? I've tried to add O_NONBLOCK attribute to open function, then it returns a correct fd, but read function returns "resource temporarily unavailable".
Does someone has an idea about this problem ?
Thanks for help !
to control a solar installation, I've made an electronic board based on a PIC which outputs data (temperatures, ...) on a RS232 serial link @9600bps. To log data, I've bought an USB-serial convertor that I connected to my iMac. I've tested this link with a software like "coolTerm", everything is fine !
Now, to store all this data and to provide it on a web site, I want to write a C program on the MAC to read data from USB-serial link and generate some kinds of HTML pages.
My first C lines on MAC (my frist try after several years under Linux) start hardly : this easy program crashes on open function (it seems definitely locked...) ??? I've tried to add O_NONBLOCK attribute to open function, then it returns a correct fd, but read function returns "resource temporarily unavailable".
Does someone has an idea about this problem ?
Thanks for help !
Code:
int main(int argc, char **argv)
{
int fd;
int ret;
char c;
printf("open /dev/tty.usbserial...\n");
fd = open("/dev/tty.usbserial", O_RDONLY);
printf("...Serial port open - Return code : %d\n", fd);
if (fd < 0)
{
printf("Erreur a l'ouverture de /dev/tty.usbserial - Code=%d\n", fd);
exit(1);
}
printf("Serial port opened...\n");
while (1)
{
ret = read(fd, &c, 1);
if (ret == 1)
printf("%c", c);
else
{
perror("Error read ");
close(fd);
return 1;
}
}
printf("close /dev/tty.usbserial\n");
close(fd);
return 0;
}