multiple serin/serout items


Closed Thread
Results 1 to 9 of 9
  1. #1
    Join Date
    Feb 2005
    Location
    Toronto, Canada
    Posts
    46

    Default multiple serin/serout items

    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!

  2. #2
    skimask's Avatar
    skimask Guest


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by kenpo View Post
    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).

  3. #3
    Join Date
    Feb 2005
    Location
    Toronto, Canada
    Posts
    46


    Did you find this post helpful? Yes | No

    Default

    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....

  4. #4
    skimask's Avatar
    skimask Guest


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by kenpo View Post
    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.

  5. #5
    Join Date
    Feb 2005
    Location
    Toronto, Canada
    Posts
    46


    Did you find this post helpful? Yes | No

    Default

    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
    Last edited by kenpo; - 27th April 2007 at 20:05.

  6. #6
    skimask's Avatar
    skimask Guest


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by kenpo View Post
    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.

  7. #7
    Join Date
    Feb 2005
    Location
    Toronto, Canada
    Posts
    46


    Did you find this post helpful? Yes | No

    Default

    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

  8. #8
    skimask's Avatar
    skimask Guest


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by kenpo View Post
    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.

  9. #9
    Join Date
    Feb 2005
    Location
    Toronto, Canada
    Posts
    46


    Did you find this post helpful? Yes | No

    Default

    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.

Similar Threads

  1. Multiple PICS from Same Crystal?
    By WOZZY-2010 in forum General
    Replies: 2
    Last Post: - 6th February 2010, 15:18
  2. Multiple PIC programming
    By Nicholas in forum mel PIC BASIC Pro
    Replies: 0
    Last Post: - 7th May 2007, 23:47
  3. Multiple PIC's with 1 crystal
    By puma in forum Schematics
    Replies: 11
    Last Post: - 20th March 2007, 17:02
  4. Multiple Pics to One serial port
    By Rleonard in forum Serial
    Replies: 1
    Last Post: - 18th January 2007, 18:30
  5. Using Multiple EEPROMs
    By Tom Gonser in forum mel PIC BASIC Pro
    Replies: 5
    Last Post: - 27th March 2005, 07:37

Members who have read this thread : 1

You do not have permission to view the list of names.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts