Serial port question

Has someone had this problem before?
Simple Arduino program. It just throws out the value of 20 to the serial port until something comes back.

int i = 0;
void setup()
{
Serial.begin(19200);
pollForHost();
}
void loop()
{
if(Serial.available() > 0)
{

Serial.write(i);
i +=1;
}
}

void pollForHost()
{
while (Serial.available()==0)
{
Serial.print(20,DEC);
}
}

The host program i have works great with it until i cycle the power on the arduino. Then there is NO serialport activity.
The host program has a data recieved event that fires when it sees something on the serial port.
Upl arduino program-> works great
Power off then on again-> no serialport activity.
Am i missing something?

hey!

can u c if the TX LED is flashing?

maybe the host sends data during the arduino-reset, so that the arduino goes into flash-programming-mode?

bye

As you power off the arduino the USB serial port is effectively switched off. Therefore the host program looses it's serial port. To get it back it has to initialise it again. Which I suspect it isn't doing.

So you host program needs to be informed when a port disappears and then will have to go into a loop until it sees it again and then re initialise it.

Turning on and off the Arduino's serial monitor in effect does this and throws in a reset as well.

Thanks for responding.
I can shut down the arduino and the computer with the host program for 2 min or for a day and i get the same results-no serial response until i upload again.
Is there a command to tell the serial port to start responding again?

It just throws out the value of 20 to the serial port until something comes back

What do you mean by "the value of 20"? Does it matter to your host program that it is receiving 0x32, 0x30 and not 0x14?

Could you post the portion of your host program that is communicating with the Arduino?

Below is an event in C#
which never gets called after intital arduino power up.
Unless i upl the Arduino program again.

It dosen't matter if I keep sending bytes via C# and listen on the serial port because there is no response back.
Has anyone tried this after a power cycle?

private void port_DataReceived(object sender, SerialDataReceivedEventArgs e)
{
intBuffer = port.BytesToRead;
byte[] byteBuffer = new byte[byteBuffer];
port.Read(byteBuffer, 0, intBuffer);

}

i get the same results-no serial response until i upload again

Try down loading the blinking LED sketch. See the LED blink and then unplug it. Now connect it up again and see the LED blink again. This proves that the arduino is retaining the program sent to it.

I can shut down the arduino and the computer with the host program

Now load in your original program into the arduino. Shut down your computer.
Power up your computer, let it boot. Plug in the arduino board THEN run your C# program. It will work.

maybe the host sends data during the arduino-reset, so that the arduino goes into flash-programming-mode?

Could be close to the reason.

I have the Arduino sending bytes out the serial port constantly.
After i unplug it and plug it in again the TX light flashes until i open the port with C#
sPort = new SerialPort(CboPort.Text, 19200);
sPort.Open();
I don't send anything over the serial port after that.
The TX light stops flashing from then on even if i completely close down C#.
I then try the serial monitor in the Arduino IDE and the TX light pops back on. I get out of the serial monitor and the TX light stays off.

I'm not sure why the Serial port open command is shutting down the transmit on the Arduino side.