Sure. Only the hardware serial function actually implements the available method. The software serial functions include the method, but it is not implemented. It simply returns true.
You need to actually examine the value returned by nss.read(). If it's negative, don't use it.
But that's the serial library we are talking about.
Just to clarify, talking about NewSoftSerial (NSS)
It looks like it's implemented and I'm assuming it's doing something useful...?
uint8_t NewSoftSerial::available(void)
{
// A newly activated object never has any rx data
if (activate())
return 0;
return (_receive_buffer_tail + _NewSS_MAX_RX_BUFF - _receive_buffer_head) % _NewSS_MAX_RX_BUFF;
}
Right... I'm getting what I'd expect which is good output at the start (the CMD), and good output after =solar onwards, but still the corruption of course - just to remind, I didn't get this corruption when using the first program so it isn't the actual device itself which is outputting this corruption. The bit before =solar should be SSID (again, which I get on the first program)
Here's the main part:
Bytes available: 18
Read a C which has a decimal value of 67
Read a M which has a decimal value of 77
Read a D which has a decimal value of 68
Read a
which has a decimal value of 13
Read a
which has a decimal value of 10
Read a
which has a decimal value of 3
Read a c which has a decimal value of 99
Read a s which has a decimal value of 115
Read a k which has a decimal value of 107
Read a l which has a decimal value of 108
Read a j which has a decimal value of 106
Read a = which has a decimal value of 61
Read a s which has a decimal value of 115
Read a o which has a decimal value of 111
Read a l which has a decimal value of 108
Read a a which has a decimal value of 97
Read a r which has a decimal value of 114
Read a
which has a decimal value of 13
Just for information this is coming over UART from a Wifly GSX at 9600 baud (any faster and NSS gave me a ton of corruption)
I'm confused, after reading the User Manual for the WiFly. The CMD string is returned as a prompt after the WiFly enters command mode. Command mode is entered by sending "+++" to the device.
But, you are sending "cmd", and getting CMD back, and then you continue to read data.
I would expect that you would send a command after receiving the CMD string (followed by the carriage return/line feed).
I'm getting CMD back at first because I'm not giving the module a proper chance to respond before flushing, adding a 400msec delay before flushing fixes this, but still get corrupted chars:
Bytes available: 15
Read a + which has a decimal value of 43
Read a
which has a decimal value of 3
Read a k which has a decimal value of 107
Read a l which has a decimal value of 108
Read a j which has a decimal value of 106
Read a = which has a decimal value of 61
Read a s which has a decimal value of 115
Read a o which has a decimal value of 111
Read a l which has a decimal value of 108
Read a a which has a decimal value of 97
Read a r which has a decimal value of 114
Read a
which has a decimal value of 13
Read a
which has a decimal value of 10
Again... I continue recieving a bunch of data after that (just a snippet) but it's all perfect apart from those first few chars which should be SSID(=solar)...
I don't think I'm going to be able to help you any more. I am curious, though, why you switched from the hardware serial interface to a software serial interface.
I don't think I'm going to be able to help you any more. I am curious, though, why you switched from the hardware serial interface to a software serial interface.
No worries, thanks for your help so far Paul, I'll keep playing myself.
Switched purely so I could keep using the hardware serial interface for debugging etc... I've been using NewSoftSerial for ages on Lantronix devices without any problems at all which is why I'm so confused!