BasicMicroUK - Forums

www.basicmicro.co.uk
It is currently Mon Dec 18, 2017 2:02 am

All times are UTC [ DST ]




Post new topic Reply to topic  [ 2 posts ] 
Author Message
 Post subject: Comparing string
PostPosted: Mon Apr 10, 2017 9:11 am 
Offline
Guru

Joined: Mon Dec 21, 2009 6:52 am
Posts: 92
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


Top
 Profile  
 
 Post subject: Re: Comparing string
PostPosted: Mon Apr 17, 2017 3:16 am 
Offline
Master

Joined: Wed Oct 19, 2011 2:28 am
Posts: 123
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

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


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 2 posts ] 

All times are UTC [ DST ]


Who is online

Users browsing this forum: No registered users and 0 guests


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

Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group

phpBB SEO