Is smarmengol Modbus software serial compatible with half duplex RS485 modules?

-dev:
AltSoftSerial is much more efficient and reliable than NeoSWSerial, so I would recommend it any day of the week. You may have to use time to "know" that the AltSoftSerial transmit buffer is empty... unless you want to modify AltSoftSerial, too. :wink:

I'll get back to that.

-dev:
I think so. This doesn't make sense:

        case 0:

default:
            UCSR0A=UCSR0A |(1 << TXC0);
            break;



That looks like code for case 0, not case 4 (default). When it's a software serial library, there is no "transmit complete" flag, and there is no "control and status register".

Unfortunately, AltSoftSerial and NeoSWSerial differ in how they handle transmission: AltSoftSerial has a transmit buffer that empties in the background, while NeoSWSerial blocks until the characters are transmitted. Detecting "transmission complete" will be different for these two libraries.

I hadn't noticed that.

I was looking at

if(u8serno<4)
        port->write( au8Buffer, u8BufferSize );
    else
        softPort->write( au8Buffer, u8BufferSize );

That requires u8serno to be >= 4 to use the software serial port. But to make it 4 then txenpin is set to 0 per

void Modbus::init(uint8_t u8id)
{
    this->u8id = u8id;
    this->u8serno = 4;
    this->u8txenpin = 0;
    this->u16timeOut = 1000;
}

If I try to use

void Modbus::init(uint8_t u8id, uint8_t u8serno, uint8_t u8txenpin)
{
    this->u8id = u8id;
    this->u8serno = (u8serno > 3) ? 0 : u8serno;
    this->u8txenpin = u8txenpin;
    this->u16timeOut = 1000;
}

and set u8serno to 4, then the if statement catches is and forces it back to 0 (hardware Serial).

What would be the point of that logic? Incomplete implementation?