[racket] usb/serial port
On 7 Sep 2014, at 17:54, Eduardo Costa <edu500ac at gmail.com> wrote:
>
> I am not sure if there a library specifically written in racket for reading/writing to serial ports, however, you can read/write to character devices using standard i/o routines.
>
> Could a member of this list elaborate on this answer? For instance, how can I open a device from Racket? I tried:
>
>> (define out (open-output-file "/dev/tty.usbmodem1421"))
> . . ../../Applications/Racket v6.1/share/pkgs/drracket/drracket/private/rep.rkt:1123:24: open-output-file: cannot open output file
> path: /dev/tty.usbmodem1421
> system error: Permission denied; errno=13
>>
open-output-file should work, are you sure you have the right permissions? This is what I use to write/read to/from an Arduino board connected using a USB port (where port-name is /dev/tty.usbmodem*" on mac, similar to your case):
(system "stty -f " port-name " 57600 cs8 cread clocal")
(set! out (open-output-file port-name #:mode 'binary #:exists 'append))
(set! in (open-input-file port-name #:mode 'binary))
(file-stream-buffer-mode out 'none)
It works both on mac and linux. I have a separate thread to read the USB port, but it may not be necessary in your case.
Have a look at open-firmata (line 414) of this file: https://bitbucket.org/fraimondi/racket-firmata/src/7707268b4b52aabe336c69d347877459dc8c7ae5/firmata.rkt?at=master if you want more information. This works also under Windows.
F