Shop OBEX P1 Docs P2 Docs Learn Events
Serial in, Serial out — Parallax Forums

Serial in, Serial out

knightofoldcodeknightofoldcode Posts: 233
edited 2005-08-05 21:14 in BASIC Stamp
Board,

I'm trying to understand how this could happen. I'd like to have several pins of a BS2, set to serial input/output. A few of them will have flow control pins, others wont (such as a RFID reader). I'd like to just do some simple restransmitting of the serial info.

For example. I'd like to have a pair of main serial pins that sends and recieves serial to a computer. I'd like to have a keypad encoder, and a RFID reader. Both of these will be serial, but without handshaking. So, I know that I'll need to have the BS2 watch the RFID, and keypads the most, briefly checking the serial line, I can do all of the hardware aspect of this project no problems.

Software is where I'm having an issue. I'm a Visual Basic guy, and know exactly how to do this in VB. But in pBasic is harder. [noparse]:)[/noparse] Just a new language, and not as..... friendly?... Anyways. How would I setup the BS2 to send the RFID input to the RS-232 line?


RFID on pin 15 (I'm leaving out the "enable" in this example, I understand completly about it, and how to use it/implement it, just making this example simple. [noparse]:)[/noparse]
Keypad pin 14
rs-232 on pin 0

I'm not looking for a step by step program, just where to go. The entire reason I'm having an issue is the variable length strings. How do you handle a variable length string? The keypad might have, "1234a" (The "a" is the ascii code for the enter key on the keypad), and the RFID have "0f025d2d5b[noparse][[/noparse]CR]". How would you got about sending this to the main computer?

MUCH TIA,
Knight.

Comments

  • Bruce BatesBruce Bates Posts: 3,045
    edited 2005-08-05 09:58
    Knight -

    The input/output aspect you may be missing, until you take a look at the PBASIC Stamp Manual (hint, hint), is that there is no particular restriction on use of the 16 general pin ports (pin ports 0 - 15). Said differently, you can use any pin port for input or output, and any pin port can support RS-232 communication through the use of SERIN/SEROUT. Depending on the connected device, you may or may not need to use an RS-232 driver chip (ex. MAX-232). Pin port 16 (the programming and DEBUG port) is already set up to operate at appropriate RS-232 levels, but there are some idiosyncracies in using it.

    Insofar as the outputting of an array is concerned, that 's just a matter of sending the data out as individual bytes, but in one SEROUT command (presuing that's your aim). See the example below, without regard to proper PBASIC syntax:

    SEROUT PinPort, baudmode, [noparse][[/noparse]array(1), array(2), arrry(3) ... etc]

    The alternative to that above, is to output one byte at a time, until the entire string is
    output:

    For I = 1 to TotalLength
    SEROUT PinPort, baudmode, [noparse][[/noparse]array(I)]
    Next
    ' Send EOD if necessary
    SEROUT PinPort, baudmode, [noparse][[/noparse]$FF] ' hex FF is arbitrary in this example

    You can also get tricky, stuff an unused or null character as a trailing delimiter within the arrray, and pump the string out using DO ... WHILE or DO ... UNTIL using the special character as the DO termination value.

    As regards flow control, that's just a matter of using (usually) another pin adjacent to the data pin for such flow control, again as indicated in the PBASIC Stamp Manual. There is no specific requirement to use an adjacent pin, it's just a bit easier from a logic and common sense point of view to do so.

    Regards,

    Bruce Bates
  • allanlane5allanlane5 Posts: 3,815
    edited 2005-08-05 13:56
    You must also understand that the BS2 is a single-tasking processor. Thus if you are 'listening' in a SERIN statement on pin 1, you will miss any message that comes in pin 2.
  • knightofoldcodeknightofoldcode Posts: 233
    edited 2005-08-05 21:14
    Bruce Bates said...
    Knight -

    The input/output aspect you may be missing, until you take a look at the PBASIC Stamp Manual (hint, hint), is that there is no particular restriction on use of the 16 general pin ports (pin ports 0 - 15). Said differently, you can use any pin port for input or output, and any pin port can support RS-232 communication through the use of SERIN/SEROUT. Depending on the connected device, you may or may not need to use an RS-232 driver chip (ex. MAX-232). Pin port 16 (the programming and DEBUG port) is already set up to operate at appropriate RS-232 levels, but there are some idiosyncracies in using it.

    Insofar as the outputting of an array is concerned, that 's just a matter of sending the data out as individual bytes, but in one SEROUT command (presuing that's your aim). See the example below, without regard to proper PBASIC syntax:

    SEROUT PinPort, baudmode, [noparse][[/noparse]array(1), array(2), arrry(3) ... etc]

    The alternative to that above, is to output one byte at a time, until the entire string is
    output:

    For I = 1 to TotalLength
    SEROUT PinPort, baudmode, [noparse][[/noparse]array(I)]
    Next
    ' Send EOD if necessary
    SEROUT PinPort, baudmode, [noparse][[/noparse]$FF] ' hex FF is arbitrary in this example

    You can also get tricky, stuff an unused or null character as a trailing delimiter within the arrray, and pump the string out using DO ... WHILE or DO ... UNTIL using the special character as the DO termination value.

    As regards flow control, that's just a matter of using (usually) another pin adjacent to the data pin for such flow control, again as indicated in the PBASIC Stamp Manual. There is no specific requirement to use an adjacent pin, it's just a bit easier from a logic and common sense point of view to do so.

    Regards,

    Bruce Bates

    I don't think I've explained what I'm looking for well enough. [noparse]:)[/noparse]

    I've looked at the pBasic manual. And as I stated in my message, I know how to do the hardware aspect. I understand and know that any pin could be used as serial TTL levels, and a level shift IC would be required for true RS-232 if not using pin 16 (pin number for the rs-232 port built into the BS2). I know and understand all of these things. I know and understand flow control. What I don't know is the software aspect, as stated in my message. [noparse]:)[/noparse]
    allanlane5 said...
    You must also understand that the BS2 is a single-tasking processor. Thus if you are 'listening' in a SERIN statement on pin 1, you will miss any message that comes in pin 2.
    Yes, I understand this. There shouldn't be any case where the keypad and RFID are being used within 5 seconds of each other. I can't see that happening, especially since it's either the keypad or the RFID, not, RFID then keypad.

    Bruce Bates said...
    SEROUT PinPort, baudmode, [noparse][[/noparse]array(1), array(2), arrry(3) ... etc]

    So, I need to look into using array's to send a variable length string to another pin. [noparse]:)[/noparse] That's what I was looking for. [noparse]:)[/noparse] I'll look into it, and post any problems I might have, since I know I will. [noparse]:)[/noparse]

    TIA,
    Knight.

    Post Edited (knightofoldcode) : 8/5/2005 9:56:58 PM GMT
Sign In or Register to comment.