Wait for real end of serial transmission

I know that Serial.flush() waits until the transmit circular buffer is empty, but as far as I am aware, that will return at the point that the last character gets moved from the transmit circular buffer into the transmit hardware buffer. That means that Serial.flush() actually returns at the start of the transmission of the last character.

What is the best way of waiting until the end of the transmission of the last character?

I am guessing it will involve first running Serial.flush() to get to the last character, then inspecting the SFRs for the serial port to know if transmission has finished.

Is there a more "Arduino" way of doing it that isn't going to be so hardware specific? Is some flag set somewhere by a transmit interrupt to say that the transmission has finished and a new character can be loaded into the buffer?

Which version of the IDE? There have been changes in how Serial.flush() operates over the last year.

1.0.1, and it is just a while loop comparing the head and tail of the circular buffer.

Thinking about it, I could do a flush followed by a dealt of 10000000/baud+1 microseconds. That should do the trick.

Serial.flush() followed by Serial.end() does it for me in 1.0.3.

1.0.3 does a little more than just make sure that the last character is being shuffled out before it returns.

There were issues with the last character or two now being sent before the Arduino went to sleep that were fixed. Completely? I don't know. I only use wallwarts.

Does flush() block?

Yes. But in the situation I am wanting it for that is actually desirable.

GoForSmoke: Does flush() block?

Yes, until all the characters are sent out. They 'fixed' the flush command in version 1.0.4 ( I think, might have been fixed in 1.0.2 according to release notes) to actually wait till the last character has left the building before returning, as before they returned when just the transmit serial software buffer was empty, but up to two characters could still be waiting to be sent in the serial hardware buffers. This effected people using RS-485 type transceiver chips where they had to output a signal to perform the send/receive enable signal.

Lefty

So it’s pretty quick until you have more string than hardware buffer?

Wow. I write Serial.available() driven routines… if I want the most responsive code doing much text-out it would make sense to manage what I feed Serial when, on a BlinkWithoutDelay scale. XD

retrolefty:
Yes, until all the characters are sent out. They ‘fixed’ the flush command in version 1.0.4 to actually wait till the last character has left the building before returning, as before they returned when just the transmit serial software buffer was empty, but up to two characters could still be waiting to be sent in the serial hardware buffers. This effected people using RS-485 type transceiver chips where they had to output a signal to perform the send/receive enable signal.

Which, surprisingly enough, is exactly what I want it for :slight_smile:

So, if 1.0.4 is in use, I can just flush. If < 1.0.4 is in use, then I should replicate the 1.0.4 flush routine myself and use that. If something other than Arduino is in use, then I should really do something specific to that chip in the replicated flush routine. That’s cool, I can do that. I really must upgrade to 1.0.4… When will Arduino set up their own ppa on launchpad so that you can track the latest version, instead of one thee versions too old that the os vendor has managed to drag himself out of bed to package?

When will Arduino set up their own ppa on launchpad so that you can track the latest version, instead of one thee versions too old that the os vendor has managed to drag himself out of bed to package?

For what OS?

Windows checks often to see if there is a new version of the IDE, and then won't accept no for an answer when you say that you don't want to go get it.

Every time I run an older version, to check out a user problem, Windoze wants me to get the newest version, even though I have.

What I would like to see is an announcement in the forum when there is a new version released.

PaulS:

When will Arduino set up their own ppa on launchpad so that you can track the latest version, instead of one thee versions too old that the os vendor has managed to drag himself out of bed to package?

For what OS?

Windows checks often to see if there is a new version of the IDE, and then won’t accept no for an answer when you say that you don’t want to go get it.

Every time I run an older version, to check out a user problem, Windoze wants me to get the newest version, even though I have.

What I would like to see is an announcement in the forum when there is a new version released.

What do you mean for what OS?

A launchpad ppa is for any Debian based system (chiefly Ubuntu and derivatives). “ppa” is the main way of installing new repositories into an Ubuntu system:

$ sudo apt-add-repository ppa:arduino

There is a third party ppa, but it’s decades out of date. The official repository only has what it considers “stable”, which is 1.0.1. I think 1.0.3 is in “proposed”, but it would be kind of nice if Arduino themselves maintained an official ppa, with current and stable branches, so you can track the latest version (and get 1.0.4 automatically). That’s never going to happen, of course, because Arduino don’t have much of a clue about installing packages in Linux. The official repository is maintained by third parties who do have a clue.

I for One, would be ecstatic... If there was a Forum Section devoted to the IDE and especially New releases. I have questions from time to time about the IDE and it's changes and so far the only way I find out about new releases is to read of other peoples issues... It wasn't until Ver 1.03 was released that I was aware of the 1.02 issues.. If nothing else perhaps a banner somewhere obvious in the forum.?

Bob

The official repository only has what it considers "stable", which is 1.0.1. I think 1.0.3 is in "proposed", but it would be kind of nice if Arduino themselves maintained an official ppa, with current and stable branches, so you can track the latest version (and get 1.0.4 automatically). That's never going to happen, of course, because Arduino don't have much of a clue about installing packages in Linux. The official repository is maintained by third parties who do have a clue.

Better check again, 1.0.4 was released 3/11/13

http://arduino.cc/en/Main/ReleaseNotes

Lefty

PaulS: Windows checks often to see if there is a new version of the IDE, and then won't accept no for an answer when you say that you don't want to go get it.

Every time I run an older version, to check out a user problem, Windoze wants me to get the newest version, even though I have.

I'm running windows and the IDE has never asked to update. Only time I know to upgrade is when I see people on here talking about a new release.

Of you want to run the newest then run it but some of us would rather the use quirks we know.

GoForSmoke:
Of you want to run the newest then run it but some of us would rather the use quirks we know.

I think the best route to go is to have several versions of the IDE installed on your PC. I presently have an older pre 1.0 release, version 22, and version 1.0.3 as well as 1.0.4 I downloaded this week. It does take a little manual management to change the user sketch directory location in the preference option when one changes versions to use, as it is best to have different user directories to store the sketches and the user libraries folder that are compatible with the IDE version being used. Once you get the hang of it it’s not hard to manage switching versions quickly and it allows the most freedom and choice of running older sketches and newer sketches that often require newer or older library folders.

Lefty

I use 0022 and have 1.03 that I set up to work someone else's sketch with. XP being what it is, I've had to reload drivers to go back.

Yes, I know the solution. Quit using XP and the things that I run that only run on Winblows. I'm just not ready yet. The day is coming though.

GoForSmoke: I use 0022 and have 1.03 that I set up to work someone else's sketch with. XP being what it is, I've had to reload drivers to go back.

Yes, I know the solution. Quit using XP and the things that I run that only run on Winblows. I'm just not ready yet. The day is coming though.

I run XP SP3 and never had to do anything with 'drivers' when switching back and forth between IDE versions. But then again I don't presently own any arduino boards that use the 8U2 or 16U2 serial USB chips, only FTDI or CP2102 based boards, if that is the issue. I do own a teensy 3.0 that uses it's own modified IDE and drivers so that doesn't get switched around.

Lefty

Riva:

PaulS: Windows checks often to see if there is a new version of the IDE, and then won't accept no for an answer when you say that you don't want to go get it.

Every time I run an older version, to check out a user problem, Windoze wants me to get the newest version, even though I have.

I'm running windows and the IDE has never asked to update. Only time I know to upgrade is when I see people on here talking about a new release.

With current version of the IDE there is a preference option to be notified or not, so check yours to see if it's enabled or not. I leave mine turned off.

Lefty