Shop OBEX P1 Docs P2 Docs Learn Events
In-code COM port selection and change — Parallax Forums

In-code COM port selection and change

LenaLena Posts: 2
edited 2009-12-07 20:07 in Robotics
Hi all,

I am trying to figure out a way to change the selected COM port I am using for communicating with my Boe Bots within the code itself and not through the window selection in the BasicStamp app. I am pretty confused on where to start... The basic idea is that I want to control a number of devices simultaneously, without interacting with BasicStamp after loading the code on.

Thanks for your help!

Lena

Comments

  • SRLMSRLM Posts: 5,045
    edited 2009-12-01 20:44
    The short answer is that you can't do it directly. Basically, the only thing that can change the COM port assignment is the computer itself. With windows, you have to go to the com port under devices and change it there. You could probably write a computer program (if you have the skill) to do this automatically based on serial data received over a com port but it is certain to be complex.

    Note that you can open several com ports at once to different terminals. I think the BS editor allows for 5. You could also use some other terminal program such as Parallax Serial Terminal.
  • LenaLena Posts: 2
    edited 2009-12-02 18:02
    Thanks! I'll see what else I can do...

    Lena
  • allanlane5allanlane5 Posts: 3,815
    edited 2009-12-02 20:06
    I thought on the PC you simply opened a port, and called it "COM1", "COM2", etc.

    I once wrote a simulation program that used multiple COM ports, and was able to open multiple ports. The actual port the BS2 is connected to can't be changed on-the-fly, but you can certainly open multiple ports to multiple BS2's.
  • ZootZoot Posts: 2,227
    edited 2009-12-07 20:07
    If your goal is to let the PC figure out which Stamp (bot) is on which port, it would seem a small app or script on your PC could query each port in turn (serial) and see what replies it gets back (if any) then make some determinations from there.

    On the Stamp side, nearly identical code on each Stamp would let it send an ID back to the PC, e.g.:

    
    tmp VAR Byte
    
    MyID CON 1 ' or 2 or 3 or $FF or whatever you like as long as they are unique on each Stamp
    
    tmp = 0
    DO WHILE tmp = 0
    tryAgain:
      SEROUT 16, Baud, [noparse][[/noparse] MyID ] ' send ID to PC and keep trying till you get a reply from the PC app indicating that it has recieved the ID on this com port
      SERIN 16, Baud, 1000, tryAgain [noparse][[/noparse] tmp ]  ' so perhaps the PC sends $FF in response to receiving an ID on a com port, and if serin times out, keep trying
    LOOP
    
    Main:
    
    ' the rest of the program
    
    



    On the PC side, in pseudo code (but not showing logic for checking for timeout on serialRead):

    
    Open PORT 1
    serialRead( someVar )
    port1id = someVar
    serialWrite ( $FF )
    
    Open PORT 2
    serialRead( someVar )
    port2id = someVar
    serialWrite ( $FF )
    
    ' etc
    
    
    

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    When the going gets weird, the weird turn pro. -- HST

    1uffakind.com/robots/povBitMapBuilder.php
    1uffakind.com/robots/resistorLadder.php
Sign In or Register to comment.