Pages

Friday, May 21, 2010

Simple Serial Mac AppleScript App

I'm working towards getting AVR-powered Pokey equipped with a bluetooth modem. While working on prototyping communications using the BASIC Stamp 2, I needed a simple, line-at-a-time serial communications application on my MacBook.

Having recently finished playing with Xcode and AppleScript I decided to write the comm program this way, too. Eventually this application will be evolved to gather telemetry data and send remote commands.

The AppleScript application interface consists of a pulldown menu to select a serial device to use, a button to connect to (and disconnect from) the serial device, a status indicator, a text field for data received, and a text field and send button to send data. The GUI enforces basic, state-driven behavior by enabling and disabling objects on the interface based on the connection state.

Connecting to BlueSMiRF serial port

So in other words, you can't connect until you've selected a device. Once you are connected, you can't pick a new device. If you're disconnected the button is labeled "Connect" and clicking it connects to the selected device. If you're connected the button is renamed "Disconnect" and clicking it disconnects. Likewise, the send button and text fields are controlled by connection state. Here's a state diagram that covers the device selection and connect/disconnect button.

State Diagram of Serial Comm App

With the first incarnation of the AppleScript app, I was able to successfully connect to the BlueSMiRF through the MacBook bluetooth transciever, receive, and display data from the BS2. The second incarnation permitted two-way communications.

2 comments:

Hi Michael, I have been searching the web to find a easy way to send simple text based commands to a serial device using applescript. I found your page and tried your GUITest but could not get it to work. Here is the error:

http://www.imber.com/tmp/GUITest_Error.png

Any ideas on your GUI or a simple way to send text down a serial connection?