SerialPort X

I was really glad to find serialport X as it saves me having to use smile to run some action scripts, but I only seem to be able to run the script once as it can then not access the serial port I assume that is because I have not closed it right. I am still learning applescript to I would appreciate any advice.

set dev to “/dev/cu.usbserial-A9008XQj” – Keyspan USB <-> Serial Port adapter
–set portRef to serialport open dev
set portRef to serialport open dev bps rate 9600 data bits 8 parity 0 stop bits 1 handshake 0
if portRef is equal to -1 then
display dialog " could not open port "
else – send command
set ADcmd to “1*!”
serialport write ADcmd to portRef
delay 2
serialport close
end if
end

Cheers
Steve

Hi Steve

You’ve probably discovered this by now, but you need to specify the port to close it.
So your close command would have to be serialport close portRef.

You may also find that you need to send a character before your command to make sure it is recognized by the Arduino.
I don’t know why, but if you have problems, try

serialport write " " to portRef
set ADcmd to “1*!”
serialport write ADcmd to portRef
delay 2

And of your two lines

–set portRef to serialport open dev
set portRef to serialport open dev bps rate 9600 data bits 8 parity 0 stop bits 1 handshake 0

the first is fine as the numerical data corresponds to the default options.

azoth

I forgot to include the delay in above suggestion. It should be:

serialport write " " to portRef
delay 2
set ADcmd to “1*!”
serialport write ADcmd to portRef
delay 2

azoth

your problem is :

set ADcmd to “1*!”
serialport write ADcmd to portRef
delay 2
serialport close dev <— HERE

you need to tell it which port to close…