Tuesday, December 10, 2019

#1 2008-10-31 05:08:43 pm

StevefromNewcastle
Member
Registered: 2008-10-03
Posts: 3

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

Offline

 

#2 2008-11-03 01:10:11 pm

azoth
Member
Registered: 2008-11-03
Posts: 2

Re: SerialPort X

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


Filed under: X, Serialport, Arduino

Offline

 

#3 2008-11-03 01:22:50 pm

azoth
Member
Registered: 2008-11-03
Posts: 2

Re: SerialPort X

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


Filed under: X, Serialport, Arduino

Offline

 

#4 2008-11-08 10:27:45 am

amet
Member
Registered: 2008-04-04
Posts: 5

Re: SerialPort X

StevefromNewcastle wrote:

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


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...

Offline

 

Board footer

Powered by FluxBB

RSS (new topics) RSS (active topics)