Forums
New posts
Articles
Product Reviews
Policies
FAQ
Log in
Register
What's new
Search
Search
Search titles only
By:
New posts
Menu
Log in
Register
Install the app
Install
Forums
macOS & iOS Developer Playground
macOS - Development and Darwin
problem on open(/dev/tty.usbserial"....)
JavaScript is disabled. For a better experience, please enable JavaScript in your browser before proceeding.
You are using an out of date browser. It may not display this or other websites correctly.
You should upgrade or use an
alternative browser
.
Reply to thread
Message
<blockquote data-quote="omr_treb22" data-source="post: 928007" data-attributes="member: 127920"><p>Hello all,</p><p></p><p>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 !</p><p></p><p>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.</p><p></p><p>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".</p><p></p><p>Does someone has an idea about this problem ?</p><p></p><p>Thanks for help ! </p><p></p><p>[code]int main(int argc, char **argv)</p><p>{</p><p> int fd;</p><p> int ret;</p><p> char c;</p><p> </p><p> printf("open /dev/tty.usbserial...\n");</p><p> fd = open("/dev/tty.usbserial", O_RDONLY);</p><p> printf("...Serial port open - Return code : %d\n", fd);</p><p> if (fd < 0)</p><p> {</p><p> printf("Erreur a l'ouverture de /dev/tty.usbserial - Code=%d\n", fd);</p><p> exit(1);</p><p> }</p><p> </p><p> printf("Serial port opened...\n");</p><p> </p><p> while (1)</p><p> {</p><p> ret = read(fd, &c, 1);</p><p> if (ret == 1)</p><p> printf("%c", c);</p><p> else</p><p> {</p><p> perror("Error read ");</p><p> close(fd);</p><p> return 1;</p><p> }</p><p> }</p><p> </p><p> printf("close /dev/tty.usbserial\n");</p><p> close(fd);</p><p> return 0;</p><p>}</p><p>[/code]</p></blockquote><p></p>
[QUOTE="omr_treb22, post: 928007, member: 127920"] 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 ! [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; } [/code] [/QUOTE]
Verification
Name this item. 🍎
Post reply
Forums
macOS & iOS Developer Playground
macOS - Development and Darwin
problem on open(/dev/tty.usbserial"....)
Top