Ok, I just checked in the new version of NeoICSerial with attachTxCompletedInterrupt.
FWIW, if I were modifying the library, I would fix the whole HW vs. SW serial port goofiness.The library should just hold on to a Stream * for the port pointer. I assume that port is declared like this:
HardwareSerial *port;
If you change it to this:
Stream *port;
Then it could hold on to any of the hardware or software serial ports. I guess I would have expected constructors that take a few params and a Stream *.
Modbus::Modbus(uint8_t u8id, Stream *stream, uint8_t u8txenpin)
{
init(u8id, stream, u8txenpin);
}
void Modbus::init(uint8_t u8id, uint8_t u8serno, uint8_t u8txenpin)
{
this->u8id = u8id;
this->port = stream;
this->u8txenpin = u8txenpin;
this->u16timeOut = 1000;
}
... and called like this:
AltSoftSerial modbusPort;
...
Modbus modbus( MODBUS_ID, &modbusPort, TX_EN_PIN );
I'm pretty sure that the rest of the library won't know the difference, as it probably just uses available, read and write (and print variants).
If it calls begin for you, why? Delete that code and just call begin before you start the modbus library. :-/
I'm not sure how the TxComplete factors into this. If there are places in the library that wait for that UART status register bit to clear, I'd say switch to using flush everywhere.
If they were defining their own TXC_ISR, you would have to expose the TXC code in the library header, and connect it from the caller (the sketch). Sorry, I just haven't taken the time to look at the library.
But you're doing the work, not me. ![]()