PDA

View Full Version : multiple serin/serout items



kenpo
- 27th April 2007, 17:15
Hey all, so I got serial running (dunno if you remember but thanks guys! I didn't need a crystal but I did need a max232...).

what my question now is, what's the best, or, easiest? way to send multiple items via serial?

eg, I want to send 3 sets of numbers from my pc to my pic, in this case, how many unread emails do I have in my inbox.
account1 has 3
account2 has 1
account3 has 0.

should I just send the number 1-3 (signifying account or set 1-3) then wait for a second set of numbers? this seems like it has the possibility for getting messed up along the way as I'll be sending the numbers 1,2,3 for the data. from what I understand if /else doesn't work with strings so I can't say if data_in = "a" then.. blah blah

sorry if this is a silly question, thanks guys!

skimask
- 27th April 2007, 17:20
from what I understand if /else doesn't work with strings so I can't say if data_in = "a" then.. blah blah

If data_in = "a" then xxxx....

is a valid statement in PBP, so long as 'data_in' is a declared variable and 'xxxx....' is also a valid PBP statement.

As far as sending the numbers, just send the ASCII equivlalent of the numbers, then send it's inverted form. 'AND' the two together, should come up with $FF. Quick and dirty form of doing a data check. Or send the number more than once in a packet. I.E. '11111' is valid data for 1, '22221' isn't valid data for anything. Something like that. Or make something up yourself and call it KEDP (kenpo's error detection protocol).

kenpo
- 27th April 2007, 17:33
ahhh, I must of been getting compiler errors for not declaring or soemthing then.

so i can declare a variable string,
then
SERIN2 0,396, [str din]
then say soemthing like
if din=a gosub a_loop
else (do nothing)....
endif
if din=b gosub b_loop....

etc?

that makes things much easier....

skimask
- 27th April 2007, 17:47
ahhh, I must of been getting compiler errors for not declaring or soemthing then.
so i can declare a variable string,
then
SERIN2 0,396, [str din]
then say soemthing like
if din=a gosub a_loop
else (do nothing)....
endif
if din=b gosub b_loop....
etc?
that makes things much easier....

Disconnect between us...
You're right... if/then doesn't work with strings, but it will work with individual byte characters which you can treat as a single character strings.

kenpo
- 27th April 2007, 17:54
not really sure what you mean, like single character byte as in 1 or 7? this would leave me in the sticky situation as I mentioned up top, not sure if I'm understanding you

skimask
- 27th April 2007, 20:37
not really sure what you mean, like single character byte as in 1 or 7? this would leave me in the sticky situation as I mentioned up top, not sure if I'm understanding you

Disconnect between us = didn't get what you wanted, gave you the wrong thing, whatever...

Now I'm not sure what you don't understand.
PBP doesn't work with strings. The serial commands, in general, will work with an array of a variable, not exactly the same thing as a string, but close. And yes, you can send multiple characters or a variable array, but they are treated as multiple, individual bytes, and not a string.

kenpo
- 27th April 2007, 20:47
ok, how would I send an array of a variable via hyperterminal? is it possble? I haven't used variable arrays in pbp before, only in other languages.

maybe the best question is: how would you do it?
if you wanted to have 3 sets of date sent, how would you send it, and make sure they don't get mixed up. ie, what if one set doesn't get sent, I don't want things getting out of synch after 1 month of contnuos usage... it would be cool to send it all at once as an array, but I'd have no idea how to do that via the windows end, so for now, I'm sticking to sending one at a time

skimask
- 27th April 2007, 21:41
ok, how would I send an array of a variable via hyperterminal? is it possble? I haven't used variable arrays in pbp before, only in other languages.

maybe the best question is: how would you do it?
if you wanted to have 3 sets of date sent, how would you send it, and make sure they don't get mixed up. ie, what if one set doesn't get sent, I don't want things getting out of synch after 1 month of contnuos usage... it would be cool to send it all at once as an array, but I'd have no idea how to do that via the windows end, so for now, I'm sticking to sending one at a time

How would I do it?
I would write a quick program in VB6 (others will say to use VC+, C#, whatever, I use VB6 'cause I know it well and it works for me, so whatever works for you) for the PC end of things to run the serial port, pick a byte sequence to be a leader (preferably 2 bytes that I would be reasonably sure wouldn't be used in the data payload), maybe add in a 'sequence' number to keep everything lined up, send the data, 1, 2, 3, then a checksum byte (or word, whatever), and maybe a trailer byte pair if needed.

At the PIC end, I would receive the data in a single SERIN statement into my variables, check the leader bytes are correct, check the 'sequence' number against the last one received, keep the data for the time being, do my error detection/checksum, check the trailer byte pair, then put the data where I needed it if all checks out ok.

Not very difficult stuff...usually. Sometimes you just gotta break it down into smaller chunks because the overall chunk almost looks daunting.
I'd just work on sending one or two bytes at a time, get used to sending stuff, maybe some error detection, etc...then work my way up to the big stuff.

kenpo
- 27th April 2007, 23:47
cool, thanks dude, that's what I had in mind then. except I was thinking either C or vb.net

for now acctually just php/mysql on the pc end connected to the serial port.