View unanswered posts | View active topics It is currently Sat Jul 31, 2010 10:24 am



Reply to topic  [ 7 posts ] 
 From the Beginning 
Author Message

Joined: Feb 11, 2008
Posts: 5
Location: Berkshire, United Kingdom
Post From the Beginning
Hi ive now spent the best part of two days looking at this program as a whole and no nearer as to where to go. Im normally quite good at this stuff but that is usually achieved by seeing something working and building on it. Ive got Indigo Pro, SerialBridge and a Weeder Board. I can talk to the weeder board from windows fine. Ive connected it to my mac via a 10 port Serial>USB adapter (the same one used on windows so I know it works) loaded the drivers for said adapter and Serial Bridge sees the Ports. Got hold of a copy of DarkTech's Script. Loaded that in to serial bridge. And thats as far as I can work out. How do I get serial bridge to Talk to Indigo Via Applescript and what do I need to do to to get what the weeder board is saying to activate stuff in Indigo. I have NO experience with Indigo at all but it all seems to want to talk to X10 or insteon devices which if I had some I could gain some knowledge of this program and what difference between Devices, Triggers..... Are, but sadly I dont. Im sure once I get started Ill be fine Just dont know where to start.


Mon Apr 27, 2009 12:46 pm
Profile

Joined: Aug 03, 2008
Posts: 20
Location: Gambrills, MD
Post weeder io
I've got both a digital io and an analog io board from weeder hooked up to indigo using serial bridge. Here's the code for the AS that I associate with the connection. I took some code from someone else for the digital io and then added the code for the analog io module. Hope this helps.


Code: Select all
-- Weeder IO Script
--
--
--
--

on MyProcessSerialData(connectionName)
   tell application "Serial Bridge"
      
      wait for data from source connectionName to count 1
      
      set whichWeeder to read string from source connectionName to count 1
      
      if whichWeeder = "A" then -- digital I/O
         
         -- capture the remaingin two character word from the Weeder Module
         set WeederResponse to read string from source connectionName to count 2
         
         -- Log it in its untraslated state
         log "The Weeder says... " & "A" & WeederResponse using type "Sample"
         set restOfString to read string from source connectionName
         
         -- Identify the which contact the Weeder is reporting on.
         set ContactName to "Contact_" & first character of WeederResponse as text
         
         
         -- Convert the Contact state to state of the Contact
         set ContactState to second character of WeederResponse
         if ContactState = "L" then
            set ContactState to "CLOSED" as text
         else if ContactState = "H" then
            set ContactState to "OPEN" as text
         end if
         
         -- Log the the tranaslated state.
         log "That translates to... " & ContactName & " is " & ContactState & "."
         
         -- Get a timestamp from the OS.
         set time_stamp to do shell script "date +%Y-%m-%d\\ %H:%M:%S"
         
         tell application "IndigoServer"
            log ContactName & " is " & ContactState & "."
            
            -- Create if neccessary a state varable name after the Contact, then set the state.
            if not (variable ContactName exists) then
               make new variable with properties {name:ContactName, value:ContactState}
            else
               set value of variable ContactName to ContactState
            end if
            
            -- Create a dynamic variable name (just because we are going to call on  it several times)
            set ContactTimestamp to ContactName & "_LastEvent_TimeStamp"
            
            -- Create if neccessary a timestamp varable name after the Contact number, then set the timestamp.
            if not (variable ContactTimestamp exists) then
               make new variable with properties {name:ContactTimestamp, value:time_stamp}
            else
               set value of variable ContactTimestamp to time_stamp
            end if
            
         end tell
         
      else if whichWeeder = "B" then -- analog I/O
         
         delay 0.2
         set wtaio to read string from source connectionName
         log "Analog I/O:  " & wtaio
         --set measurement1 to word 1 of wtaio as integer
         --log "Word 1:  " & measurement1
         
         tell application "IndigoServer"
            
            set AutoZero to word 1 of wtaio
            if AutoZero = "Z" then
               log "AutoZeroize WT Analog I/O"
               
            else
               set value of variable "wtaio1" to word 1 of wtaio
               set value of variable "wtaio2" to word 2 of wtaio
               set value of variable "wtaio3" to word 3 of wtaio
               set value of variable "wtaio4" to word 4 of wtaio
               set value of variable "wtaio5" to word 5 of wtaio
               set value of variable "wtaio6" to word 6 of wtaio
               set value of variable "wtaio7" to word 7 of wtaio
               set value of variable "wtaio8" to word 8 of wtaio
               log "Reading WT Analog I/O"
               
               -- adjust scaling for integer degrees with a single decimal place
               set t1 to (get value of variable "wtaio8" as string)
               set t1Last to last character of t1
               set t1Len to length of t1
               set t1 to characters 1 thru (t1Len - 1) of t1 as string
               --set value of variable "TempBasement" to t1 & "." & t1Last
               set value of variable "TempBasement" to t1
               
               set t1 to (get value of variable "wtaio1" as string)
               set t1Last to last character of t1
               set t1Len to length of t1
               set t1 to characters 1 thru (t1Len - 1) of t1 as string
               set value of variable "TempOutside" to t1 & "." & t1Last
               
            end if
            
         end tell
         
      end if
      
   end tell
end MyProcessSerialData

-----------------------------------------------------------------------------
on startCommunication(connectionName)
   tell application "Serial Bridge"
      -- initialize Serial Bridge; 5 contacts into Switch Mode
      
      send to source connectionName string "ASI" & return
      delay 0.2
      send to source connectionName string "ASJ" & return
      delay 0.2
      send to source connectionName string "ASK" & return
      delay 0.2
      send to source connectionName string "ASL" & return
      delay 0.2
      send to source connectionName string "ASM" & return
      delay 0.2
      
      -- make other ios into outputs to prevent false triggering
      send to source connectionName string "AHA" & return
      delay 0.2
      send to source connectionName string "AHB" & return
      delay 0.2
      send to source connectionName string "AHC" & return
      delay 0.2
      send to source connectionName string "AHD" & return
      delay 0.2
      send to source connectionName string "AHE" & return
      delay 0.2
      send to source connectionName string "AHF" & return
      delay 0.2
      send to source connectionName string "AHG" & return
      delay 0.2
      send to source connectionName string "AHH" & return
      delay 0.2
      send to source connectionName string "AHN" & return
      
      
      log "INITIALIZED" using type "Error"
      
      
      -- Loop forever: wait for data, read it, process it, and optionally send
      -- out serial data.
      --
      -- We do not want our script to return or exit since Serial Bridge
      -- only calls our script on launch (or when the Reload Script button
      -- is pressed).
      
      repeat while true
         try
            set maxTimeoutDelay to 8947848 -- 103.56 days (hex 0x00888888)
            with timeout of maxTimeoutDelay seconds
               my MyProcessSerialData(connectionName)
            end timeout
         on error number errNum
            
            (* Log timeout errors (-1712) but continue processing loop. Without
                      * handling this error, the script would throw out of the repeat loop
                      * and terminate if any of the script calls were to throw a timeout error.
                      * Normally, if there was a timeout error thrown you would want
                      * to continue processing your main loop in an attempt to get back
                      * in syncronization with the hardware. By catching this error we
                      * will do exactly this and continue to process our script repeat loop.
                      *)
            
            if errNum is -1712 then
               log "timeout waiting for serial data" using type "Error"
            else if errNum is -1708 then
               log "AppleEvent not handled" using type "Error"
               return -- fatal error; exit script processing
            else if errNum is -128 then
               log "connection script aborted" using type "Error"
               return -- fatal error; exit script processing
            else
               log "error " & errNum & " inside MyProcessSerialData()" using type "Error"
               return -- maybe fatal error; exit script processing
            end if
            
         end try
      end repeat
   end tell
end startCommunication



[/code]

_________________
Tim


Mon Apr 27, 2009 5:46 pm
Profile

Joined: Apr 01, 2003
Posts: 731
Location: Rio Rancho, NM
Post 
Great script. I had a much sloppier version for my Weeder, I will have to replace it with this one.

_________________
Greg In The Desert


Mon Apr 27, 2009 6:51 pm
Profile WWW

Joined: Feb 11, 2008
Posts: 5
Location: Berkshire, United Kingdom
Post 
WOW when I get back from work tonight I guess Ive got some playing to do. Ive also got both the DIO and the AIO but im just starting with the DIO. Many thanks for that. Hopefully that gets me going.


Tue Apr 28, 2009 1:37 am
Profile

Joined: Aug 03, 2008
Posts: 20
Location: Gambrills, MD
Post more weeder io
I forgot to add that the digital io board is initialized to send a report on a level change, but that the analog io board is polled once per hour. Here's the small script in a trigger action set to fire once every hour (but you could set your trigger action to poll at a slower or faster rate depending upon your need):

Code: Select all

tell application "Serial Bridge"
    -- request reading from WT Analog I/O
    send to source "wtdio" string "BS" & return
    
end tell




and then I also have another small script in a trigger action to perform a Auto Zeroize function for the analog io board once a day:

Code: Select all

tell application "Serial Bridge"
    -- AutoZeroize WT Analog I/O
    send to source "wtdio" string "BZ" & return
    
end tell



Obviously (but perhaps not), the weeder digital io board is setup to use address A while the analog io board is setup to use address B.

Sorry for not including this in the earlier post. But it's been so long since I set this up that I had forgotten about this little aspect.

Also, just to be clear, I didn't write most of this script rather I just modified it to include the checking to see which weeder board was responding (analog or digital) and also the handling of the analog response to the polling. But I also don't remember where the original script came from -- but someone did an excellent job in writing it.

_________________
Tim


Tue Apr 28, 2009 9:24 pm
Profile

Joined: Jan 17, 2010
Posts: 11
Location: San Fran
Post Weeder DIO with Serial Bridge
Hi all,
Sorry, a few questions for the applescript challenged.

I was trying to get your weeder script running, thanks tjm000, but I don't get the basics of what goes where.
Where is "wtdio" defined for when you poll the weeder board? Just running that will naturally error.
I couldn't find a wikipage on this (Is there one?) so sorry if it's been covered elsewhere.
I've been using the DIO WT board with misterhouse for 6+ years so I know it works fine. I can connect to the DIO board via a usb-serial with SerialBridge and get, what I assume is the standard data:
Received 41
Received 21
Received 0D

But I'm not sure how to put it all together.

I've always ignored applescript so I'm just getting up to speed after transitioning from perl. Applescript to me is like a bad date: A little too verbose and still makes no sense.

Thanks for the help.
Michael


Sun Jan 17, 2010 4:48 pm
Profile
Site Admin
User avatar

Joined: Jan 27, 2003
Posts: 8013
Location: Texas
Post Re: Weeder DIO with Serial Bridge
Hi Michael,

cme1ca wrote:Where is "wtdio" defined for when you poll the weeder board? Just running that will naturally error.

wtdio is the Serial Bridge connection name Tim used when he first created the connection. When you choose the File->New Connection menu item in Serial Bridge it will prompt you for a connection name. To use Tim's script unmodified, enter "wtdio" in that Save As dialog.

Next, make sure in the connection window that appears you have the correct serial port, baud rate, etc., selected.

Next, press the Edit Script... button to edit the connection script that Serial Bridge will automatically launch when it runs for this port. This will open the Apple Script Editor with an example script template. You'll want to copy/paste Tim's original script (second post above) into this file. Just delete everything currently in the file and replace it with Tim's script. Press the Compile button to make sure it got copied in correctly (check for errors), then Save and quite out of the Script Editor. Actually, before you save and quit, look at the strings the script sends at the top of the startCommunication() function. You might want to edit those based on your Weeder board input/output configuration? Not sure...

Back in Serial Bridge now you'll want to press the Reload Script button to have Serial Bridge pull in and start executing the script you just pasted in. Watch SB's Event Log window to make sure there aren't errors. Also check the Script Status field in the connection window to make sure it stays running.

Now open the Variable window inside of Indigo. As input changes come in from the Weeder board the Serial Bridge AppleScript looks like it will automatically create and update Indigo Variables for each input. From there you can create Trigger Actions whenever a variable changes.

To poll the analog inputs from the Weeder it looks like Tim is sending the string "BS" to the weeder board every hour (his first script in the 5th post on this forum thread). To use that Script create a Time/Date Action in Indigo that repeats every 1 hour (or however often you need), set the action type to Execute AppleScript and copy/paste the script contents into the embedded text field.

_________________
Image


Wed Feb 03, 2010 8:47 am
Profile WWW
Display posts from previous:  Sort by  
Reply to topic   [ 7 posts ] 

Who is online

Users browsing this forum: No registered users and 0 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group.   Template designed by STSoftware.