Testing whether strings are equivilant
robo_noob
Posts: 1
Hello all,
I am new to SPIN and micro controllers in general. Surprisingly I have been able poke and prod enough to get the a number of things working. One issue that I have not been able to figure out is testing equivilancy of strings. I am trying to send commands over a serial connection from a PC to verify whether my application is working correctly. I can receive a string and print it back out through the terminal.
Here is a snippet of my code. In it, I am storing the string in a long variable and am trying to evaluate it in a case statement. When I use numbers rather than character arrays this case statement works. Can someone explain to me what I am doing wrong? I am pretty sure I am missing some concept very important involving working with variables.
Thanks in advance!
I am new to SPIN and micro controllers in general. Surprisingly I have been able poke and prod enough to get the a number of things working. One issue that I have not been able to figure out is testing equivilancy of strings. I am trying to send commands over a serial connection from a PC to verify whether my application is working correctly. I can receive a string and print it back out through the terminal.
Here is a snippet of my code. In it, I am storing the string in a long variable and am trying to evaluate it in a case statement. When I use numbers rather than character arrays this case statement works. Can someone explain to me what I am doing wrong? I am pretty sure I am missing some concept very important involving working with variables.
Thanks in advance!
VAR long command OBJ comm : "SeriialDriver" ... PUB main comm.start( PIN_RX, PIN_TX, 0 & INVERT, BAUDRATE ) ... ... repeat comm.getstr(command) case command "showVersion" : comm.str(string("command recognized:")) ... other : comm.str(string("unknown command: ")) comm.str(command)
Comments
Use for instance 4 letter commands like "shwv" and be done.
A "string" is a pointer to a piece of memory you have to allocate in advance, terminated by a zero.byte (=C-convention)
Comparing such pieces of memory needs hand made loops, CASE works with 32 bit values only.
BTW: I do not know your "SeriialDriver"; and 0&INVERT also looks funny (or is that a "disabled INVERT" )...
You'll need to post your entire code (including this illusive "SeriialDriver"). From what I can see, you are calling the getstr() method incorrectly (generally functions that return a string will require a pointer to an array of bytes to be provided as an argument).
In your case, you would likely need to do: