BasicMicroUK - Forums

Comparing string
Page 1 of 1

Author:  ChrisB [ Mon Apr 10, 2017 9:11 am ]
Post subject:  Comparing string


This should be quite easy but I can't figure it out :-(
I wish to compare a string with an if statement.
I am using a nano 28 sx and wifi module from parallax.
I am sending commands from my computer to the nano through the WIFI module using TCP.
I am using HSERIN, see code below :
string var byte(4)
sethserial1 h38400', h8databits, hnoparity, h1stopbits
   hserin [str string\20\13]
   serout s_out,i9600,[str string\4\13,13]
   pause 1000
goto main

HSERIN works well but I don't know how to compare the string the string I am receiving to make the nano do something?
The code above won't compile neither anything I have tried so far...

Thanks for your help


Author:  tauro0221 [ Mon Apr 17, 2017 3:16 am ]
Post subject:  Re: Comparing string

The problem it is in the way you was checking the variables. You need to check it by bytes.
Attached it is a test routine so you can test it. It will check the variable byte by byte. Also I have to comments some lines so can be a able to test the routine. A good matched it is = 0 means no errors found . Try it to see if it works as looking for,

string var byte(4)
string = "test"

'**************************** added these variable for the subroutine**********
chk_error var byte(4)
chk_error = "test"
error_flag var byte
cnt_char var byte

'sethserial1 h38400', h8databits, hnoparity, h1stopbits

' hserin [str string\20\13]
' serout s_out,i9600,[str string\4\13,13]
gosub check_error ' check for error ----- error_flag = 0 no errors found
pause 1000
'serout s_out,i9600,[0,13]
goto main

'*************************** error subroutine *******************************

error_flag = 0

for cnt_char = 0 to 3
if string(cnt_char) <> chk_error(cnt_char) then
error_flag = 1

if error_flag = 1 then
serout s_out,i9600,["------ found errors --- ",dec error_flag,13]
serout s_out,i9600,["------ found no errors ",dec error_flag ,13]




Page 1 of 1 All times are UTC [ DST ]
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group