How to check if softwareSerial port has finished sending?

Hi,

My application uses two softwareSerial ports. One to talk to the ESP8266 at 9600bps and another to talk to another device at 1200bps. The latter doesn’t support higher speeds. In most cases the application replicates data packets from one to port to the other with or without pre-processing.

My question is how to avoid overflow situations in the slower serial port considering that there is no serial buffer on Tx. In other words, how can I make sure that one packet has been completely sent before trying to send the next?

Thanks

What software serial library are you using? depending on which one it may not the implimentation of 2 software serial ports may not be supported...

I am using the one that comes with the IDE 1.8x

It does support 2 serial ports but only one is listening at a time. I use port.listen () to switch between ports.

SoftwareSerial is the worst choice. Use AltSoftSerial on pins 8 & 9 (for an UNO), or NeoSWSerial on any two pins (at 9600, 19200 or 38400). It would be even better if you could use the built-in Serial for one of them. Here's some info about choosing a serial port for a GPS device, but it applies to your case.

@dev: I was under the impression that Newsoftserial is now the standard in the IDE. Altsoftserial is not an option since i cant change the pins used. Serial1 is also being used.

I did not say "Newsoftserial".

It would help if you told us which Arduino you are using...

Watcher: My question is how to avoid overflow situations in the slower serial port considering that there is no serial buffer on Tx. In other words, how can I make sure that one packet has been completely sent before trying to send the next?

Thanks

Isn't writing to software serial blocking anyway? I'm pretty sure it is, in which case this problem doesn't exist.

Your problem is making sure one of the serial ports doesn't try to RECEIVE anything while either of them is trying to transmit.

DrAzzy:
I’m pretty sure it is, in which case this problem doesn’t exist.

trust your instincts…

#include "Print.h"

// Public Methods //////////////////////////////////////////////////////////////

/* default implementation: may be overridden */
size_t Print::write(const uint8_t *buffer, size_t size)
{
  size_t n = 0;
  while (size--) {
    if (write(*buffer++)) n++;
    else break;
  }
  return n;
}