Teensy Serial port handshake? (USB)

I've been using serial (over the standard usb port) to communicate between the host PC and my teensy 3.2.

It's been fine so far, but I recently ran into a bug that stumped me for a bit.

I wanted to do something when the connection was established, so I used
Code:
if(Serial)
and then added the initialisation code I wanted. But it didn't seem to be called, (but my other stuff still worked, so serial communication was definitely working.

I tried reducing my program down to what basically amounts to hello world:
Code:
if(Serial) Serial.println("Hello!")
and still nothing. However, as soon as I connected the serial monitor in the arduino ide, my PC was flooded with messages of greeting from my teensy.

So I'm essentially wondering, what am I doing differently (or simply not doing) that the arduino ide serial monitor does?

On the PC side, I've got a console app written in C# using the serial port library (Windows). Essentially all I really do is open a connection on a port and start sending data, there are a whole bunch of properties listed there that I haven't used, including the "handshake" property.
 
Try

Code:
while(!Serial);

instead. Your code doesn't wait for the connection.

See the user wiki for more info and c# examples: https://github.com/TeensyUser/doc/wiki/Serial

That while loop doesn't change anything for me, it's just a different semantic approach. I've essentially worked around the problem for now, but I'd like to know what the problem is

My "hello world" code can essentially be boiled down to:

Code:
void loop()
{
    if(Serial)
    {
        Serial.println("Hello!");
    }
}

So once it's connected, it spams the serial connection over and over (but that's fine for my debugging purposes). Except, my program receives nothing from the serial port, but arduino does

Thanks for pointing me at that wiki though, didn't realise it existed, it's too well hidden
 
Last edited:
Try to add a
Code:
  p.DtrEnable = true;
after you open the port (p) in c#. IIRC the Teensy needs this to detect the port.
 
Back
Top