View unanswered posts | View active topics It is currently Tue May 21, 2013 7:21 am



Reply to topic  [ 11 posts ] 
 Script help: 8 bytes into Indigo 
Author Message

Joined: Feb 09, 2009
Posts: 108
Post Script help: 8 bytes into Indigo
My controller board for my homemade automated blinds and temperature measurement system is working great. I have it hooked up to the Mac and I'm getting good data in the Serial Bridge Event window.

I have 8 bytes coming from the microcontroller to the Mac every half second. There are always 8 bytes and they are always in the same order. I want to take the value of each byte and put it into an Indigo variable (so 8 variables). How do I do that? It would be like the three byte example, but with 8 bytes.

Second, I will want to send 3 bytes at a time from Indigo to the microcontroller. Those will be sent from either Time/Date or Trigger Actions. How do I do that?

I have more questions, but this will get me to the point where I have the chance to figure them out for myself. :+D

Thanks!

Brian


Wed Dec 16, 2009 9:07 pm
Profile

Joined: Feb 09, 2009
Posts: 108
Post 
I can report some success!

I have it reading the serial data and putting it into variables, thanks to a post I found where someone named Greg was integrating something called a Weeder Board. If you read this, thanks Greg!

I am also able to control the blinds from Trigger Actions that call an Applescript. So, all the basic functionality is there.

Only problem: the data I am getting from the microcontroller is junk! I think what is happening it that there is more traffic going from the microcontroller than I expect, and the applescript is loyally plugging it into the Indigo variables. So, how would I tell Serial Bridge to wait for a specific byte (discarding anything that comes before it), and then put the eight bytes AFTER that specific byte into Indigo variables?

Thanks, and now that I know it works for my application I will be registering Serial Bridge tomorrow. So a good day all around! :+D

Brian


Fri Dec 18, 2009 12:19 am
Profile
Site Admin
User avatar

Joined: Jan 27, 2003
Posts: 11689
Location: Texas
Post 
Hello Brian,

Check the Event Log window in Serial Bridge. There is an option in the connection window to have Serial Bridge log all incoming data as bytes. When you do this, do the bytes look correct in the log? Are you sure you have the baud rate set correctly?

It sounds like you need to use AppleScript to loop over the incoming bytes. Take a stab at it and if doesn't work, then post your AppleScript code along with details of what you are trying to do and what is currently happening.

_________________
Image


Fri Dec 18, 2009 5:44 pm
Profile WWW

Joined: May 27, 2007
Posts: 689
Location: NC
Post 
Could it be getting a string and needing an integer?

Also does a window shade controller *need* to update Indigo twice a second?


Sun Dec 20, 2009 6:14 am
Profile

Joined: Feb 09, 2009
Posts: 108
Post 
I guess I am still doing something wrong. I have confirmed the data being sent by the microcontroller is correct, so I guess I am reading it wrong?

Here is some sample data sent by the microcontroller:

1 65 2 205 205 26 0 0

First is the TV on/off state, either 1 or 2.
Second is the name of the window talking, in this case "A", sent numerically so 65.
Third is whether the window is closed or open, 1 or 2.
Fourth is a light dependent resistor, 0 - 254
Five is another LDR, 0-254
Sixth is a temperature in Celcius, so roughly 0-100, more like 20-40
Seventh and Eighth are for the future, and right now are always zero.

There are spaces sent between each one.

So is this the correct way to read them?



Code: Select all
wait for data from source connectionName to count 15

set eightBytes to read byte list from source connectionName to count 15
        log "first byte = " & item 1 of eightBytes using type "Sample"
        log "second byte = " & item 3 of eightBytes using type "Sample"
        log "third byte = " & item 5 of eightBytes using type "Sample"
        log "fourth byte = " & item 7 of eightBytes using type "Sample"
        log "fifth byte = " & item 9 of eightBytes using type "Sample"
        log "sixth byte = " & item 11 of eightBytes using type "Sample"
        log "seventh byte = " & item 13 of eightBytes using type "Sample"
        log "eighth byte = " & item 15 of eightBytes using type "Sample"
       
        tell application "IndigoServer"
            set value of variable "PTVOnOrOff" to item 1 of eightBytes
            set value of variable "Pwloc" to item 3 of eightBytes
            set value of variable "Pcoro" to item 5 of eightBytes
            set value of variable "PLDR1d" to item 7 of eightBytes
            set value of variable "PLDR2d" to item 9 of eightBytes
            set value of variable "PTempd" to item 11 of eightBytes
            set value of variable "PBlank1" to item 13 of eightBytes
            set value of variable "PBlank2" to item 15 of eightBytes
        end tell



Merry Christmas, and thanks for the help!

Brian


Thu Dec 24, 2009 8:48 pm
Profile

Joined: May 27, 2007
Posts: 689
Location: NC
Post 
shouldn't the count be 21? (do spaces count?)


Fri Dec 25, 2009 10:20 am
Profile
Site Admin
User avatar

Joined: Jan 27, 2003
Posts: 11689
Location: Texas
Post 
What does the Serial Bridge Event Log show when you try it?

_________________
Image


Sat Dec 26, 2009 1:44 pm
Profile WWW

Joined: Feb 09, 2009
Posts: 108
Post 
support wrote:What does the Serial Bridge Event Log show when you try it?


Sorry for the long delay. I've almost got this figured out!

SB receives hex:

31 20 36 35 20 31 20 35 30 35 30 34 39 20 34 39 35 35 35 37 20 34 38 35 30 34 39 20 30 20 30 0D 0A

... which it automatically translates to ascii decimal (and with me removing the "20" space character),

1 6 5 1 50 50 49 49 55 57 48 50 49 0 0 CR NL

... which REALLY means

1 A 1 221 179 021 0 0 CR NL

This line ^^^^^^ is what I want to import into Indigo. So I guess this just all comes down to an Applescript question, and Google is not finding the answer.

How do I turn an ascii number to its character? What do I use to turn "65" into "A"? Or "50" into "2"?

Thanks, and happy new year!
Brian


Thu Dec 31, 2009 9:38 pm
Profile
User avatar

Joined: Nov 18, 2008
Posts: 1721
Location: Berkeley, CA
Post 
How do I turn an ascii number to its character? What do I use to turn "65" into "A"? Or "50" into "2"?

set foo to ASCII character 65

Happy New Year to you too


Thu Dec 31, 2009 10:57 pm
Profile
Site Admin
User avatar

Joined: Jan 27, 2003
Posts: 11689
Location: Texas
Post 
You might also want to experiment around with changing this:
Code: Select all
set eightBytes to read byte list from source connectionName to count 15

to use the verb that reads in a string instead:
Code: Select all
set myString to read string from source connectionName

The verb has an optional to count argument that might help, but you might still have to loop through the string looking for the CR NL characters to find the breaks in the lines of data (the above example might read more than one line and put it all into myString).

_________________
Image


Fri Jan 01, 2010 10:17 am
Profile WWW

Joined: Feb 09, 2009
Posts: 108
Post 
Reading it as a string instead of a byte list worked. I thought that would give me one big string I'd have to break up, but it turns out that is really easy to do in Applescript.

I now have 1 station system 100% functional. Time to work on stations 2-8!

Thanks for the help, everyone.

Brian


Sun Jan 03, 2010 2:59 pm
Profile
Display posts from previous:  Sort by  
Reply to topic   [ 11 posts ] 

Who is online

Users browsing this forum: No registered users and 1 guest


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.