Support

If you have a problem or need to report a bug please email : support@dsprobotics.com

There are 3 sections to this support area:

DOWNLOADS: access to product manuals, support files and drivers

HELP & INFORMATION: tutorials and example files for learning or finding pre-made modules for your projects

USER FORUMS: meet with other users and exchange ideas, you can also get help and assistance here

string manipulation

Home and building automation using flowstone

string manipulation

Postby JB_AU » Tue May 21, 2013 11:50 pm

In my attachment i am trying to manipulate user input as string variables which will be used to manipulate io control.
My arduino sketch for this system is 2kb. I am trying to build a universal io interface.

From left to right, the first selector allows the user to choose the type of control needed, the next selector depending on the value of the first, makes available the required input/outputs available.
This information is sent to an edit box, which ideally sets the led red until all command requirements are met, and turns green to signify argument is ready to be sent from the button, where required feedback is written to the final edit box.

How do i keep the led red until needed?
All read requirements are thus far met, How would i set the led green?
Were a write argument requires a numerical value input, how can i accomplish this?

Thankyou
Attachments
stringmaker.fsm
(28.4 KiB) Downloaded 841 times
"Two things are infinite: the universe and human stupidity; and I'm not sure about the the universe."

Albert Einstein
User avatar
JB_AU
 
Posts: 196
Joined: Tue May 21, 2013 11:01 pm

Re: string manipulation

Postby MyCo » Wed May 22, 2013 1:31 am

Hope this is what you mean... I commented in the schematic.
Attachments
stringmaker (MyCo).fsm
(29.49 KiB) Downloaded 872 times
User avatar
MyCo
 
Posts: 762
Joined: Tue Jul 13, 2010 12:33 pm
Location: Germany

Re: string manipulation

Postby RJHollins » Wed May 22, 2013 1:48 am

Nice touch with the arrow pointers, MyCo !
:)
RJHollins
 
Posts: 1242
Joined: Thu Mar 08, 2012 7:58 pm

Re: string manipulation

Postby JB_AU » Wed May 22, 2013 8:09 am

As nice as that reply was, & thankful that i am.
The led state changes to green even when the statement is wrong, this would be my mistake, as i was expecting a verbal answer & not a full blown demonstration :ugeek:

For all statements of ar & dr are true, as no further input is needed, whereas aw & dw statements are false until the user has inputted the correct parameters.

"dw7" by itself would be false, led would equal red, until "dw7+" is supplied a user value, "dw7+1" , writing pin7 HIGH.

My apologies and thanks for not going into further detail from the first question.
"Two things are infinite: the universe and human stupidity; and I'm not sure about the the universe."

Albert Einstein
User avatar
JB_AU
 
Posts: 196
Joined: Tue May 21, 2013 11:01 pm

Re: string manipulation

Postby MyCo » Wed May 22, 2013 5:41 pm

For me, it's often easier to build the schematic than explaining it in english (which is obviously not my native language). So here is a version, that has the Data added to the write commands and at the end it gets cheaply verified. When this does what you want, you can ask questions about the parts of the schematic that you don't understand. That's some kind of the other way around: First find a solution to your problem, and then understand the way this solution works :twisted: Sorry!
Attachments
stringmaker2 (MyCo).fsm
(31.17 KiB) Downloaded 822 times
User avatar
MyCo
 
Posts: 762
Joined: Tue Jul 13, 2010 12:33 pm
Location: Germany

Re: string manipulation

Postby trogluddite » Wed May 22, 2013 10:51 pm

Another alternative to this problem would be to use 'regular expressions' inside a Ruby primitive.
Regular expressions are common to many programming languages, and are an extremely versatile way to parse any kind of text.
The downside is that they are very cryptic and take some learning - though there are many excellent resources out there on the web that can help with this.

First you need a Ruby editor primitive, and right click the output connector to choose the 'boolean' data type for the output. Then, the Ruby code for your example would look something like this...

Code: Select all
if @in =~ /[ad]r\d+|[ad]w\d+=\d+/
  output true
else
  output false
end


Guess you see now what I mean about cryptic"! ;) But the regular expression can be broken down into smaller chunks that are easier to undertand (I'll assume that the if...else part is fairly intuitive).

Firstly @in will be the string coming in at the input, and '=~' means "does this string match the character pattern'.
The regular expression is contained between the forward slashes (all the other kind of brackets are already used for other things!).
It then divides into two parts, with the 'pipe' character '|' in the middle. The '|' just means OR - the text must either match the bit before the '|' or the bit after it.

Part 1...
[ad]r\d+
[ad] means 'find any of the characters inside the brackets' - in this case either 'a' or 'd', though you can include as many as you need.
Then 'r', which simply means, 'the next character must be 'r'' (so this parts checks only for the read codes)
The backward slash means that the next item is a special character code - in this case '\d' means "any number character" (i.e. digit).
That's followed by '+', which means "find one or more of the previous character" - so that '\d' can find numbers with more than one digit.
So that takes care of the 'read' part - we find an 'a' or a 'd', followed by 'r', followed by an integer number (we didn't say to look for decimal points!).

The second half of the 'OR' looks pretty similar, the beginning...
[ad]w\d+
...is just like the 'pattern' for the read codes, but with 'w' substituted for 'r'.
Then there is '=' to check for an equals character separating the channel from the value that you want to assign, and finally '\d+' again to find the second number sequence.

The trickiest bit to get used to is knowing when a character in the pattern will simply match a character of the input string, and when it has a special meaning, like the {, }, \, + characters - but you get used to that after a while. (NB putting a '\' before a special character cancels its effect so that you can check for the literal character; e.g. '\+' means 'look for a plus sign'.

That's just scratching the surface of regular expressions - it could be taken much further. For example, it is possible to extract the '\d+' sections as so-called "captures", enabling you to treat them as numbers and check that the values are in the correct range - or to parse a whole string with multiple commands to send them as a sequence.
All schematics/modules I post are free for all to use - but a credit is always polite!
Don't stagnate, mutate to create!
User avatar
trogluddite
 
Posts: 984
Joined: Fri Oct 22, 2010 12:46 am
Location: Yorkshire, UK

Re: string manipulation

Postby JB_AU » Thu May 23, 2013 3:51 am

:lol: Gloriously Stupendous Chaps!

aka Impressive work.

Might take a while to get my head around those ruby arguments, but they do make sense, after reading your unabridged break down trogluddite :roll:
Your examples MyCo are just as impressive, breaking down a module and rebuilding it in a seperate sheet , is helping to understand what each component does.

My hat goes off to both of you! :ugeek:

Why neither has 5 dsp logo's below their avatar is a mystery to me, your examples and explanations prove & show your greater understanding of the flowstone system.

Thank you for you time & diligence.
"Two things are infinite: the universe and human stupidity; and I'm not sure about the the universe."

Albert Einstein
User avatar
JB_AU
 
Posts: 196
Joined: Tue May 21, 2013 11:01 pm

Re: string manipulation

Postby RJHollins » Thu May 23, 2013 6:25 am

Agreed ... on BOTH !

Wish there was a way to assemble a practical 'USER's MANUAL' from the explanations and examples that
GURU members so graciously share !

Granted, I certainly need to continue re-reading the manual, but so often I stumble into a thread ... on a topic I might have no interest or understanding ... only to learn something that may very well be a 'key' to my project, or a revelation to a contemplated idea for one.

Thanks for sharing your time, knowledge, and experience ! And to be able to ask follows is priceless.

I know I have a ton to learn ... but I'm also realizing that a 'elegant' programming concept becomes a cornerstone and building block that can ascend a initial idea [program] into a powerful application. Its' like playing with musicians that are better than me ... I might really stink it up ... but the things I learn from that .... !
:D
RJHollins
 
Posts: 1242
Joined: Thu Mar 08, 2012 7:58 pm

Re: string manipulation

Postby JB_AU » Thu May 23, 2013 4:44 pm

I am missing just a little something on what is expected as output.
From a terminal dw12+1 , dr12 returns 1.
But there is something i am not doing, hex-->string? , ascii-->string , binary?
Or something i can't find in the forum.
Attachments
so_close.fsm
(170.21 KiB) Downloaded 828 times
"Two things are infinite: the universe and human stupidity; and I'm not sure about the the universe."

Albert Einstein
User avatar
JB_AU
 
Posts: 196
Joined: Tue May 21, 2013 11:01 pm

Re: string manipulation

Postby MyCo » Thu May 23, 2013 5:15 pm

There are primitives that handle the conversions. See Attachment. It can also be done in Ruby using "String unpack" method.
Attachments
conversion (MyCo).fsm
(514 Bytes) Downloaded 838 times
User avatar
MyCo
 
Posts: 762
Joined: Tue Jul 13, 2010 12:33 pm
Location: Germany

Next

Return to Home Automation

Who is online

Users browsing this forum: No registered users and 1 guest