BasicMicroUK - Forums
http://forums.basicmicro.co.uk/

Comparing string
http://forums.basicmicro.co.uk/atomnano-f485/comparing-string-t10534.html
Page 1 of 1

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

Hi,

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 :
Code:
string var byte(4)
enableserial1
sethserial1 h38400', h8databits, hnoparity, h1stopbits
main:
   hserin [str string\20\13]
   serout s_out,i9600,[str string\4\13,13]
   IF STRING="TEST" THEN
   ENDIF
   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

Chris

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

Hi,
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
'*****************************************************************************

'enableserial1
'sethserial1 h38400', h8databits, hnoparity, h1stopbits
main:

' 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 *******************************
check_error

error_flag = 0

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

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

endif

return

'****************

Page 1 of 1 All times are UTC [ DST ]
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
http://www.phpbb.com/