string search in struct buffer

Tip / Sign in to post questions, reply, level up, and achieve exciting badges. Know more

cross mob
DaHu_285096
Level 5
Level 5
10 likes received 250 replies posted 100 replies posted

 Does the compiler mind doing a string search on a buffer in struct. like this...

   

COM.Buf[LastByte] = '\0';

   

if(strstr(COM.Buf,"OK")

   

{

   

  //got it

   

}

   

This appeared to working initially when I had debugger attached to target, when I programmed the target and ran on its own, the code program did not perform the same as when debugging.

   

I then connected to debugger again and re-ran.When I stepped through this code, I noted the COM.Buf contained CR LF OK CR LF but the loop failed to find the string.

   

I also tried below code and it appeared to work but when I programmed device, the code did not perform the same.

   

COM.Buf[LastByte] = '\0';

   

sprinft(tempsrtr,COM.Buf)

   

if(strstr(temstr,"OK")

   

{

   

  //got it

   

}

   

What I mean by "did not perform the same" is that the fisrt part of initiation for the GSM modem simply issues and AT command to check modem responds with "OK", before sending setup parameters to it.

   

I have a seried of LEDs that show progress, AT OK, SIM OK, Network OK etc.

   

When I program the target and run on its own, It never indicates AT is OK. I have been running on debugger for several days developing the code and it appeared to get the AT OK response every single time.

0 Likes
5 Replies
Bob_Marlowe
Level 10
Level 10
First like given 50 questions asked 10 questions asked

Can you post your complete project? This issue will be outside of your provided code-snippet.

   

 

   

Bob

0 Likes
HeLi_263931
Level 8
Level 8
100 solutions authored 50 solutions authored 25 solutions authored

Did it only work when stepping through the code? Or was the difference whether the debugger was attached or not? Did you run the same code (compiled in debug mode) both times?

0 Likes
DaHu_285096
Level 5
Level 5
10 likes received 250 replies posted 100 replies posted

 I cannot step through the code properly due to inteerupt timer going off.

   

What I did was set break point before sending command to modem and then another at the point where successful response should have occurred.

0 Likes
DaHu_285096
Level 5
Level 5
10 likes received 250 replies posted 100 replies posted

 The program works fine if I program the target and run it with miniprog connected.

0 Likes
Anonymous
Not applicable

 How about change your timer to a longer tiem to see if that helps

   

Also, try to set some delay between sussesive commands, give more time for message to return and decode.

   

We use a Vreg from the programmer to stop a external WD, do you use the Vreg for anything? also was there any external circuit that would affect XRES? 

   

If the reply is only "OK" and is the first 2 bytes, I think it would return 0, would this be a problem?

0 Likes