Lee Stang's scripting addition

Supporting 10.7 and up
LE STANG

Postby LE STANG » Mon Dec 15, 2008 1:12 am

about the ratiometric issue, right now this is the best I can do, but as soon as I get a better idea I will update the osax .

JackT

Postby JackT » Mon Dec 15, 2008 1:28 pm

Using your new syntax I get errors using this code;

Code: Select all

set theConnection to IKConnect
IKGetStatus theConnection
IKGetAnalogicInputsCount the connection


I have the same problem as the previous guy, I have 4 precision voltage sensors and 4 temp sensors to monitor 4 batteries temp and voltage. I have an applescript to check each one at separate times but I get incorrect readings because I cannot set the Radiometric to TRUE for the temp sensor and FALSE for the voltage sensor.

LE STANG

Postby LE STANG » Mon Dec 15, 2008 1:39 pm

There is a typo in your code, the following is working as expected :

Code: Select all

set theConnection to IKConnect
log (IKGetStatus theConnection)
log (IKGetAnalogicInputsCount theConnection)
IKDisconnect theConnection

LE STANG

Postby LE STANG » Mon Dec 15, 2008 2:06 pm

New version allowing to change ratiometric for the interface kit :

Code: Select all

set theConnection to IKConnect
IKSetRatiometric false kit theConnection
log (IKReadAnalogicInput kit theConnection)
IKSetRatiometric true kit theConnection
log (IKReadAnalogicInput kit theConnection)
IKDisconnect theConnection




http://lestang.org/osax/Phidgets/Phidgets-1.2.zip

JackT

Postby JackT » Mon Dec 15, 2008 6:58 pm

Thanks for your reply. I used your code snippet and got the response below in the RESPONSE LOG. What is the <<data PIKs ........>>

Code: Select all

set theConnection to IKConnect
log (IKGetStatus theConnection)
log (IKGetAnalogicInputsCount theConnection)
IKDisconnect theConnection



tell current application
IKConnect
«data PIKs00648A0000000000020000003A0300000000000000000000»
IKGetStatus «data PIKs00648A0000000000020000003A0300000000000000000000»
1
(*1*)
IKGetAnalogicInputsCount «data PIKs00648A0000000000020000003A0300000000000000000000»
8
(*8*)
IKDisconnect «data PIKs00648A0000000000020000003A0300000000000000000000»
end tell

LE STANG

Postby LE STANG » Tue Dec 16, 2008 12:59 am

this the internal representation of the connection, you don't have to care about this, this only for the scripting addition.

berkinet
Phidget Mastermind
Posts: 153
Joined: Thu Sep 17, 2009 12:17 pm
Contact:

Re: Lee Stang's scripting addition

Postby berkinet » Thu Sep 17, 2009 12:28 pm

I have been trying to run the ScriptingAddition inside Snow Leopard and am unable to get it to run. I placed phidget.osax in /Server/Library/ScriptingAdditions

The Script seems to recognize the additions since it pretty prints the functions appropriately (in blue). But, if I attempt to call IKConnect I get:

error "«script» doesn’t understand the IKConnect message." number -1708 from «script»

Is this a 10.6 issue? If so, is there a fix or workaround?

BlueMac

Re: Lee Stang's scripting addition

Postby BlueMac » Fri Jul 23, 2010 10:13 am

berkinet wrote:I have been trying to run the ScriptingAddition inside Snow Leopard and am unable to get it to run. I placed phidget.osax in /Server/Library/ScriptingAdditions

The Script seems to recognize the additions since it pretty prints the functions appropriately (in blue). But, if I attempt to call IKConnect I get:

error "«script» doesn’t understand the IKConnect message." number -1708 from «script»

Is this a 10.6 issue? If so, is there a fix or workaround?


I have the same problem - are we doing something stupid? :-)

nicohirtt

Re: Lee Stang's scripting addition

Postby nicohirtt » Fri Oct 01, 2010 8:21 am

I wrote a small LiveCode (RunRev, Revolution) external. Source-code is provided as well as an example application (written with LiveCode, but in French) to use Phidgets I/O boards for data-acquisition.

Look here fore explanation and download :

http://web.me.com/nicohirtt/application ... -Code.html

And here for other app's

http://web.me.com/nicohirtt/applications/

raneil

Re: Lee Stang's scripting addition

Postby raneil » Mon Jan 31, 2011 9:48 pm

In the event someone finds this thread looking information about using phidgets with AppleScript under Snow Leopard (as I did!), I thought I'd share my findings. It may be old news, but here it is anyway.

I just received my first phidget (a 1014) this evening. After some tinkering, I was able to control it reliably via AppleScript.

Using:

Mac OS X 10.6.6 (Build 10J567)
Intel Mac Pro
Le Stang's scripting addition (version 1.2)
Script Debugger 4.5
AppleScript Editor 2.3

When using Apple's AppleScript editor, be sure to open it in 32-bit mode. This is not necessary with Script Debugger, as it automatically determines if you're using 32-bit scripting additions, and adjusts accordingly on the fly.

If you save your script as an applet, be sure to launch it in 32-bit mode, too.

Save the following as a stay-open applet, and it will toggle digital output 0 every three seconds. When you quit the applet, the output will be disabled.

Cheers!

Code: Select all

property outputID : 0
property theDelay : 3
property errCondition : false

on idle
   --determine the current state of the specified output
   set newState to my getPhidget(outputID)
   
   -- if no error occurred determining the state
   if newState is not "" then
      --togge the state of the specified output
      my setPhidget(outputID, not (newState as boolean))
   else
      --otherwise display an entirely unhelpful alert message
      display alert "Phidget Error" message "The current state of the phidget could not be determined." as warning
      set errCondition to true
      quit
   end if
   return theDelay
end idle

on quit
   if not errCondition then
      my setPhidget(outputID, false)
   end if
   continue quit
end quit


on setPhidget(id, mode)
   (*
   sets the specified digital output (id) of the connected phidget to the specified state (mode)
   
   id should be in integer corresponding to the output (0-4 for the 1014, for example)
   mode should be a boolean value where
      true enables the output (closes the normally open relay contacts)
      false disables the output (opens the normally open relay contacts)
   *)
   
   local theConnection
   local errmsg, errnum
   
   try
      --ensure that id is an integer
      set id to id as integer
      
      --ensure that mode is a boolean
      set mode to mode as boolean
      
      --establish a connection to the phidget
      set theConnection to IKConnect
      
      --set the output to the indicated state
      if mode then
         IKEnableDigitalOutput id kit theConnection
      else
         -- There is a typo in Le Stang's scripting addition.  The word "Output" is misspelled "Ouput" for this command
         IKDisableDigitalOuput id kit theConnection
      end if
      
      --disconnect from the phidget
      IKDisconnect theConnection
   end try
end setPhidget

on getPhidget(id)
   (*
      returns a string representing the status of the digital output id of the connected phidget
      
         "true" if the output is enabled (on)
         "false" if the output is disabled (off)
         "" on error
   *)
   
   local theConnection
   local errmsg, errnum
   
   try
      --ensure that id is an integer
      set id to id as integer
      
      --establish a connection to the phidget
      set theConnection to IKConnect
      
      --query the phidget as to the status of the designated output
      set retVal to IKReadDigitalOutput id kit theConnection
      
      --disconnect from the phidget
      IKDisconnect theConnection
   on error errmsg number errnum
      return ""
   end try
   
   if retVal is 1 then
      return "true"
   end if
   
   if retVal is 0 then
      return "false"
   end if
   
   return ""
end getPhidget


Return to “macOS”

Who is online

Users browsing this forum: No registered users and 1 guest