Comparing string?
Falcon
Posts: 191
I pretty sure there is no way to actually compare a string but I'm looking for a workaround to the following situation:
I use the following routine to compare a bit from a sensor to check to see if there is a change, and act accordingly.
I have a PINK with a small webpage with variables that I can update with my Droid phone as either an OFF or ON.
I use the following code to retreive the variable from the PINK and display it:
I want to use the ON and OFF strings to trigger X-10 actions using XOUT using my compare routine. The problem is getting the ON and OFF converted to a 1 or 0 since I cannot compare a string.
Any ideas how to check the string and set a BIT to 1 if it is ON, and 0 if it is OFF?
falcon
I use the following routine to compare a bit from a sensor to check to see if there is a change, and act accordingly.
Sensor: temp = Current1.BIT0 'load temp with current door state IF Saved (0) = temp THEN 'if door saved = door current = no change set to false Flag (0)= 0 'no change ensure flag is cleared ELSE Flag (0) = 1 'door changed states , set flag to true Saved (0) = temp 'save current state for compare next time through ENDIF IF Flag (0) = 1 THEN IF Saved (0) = 1 THEN DEBUG CRSRXY, 24, 14,"OPEN " ELSE DEBUG CRSRXY, 24, 14,"CLOSED" ENDIF Flag (0) = 0 ENDIFIn this case compare works fine since I'm working with a BIT.
I have a PINK with a small webpage with variables that I can update with my Droid phone as either an OFF or ON.
I use the following code to retreive the variable from the PINK and display it:
PAUSE 50 SEROUT TX, PINKBaud, ["!NB0R01"] ' Command To Read Variable 04 SERIN RX, PINKBaud, [STR NBVAR\3] DEBUG CRSRXY, 24, 27, STR nbvar, CRThe DEBUG command can easily send the nbvar string to the terminal window.
I want to use the ON and OFF strings to trigger X-10 actions using XOUT using my compare routine. The problem is getting the ON and OFF converted to a 1 or 0 since I cannot compare a string.
Any ideas how to check the string and set a BIT to 1 if it is ON, and 0 if it is OFF?
falcon
Comments
I appreciate the reply.
I don't really understand how to use this snippit to determine if that 3 byte string is ON or OFF. I do see how I can pick a single BIT out of a BYTE and use that for a comparison.
The string that is retrieved from the PINK is 3 bytes long. I was wondering if I could just check the second byte of the string (array actually) to see if it is an ASCII "N" (78) or "F" (70)?
Would something like the following work?
falcon
So, if NBVAR(2) is either $41 (A for Affirmative) or $4E (N for Negative) -- The test for NBVAR(2) = $4e isn't essential (in a perfect world if it's not A then it's N), but this guards against jumbled data, since there's no checksum or parity.
I worked that code into my project as seen below but used $4E to look for the N, and $46 to look for the F since the string will only ever be ON or OFF:
I have the XOUT commands inhibited until I get the arguments sorted out so right now I'm just trying to get the correct feedback with the DEBUG statements.
As written, I get the error message repeatedly.
I'm not 100% sure which BYTE would be the first read from the PINK but in the case of the OFF, the second BYTE should alwys be an F no matter which end it the first BYTE read.
I also tried the arguments with $6E and $66 in case the PINK was returning lower case letters but that didn't change the result.
I checked the PINK variable page and the variables are updating correctly (and immediately) when changed with my mobile phone. The PINK is mostly used to provide variable data to the webpage from the BS2PX, and that function works flawlessly.
Any othe ideas for those arguments?
Thanks for your help.
falcon
That helped. I was using NBVAR(2) in my argument but I needed to use NBVAR(1) since (1) was the middle of the three BYTES.
The DEBUG statements are changing based on inputs from my phone via the PINK.
Now if I can just get the X-10 PL513 working. The LED is staying on all the time, even with no phone line plugged in.
Thanks for all your help.
falcon
I thought that you had a handle on that.
I posted extensively on X10 and the PL513 a few years ago, but nothing comes up with the site's search.
I guess there's a way to search the forum via google, but the address escapes me just now.
Found It!
http://forums.parallax.com/showthread.php?110688-X10-power-line-interface-to-BS2-Question!