Home AMX User Forum NetLinx Studio

find_string in buffer error

I was doing some rs-232 control programming and encounter strange error.

(0000082130) SC: $11$13 xx
(0000082130) SC: $11$13 xx
(0000082131) !!!Uwaga!!!: Przepelniono Buffer nr: 1
(0000082131) CIpLibrary::Find_String - Error 2
(0000082193) SC: $11$13 xx
(0000082194) CIpLibrary::Find_String - Error 2
(0000082194) CIpLibrary::Find_String - Error 2
(0000082194) CIpLibrary::Find_String - Error 2
(0000082194) CIpLibrary::Find_String - Error 2
(...)

SC i data.text from rs-port device, witch is send constantly and being added to buffer. I haven't wrote any logic to trow it away (it was unsuspected at the time) so theres no mystery there.
When i've tried to localize my error i've added some code, and to my surprise error is still threre.

Here's my code.


lenbSC=length_string(bSC);

if (lenbSC>=(max_length_array(bSC)-10)){
errorBufEx++;
send_string 0,"'!!!Uwaga!!!: Przepelniono Buffer nr: ',itoa(errorBufEx)";
clear_buffer bSC;
}

if (lenbSC){
stack_var integer f;
//stack_var char srch;
//srch = $55;
//find_string(bSC,srch,1)

f=find_string(bSC,srch,1); //byte snchronizacji;

if (f)){
stack_var integer k;
stack_var integer count;

send_string 0,"'znaleziono: ',itoa(f)";


count=bSC[f+1]; //domniemana długość stringu

if (lenbSC>=(f+count)){ //sprawdzanie czy stroing jest cały w buferze
sum=0;
for (k=f+1;k<f+count-1;k++){ //liczenie prostej sumy
SEND_STRING 0,"'liczona litera'";
sum=sum+bSC[k];
}
SEND_STRING 0,"'suma w dec: ',itoa(sum)";
SEND_STRING 0,"'suma w dec: ',itoa(bSC[(f+co .....

where :
bSC is buffer
error is genereted by:
f=find_string(bSC,srch,1); //byte snchronizacji;
in loop matter as soon as buffer overflows even when i:
clear_buffer bSC;

I know how to deal with my problem with protocol, I just don't get it why it is happening in this situation (and mainly why it won't stop as soon as I clear my buffer). I'm afraid it will happen again I i won't know haw to deal witch it then.
If anyone have solution please help me.

mr

Comments

  • AMXJeffAMXJeff Posts: 450
    mpmiszczyk wrote: »


    stack_var integer f;
    //stack_var char srch;
    //srch = $55;
    //find_string(bSC,srch,1)

    f=find_string(bSC,srch,1); //byte snchronizacji;

    where :
    bSC is buffer
    error is genereted by:
    f=find_string(bSC,srch,1); //byte snchronizacji;
    in loop matter as soon as buffer overflows even when i:
    clear_buffer bSC;

    mr

    The second parameter should be a character array, not just a character. Adding double quotes around it should fix this issue, else make the srch variable a char array.

    find_string(bSC,"srch",1)
  • f=find_string(bSC,"$55",1);
    worke just fine.

    thanks
  • Where can I find descriptions of what these error codes mean, besides these forums? "Error 2" is not helpful. IMHO this should be a compile-time error anyway.
Sign In or Register to comment.