Shop OBEX P1 Docs P2 Docs Learn Events
Parallax Serial Terminal - Are you connected? — Parallax Forums

Parallax Serial Terminal - Are you connected?

MJHanaganMJHanagan Posts: 189
edited 2013-09-24 04:39 in Propeller 1
I am trying to find a way to test if my Propeller is connected to a computer, and if connected is the computer running the Parallax Serial Terminal program (and in the enabled state). Essentially I want the Propeller to figure out if it should keep using the PST object or skip it because the computer isn't connected or listening.

My Propeller program stops running if the Parallax Serial Terminal isn't enabled on the computer. My guess is the PST's Tx buffer gets full so it sits in a waiting mode until empties. I don't see a TxCheck routine where I could send a small text string then query the Tx buffer to see if the characters went out and were received by the computer screen.

Any suggestions on a way to do a quick check of the PST's connection status?

Comments

  • Phil Pilgrim (PhiPi)Phil Pilgrim (PhiPi) Posts: 23,514
    edited 2013-09-22 17:30
    I can't think of any mechanism by which the PST object would not continue to transmit data, even in the absence of a conneciton, since it does not use handshaking. So the buffer should never stop emptying. So it's a mystery why your program would stop running wihtout a PC connection.

    Are you sure your Prop is powered during this time? IOW, if it's receiving power via USB and there's no connection, it may not be receiving power.

    -Phil
  • Ron CzapalaRon Czapala Posts: 2,418
    edited 2013-09-22 17:57
    I use code like this to determine if the USB cable is connected to the computer. It does not know if PST is enabled.

    I preface all of my PST statements with "if debugsw == true"
    Var
      long debugsw        ' control output to Parallax Terminal   
    
    OBJ
       Debug   : "FullDuplexSerial"
    
    Pub Main 
      debugsw := false
      if ina[31] == 1                              ' RX (pin 31) is high if USB is connected
        Debug.start(31, 30, 0, 57600)      ' ignore tx echo on rx
        waitcnt(clkfreq * 4 + cnt)             ' Pause for FullDuplexSerial.spin to initialize
        debugsw := true                         ' Debug serial connection is active
      else
        outa[30] := 0                      ' Force Propeller Tx line LOW if USB not connected
    
      if debugsw == true
        Debug.str(string(16,"USB connected",13))  
    
    
  • StefanL38StefanL38 Posts: 2,292
    edited 2013-09-22 18:04
    it would be a great help if you would post or attach your code to a posting.

    best regards
    Stefan
  • MJHanaganMJHanagan Posts: 189
    edited 2013-09-22 18:18
    You are correct! I just found the bug causing the program to hang up after a period of working.

    I am still interested in figuring out if the computer is connected and the serial terminal program is running and enabled. I could gain another much needed cog if I'm not actively running the serial terminal debug routines.
  • MJHanaganMJHanagan Posts: 189
    edited 2013-09-22 18:23
    I use code like this to determine if the USB cable is connected to the computer. It does not know if PST is enabled.

    I preface all of my PST statements with "if debugsw == true"
    Var
      long debugsw        ' control output to Parallax Terminal   
    
    OBJ
       Debug   : "FullDuplexSerial"
    
    Pub Main 
      debugsw := false
      if ina[31] == 1                              ' RX (pin 31) is high if USB is connected
        Debug.start(31, 30, 0, 57600)      ' ignore tx echo on rx
        waitcnt(clkfreq * 4 + cnt)             ' Pause for FullDuplexSerial.spin to initialize
        debugsw := true                         ' Debug serial connection is active
      else
        outa[30] := 0                      ' Force Propeller Tx line LOW if USB not connected
    
      if debugsw == true
        Debug.str(string(16,"USB connected",13))  
    
    

    Nice, that at least tells me if the USB cable is connected so I'm halfway there.

    Any ideas on figuring out if the Parallax Serial Terminal program is enabled?
  • Ron CzapalaRon Czapala Posts: 2,418
    edited 2013-09-22 18:33
    MJHanagan wrote: »
    Nice, that at least tells me if the USB cable is connected so I'm halfway there.

    Any ideas on figuring out if the Parallax Serial Terminal program is enabled?

    Don't think that's feasible. PST opens a comm port and waits for data to arrive (or for you to send data). Don't see any way the propeller can determine what the PC is doing at the other end.
  • StefanL38StefanL38 Posts: 2,292
    edited 2013-09-24 02:29
    high MJ,

    I want to re-open the minds:

    What do you want to do in the end? If you really need the last cog - How would you do some more serial debbuging if all cogs are engaged?

    Give us an overview over your project. I guess there are other possabilities to save a cog.
    What kind of debug-info do you need? Lot's of variable values or just "my program runs now method xy?"
    Second could be made visible by 2 or 3 LEDs lighting them up in different combinations.

    as stated above PST opens the comport and that's it.
    If you would code a serial terminal on your own this prg could send a "hello is there a prop answering?" bytesequence so the prop has something to receive.
    Of course you can do that by hand through typing in PST.

    I'm not sure if this works: you could check the logic level of the IO-PINs before the serial object is started. Maybe there is a reproducable logic level on Rx Tx with PST closed
    and another combination of low-high on Rx/Tx when PST opened the comport.

    best regards
    Stefan
  • max72max72 Posts: 1,155
    edited 2013-09-24 04:39
    As an alternative, in case you have another serial port in use you could switch to the 4 serial ports in a COG object. Otherwise there is no saving.
    Massimo
Sign In or Register to comment.