code problem

Can anyone tell me why this will not compile?

[code]ENABLEHSERIAL
sethserial h9600,h8databits,hnoparity,h1stopbits

elmout var long
elmin var long
dtc var long

pause 3000

main

hserin 500, expd, [elmout]

hserout ">AT Z",13]


	
if elmout= "ready" then
	hserout "req codes"]         
else 
goto main
	         
endif
	serout s_out, N9600, "got data ", elmout]  
   goto main

expd
goto main

endn
[/code]

I’m using IDE 8.0.1.11. I get an error:

(LINE 47) : [TOKEN “r”] : Expected THEN. It points to the line if elmout. I cant for the life of me figure out why.

Thanks for the help

Hi AngryOne,

I am not sure about how the basic compiler handles a string in cases like this. I do see some other things that may be issues.

One I believe that your hserin will only pass one byte of data to your variable elmout. You should look at the examples in the Atom Pro PDF under HSERIN. If you wish to accept strings, you should look at the STR io modifier.

The second issue I noticed is even if you could compare in a way similar to what you tried. The variable elmout is a long, which is only 4 bytes long and you are comparing this to a 5 byte string.

Kurt

Thanks Kurt, I feel kinda dumb mot putting a modifier in there and then declaring that variable as long. I’ll give the manual another looksey and keep you posted on what I come up with

Thanks a bunch for the help, I would have to change my S/N to crazyone if it wasnt for you

I found something weird (besides the fact they my code may not work). When the value in the if statement is larger than one character, it gives the error stated above

main

data_in var long
data_out var long
dtc var long     
    

ENABLEHSERIAL
    sethserial h9600,h8databits,hnoparity,h1stopbits

 





hserin 500, expd, [str data_in\5]


 if data_in = "" then   
           goto dtclabel             
       else
           goto resetlabel           
      endif


expd      
goto main

More info on what I’m trying to do.

I want to BAP to interface with the elm327 OBDII interpreter elmelectronics.com/thehome.html. My end goal being a handheld scan tool. The elm327 communicates over rs232, using just plain ASCII.

I’m currently trying to see if I can make the BAP talk to Docklight in a similar manner, I set up Doclight to respond to simple messages for ease of trouble shooting.

I’m beginning to fear that this project may be a little over my head due to my noobness. Any guidance is appreciated greatly

I just tried old code that would compile a similar IF statement. The old code will not compile.

Posting the code may be helpful if not just for a reality check. What do you mean specifically “will not compile” are there any errors?

[code]ENABLEHSERIAL
sethserial h9600,h8databits,hnoparity,h1stopbits

main

   id var long 
   lx var long  
   ly var long  
   rz var long  
   rr var long  
   btn var long 
   
  
  
    


   hserin 500, tmout, [id, hex2 lx\2, hex2 ly\2, hex2 rz\2, hex2 rr\2, hex4 btn\4]   

if BTN = “$0000” then
low p8

goto main 

tmout

   high p8               
   pause 100
   low p8
   pause 100
   high p8                 
   pause 100
   low p8
   pause 100
   goto main [/code]

“(LINE 20) : [TOKEN ] : Expected , or ]” Indicates the hserin line

[code];
;
;
;
;-=data requests=-
;01 -show current data
;02 -show freeze frame data
;03 -show dtc
;04 -clear codes and stored values
;07 -show pending codes
;
;-=parameter ID=-
;?
;?
;MAX232 WIRING YEL=P15 BLK=P14
;
;
main

data_in var long
data_out var long
dtc var long

ENABLEHSERIAL
sethserial h9600,h8databits,hnoparity,h1stopbits

hserin 500, expd, [str data_in]

if data_in(5) = “ready” then
goto dtclabel
else
goto resetlabel
endif

expd
goto main

resetlabel
hserout “>AT Z”,13]
goto main

dtclabel
hserout “gimme_codes”,13]
goto main[/code]

I V0.BAS(LINE 37) : [TOKEN ,] : Expected THEN. Indicating the IF line

The first problem I see if you can’t use a string of characters in an if then(or any other conditional). For example:

if temp = "1234" then ;do stuff endif

Is invalid code. You can only compare against single characters( eg “T”) or numbers. Period.

So you need to make a for next loop or something like it to compare a string to another string. But this is kind of high end so I’d like to know what exactly you are trying to do before I go into something that may just confuse you more.

Here however is a modification of your original program that may do what you want.

[code]ENABLEHSERIAL
sethserial h9600,h8databits,hnoparity,h1stopbits

main
hserout “>AT Z”,13]
hserin 500,main,[wait (“ready”)]
hserout “req codes”]
serout s_out, I9600, “got ready”]
pause 3000
goto main[/code]

I simplified it alot but this looks to be the basic jist you were going for. I assume you are talking to some kind of AT device. You send an >AT Z command and expect a reply of “ready”. If you don’t get it in half a second you retry. It’s been a long time(over 20 years) since I had to use the AT command set but I don’t remember having to send an “>” before AT but I think this will do what you want.

Thanks Acidtech, I guess I was doing the ol’ square peg in a round hole thing. Thanks for clearing up my error.

I want the atom to communicate with another chip via rs232. The elm is an OBDII to rs232 interpreter. The elm responds to ASCII strings like the following: >AT Z will reset the elm, >01 0c will make the elm request PID info from the vehicle ECM, parse it, and respond back with something like 41 0c 1a f8.

I need to send and receive these strings and parse them. I was trying to see if I could simulate the elm chip with Docklight and send strings back and forth. That is when things got retarded, sorry =) A sample for next loop would be awesome. I have other projects that would deal with more strings, so it would be very useful to me.

Hi again,

In you latest post. The first problem is probably the line:

if BTN = "$0000" then 

My guess here is that it should simply be

if BTN = $0000 then 

However compiling this, it looks like a compiler bug, which now that I think about it, I believe I have heard before. The compiler does not appear to allow the #min on the IO modifier in the hserin command. This may not be much of a problem if you are generating your own interface. If you always pass two hex digits it should work with just:
hex2 lx.

Probably should add this to the bug list.

In your second version, I am pretty sure your end program will not want to wait on a string. When I played with the STR input modifier before, I would do it more like:

data_in var byte(20)   ; allocate 20 bytes.
...
hserin 500, expd, [str data_in\20\13]

Note: did not try to compile this so don’t know if the \ will cause problems here as well in hserin. I used it before in serin. Also I had to clear the array before I did the serin into the array as the terminator is not passed into the array. IE if the first time through this loop you receive the command:“QP”, cr
the first element will be Q and the Second element witll be a P. Now if you loop back and the next input is the command “Q”, cr The first element will be the new “Q” and the second element will still be “P” as only one byte was transfered. I hope that makes sense.

If you can define your own interface, it is easier to use a fixed format, preferably with numbers instead of strings.

As Nathan (AcidTech) also mentioned you can not do a straight compare of strings. There are hacks you can do, for example if you read it into a long variable and the string you were looking for was “1234”, you could probably compare it to 0x31323334 (ie the hex value for the ascii strings), but this can be a pain.

In another program, where I was trying to have the BAP emulate the SSC-32. I instead put all of the input strings into a table and had a asembly language function scan it and return a command index number.
So there are several ways to approach this.

I hope this helps
Kurt

It totally does. I dont understand a lot of it, but it gives me dome direction, that’s half the problem