PDA

View Full Version : Problem: SERIN2 and long arrays...



pedja089
- 11th November 2011, 18:38
Several times I have problem that first few bytes can not has been received in array.
This problem occurs only if I have a large number of long arrays...
For example


Some vars...
Mail_User var byte[36]
Mail_123 var byte[36]
Mail_Pass var byte[36]
etc
And serin2 look like this

serin2 PC_RX,8588,1000,PC_Data_Mail,[wait("Mail:"), str Mail_Alrm\5, str MailServer\20, str Mail_port\6, str Mail_User\35, str Mail_Pass\35,_
str Mail_Adr\30, str Mail_Subj\20, str Mail_Msg\50, str Mail_FileName\20, Mail_Name_Tip,_
str Mail_RCPT1\35, str Mail_RCPT2\35, str Mail_RCPT3\35 ]


And in this case first 5 charter of str Mail_Pass\35 is zero if i didn't add Mail_123 var byte[36] .
But if I add Mail_123 var byte[36], or any array longer than number of bytes that didn't received everything work fine...
This is compiled with PBP2.60C, I didn't try to compile with PBP3...
I assume that first few byte and rest of array isn't in same bank or something like that...

pedja089
- 12th November 2011, 13:10
Same thing with PBP 3...
I'm not sure what difference it make if I add another array, or change order when defining variables...

mackrackit
- 12th November 2011, 13:44
What MCU are you using? Maybe you are running low on memory?

pedja089
- 12th November 2011, 13:53
PIC18F255, this issue i also had on PIC18LF1xK50.
It's not low on memory, because if I add some dummy var everything works fine.
Now I'm testing and if I tray this

Some vars...
Mail_Pass var byte[36]
Mail_User var byte[36]
etc
And problem move to Mail_User.
Now I'll try to put serin2...[mail_pass[0],mail_pass[1],...mail_pass[34]], instant of str mail_pass...

pedja089
- 12th November 2011, 14:27
Now I try this

...
Mail_User var byte[36]
Mail_Pass var byte[36]
....
serin2 PC_RX,8588,1000,PC_Data_Mail,[wait("Mail:"), str dat\5, str MailServer\20, str Mail_port\6, str Mail_User\35,_
Mail_Pass[0],Mail_Pass[1],Mail_Pass[2],Mail_Pass[3],Mail_Pass[4],Mail_Pass[5],_
Mail_Pass[6],Mail_Pass[7],Mail_Pass[8],Mail_Pass[9],Mail_Pass[10],Mail_Pass[11],_
Mail_Pass[12],Mail_Pass[13],Mail_Pass[14],Mail_Pass[15],Mail_Pass[16],Mail_Pass[17],_
Mail_Pass[18],Mail_Pass[19],Mail_Pass[20],Mail_Pass[21],Mail_Pass[22],Mail_Pass[23],_
Mail_Pass[24],Mail_Pass[25],Mail_Pass[26],Mail_Pass[27],Mail_Pass[28],Mail_Pass[29],_
Mail_Pass[30],Mail_Pass[31],Mail_Pass[32],Mail_Pass[33],Mail_Pass[34],_
str Mail_Adr\30, str Mail_Subj\20, str Mail_Msg\50, str Mail_FileName\20, Mail_Name_Tip,_
str Mail_RCPT1\35, str Mail_RCPT2\35, str Mail_RCPT3\35 ]
And this also won't work... I'm shure that problem is in serin2 because i try If mail_pass[0]=0 then HSEROUT["empty",13,10] and without adding additional array I always got empty.
But If i try to put something in array eg mail_pass[0]="a", it;s ok.
For now I can add just some arrays, but I want to know what causing this problem...
And it's not first time to bump into this...

HenrikOlsson
- 12th November 2011, 14:57
Hi,
It sounds to me like one array is "spilling over" into the next. PBP doesn't have perform boundry checking on arrays so you can easily write outside it of its "space". When you add your dummy array the data from operation A spills over into the dummy array instead of into the "real" array where you see the zeros.

That'a a theory....

/Henrik.

pedja089
- 12th November 2011, 15:11
I send fixed len. strings from vb, and it doesn't matter where I put dummy variable. I try to to add dummy after mail_pass, and again everything it's ok. So now I don't have clue what it is happening...
I have 661 byte 2 words and 4bits before Mail_user.
And if I swap place of Mail_Pass and any array, _pass is ok, and that replaced array isn't ok...

HenrikOlsson
- 12th November 2011, 15:14
Hi,
Preload your dummy array with all 255's or whatever, then after your SERIN statement, dump the content of the dummy array and see if IT now has your zeros. Then you KNOW that something is writing outside of where it should.

/Henrik.

pedja089
- 12th November 2011, 15:52
Add this before serin2
for i = 0 to 34
MAil_123[i]="A"
next i
hserout [str mail_123,13,10]
and after serin2
hserout [str mail_123,13,10]
From first HSEROUT got AAA... then CrLf, second Hserout got just CrLf...
I try to move Mail_123 var byte[36], and that array is always cleared...

HenrikOlsson
- 12th November 2011, 16:26
Hi,
Are you SURE you're sending the correct length strings from your VB program? Have you verified that?
Have you tried breaking it up in several SERIN statements?

I still think something is either writing outside of "its space" or not getting enough bytes so the next input "spans" two arrays or something...

/Henrik.

pedja089
- 12th November 2011, 16:31
I'm 100% sure that i send correct length... I check this several time's.
Now I'll try.

pedja089
- 12th November 2011, 16:42
serin2 PC_RX,8588,1000,PC_Data_Mail,[wait("Mail:"), str Mail_Alrm\5]
serin2 PC_RX,8588,1000,PC_Data_Mail,[str MailServer\20]
serin2 PC_RX,8588,1000,PC_Data_Mail,[str Mail_port\6]
serin2 PC_RX,8588,1000,PC_Data_Mail,[str Mail_User\35]
serin2 PC_RX,8588,1000,PC_Data_Mail,[str Mail_Pass\35]
serin2 PC_RX,8588,1000,PC_Data_Mail,[str Mail_Adr\30]
serin2 PC_RX,8588,1000,PC_Data_Mail,[str Mail_Subj\20]
serin2 PC_RX,8588,1000,PC_Data_Mail,[str Mail_Msg\50]
serin2 PC_RX,8588,1000,PC_Data_Mail,[str Mail_FileName\20]
serin2 PC_RX,8588,1000,PC_Data_Mail,[Mail_Name_Tip]
serin2 PC_RX,8588,1000,PC_Data_Mail,[str Mail_RCPT1\35]
serin2 PC_RX,8588,1000,PC_Data_Mail,[str Mail_RCPT2\35]
serin2 PC_RX,8588,1000,PC_Data_Mail,[str Mail_RCPT3\35]

I try to use Mail_pass in another serin2 statement, and same problem. I try to put another var, before and after in serin2 statement and same...
It won't to work without dummy var...

HenrikOlsson
- 12th November 2011, 16:50
And you have all your arrays declared properly, ie Arrayname VAR BYTE[Lenght] ?
I once forgot the [] around the length and it led to quite a bit of headache untill I posted the code here and someone spotted it right away.

/Henrik.

pedja089
- 12th November 2011, 16:53
I'll just leave dummy array, and continue...
Thank anyway.

HenrikOlsson
- 13th November 2011, 07:26
OK, I can understand that but I have a feeling that doing so will come back and bite you you sooner or later.

amgen
- 13th November 2011, 12:25
since you have 1 long array and you know where the smaller arrays are in the longer array,

serin2 PC_RX,8588,1000,PC_Data_Mail,[wait("Mail:") ]
........RCVint on....... 'turn on rcv interrupt to take your 200 (more or less) chars into your array
continue............................
.
.
.
RCVint:
place rcv chr to array[x]
char count +1
char indx +1...[x]
turn off when count = chars to rcv

Don

pedja089
- 14th November 2011, 00:48
Problem (probably) solved.
I needed bigger array for RCPT mails. And when I change size of those array from 36 to 45 bytes, I remove dummy array and it work without it :)
Then I just change in serin2 to receive 45 bytes and everything work well.
I always leave 1 byte longer array, and set last byte to 0...
I'm not sure what last 3 array have with pass array...