I'm writing an app in Swift that communicates with multiple Teensys (3.1 & LCs) but I've hit a few issues. Any experience / pointers much appreciated.
There's a number of ways to talk to a Teensy 3/LC from Swift on a Mac:
Serial over USB:
I had no problems communicating from a console app written in C, but now I'm using Swift (so I can have a natty GUI going on) I'm relying on a library to make the Serial stuff easier - ORSSerialPort. Trouble with it is that for some reason the Teensys take ages to close their port - if I call the ORSSerialPort close() function, the app hangs for anywhere between 1 and 30 seconds, spinning ball an' all that. Arduino Mega running very similar code doesn't. Could be a problem in the library, but thought I'd ask in case it rings a bell for anyone. Or if anyone's written serial library in Swift, that'd be ace...
USB-HID-Raw
I've got to move over to this: the only stumbling block is in setting up a callback so I don't have to poll the port. Bit of an esoteric question, but if anyone has already done it, I'd love a pointer or two: I can call Paul's USB-HID C library of functions OK by using a bridging header in Swift to declare the C functions, but I can't suss out how to wire in a callback facility so I don't have to poll the port. Pushing my knowledge of Swift *and* C.
There's a number of ways to talk to a Teensy 3/LC from Swift on a Mac:
Serial over USB:
I had no problems communicating from a console app written in C, but now I'm using Swift (so I can have a natty GUI going on) I'm relying on a library to make the Serial stuff easier - ORSSerialPort. Trouble with it is that for some reason the Teensys take ages to close their port - if I call the ORSSerialPort close() function, the app hangs for anywhere between 1 and 30 seconds, spinning ball an' all that. Arduino Mega running very similar code doesn't. Could be a problem in the library, but thought I'd ask in case it rings a bell for anyone. Or if anyone's written serial library in Swift, that'd be ace...
USB-HID-Raw
I've got to move over to this: the only stumbling block is in setting up a callback so I don't have to poll the port. Bit of an esoteric question, but if anyone has already done it, I'd love a pointer or two: I can call Paul's USB-HID C library of functions OK by using a bridging header in Swift to declare the C functions, but I can't suss out how to wire in a callback facility so I don't have to poll the port. Pushing my knowledge of Swift *and* C.