ESP8266 – software serial – not receive data
I have a small test project in b4r and spent about 3 hours last night going through the b4r libraries, mainly AsyncStreams and B4RStream.
The issue as far as I can tell is that when the B4RStream library does readBytes with the line
B4X:
Int i = wrappedStream->readBytes(((Byte*)Buffer->data + StartOffset + total), MaxCount);
The returned value ‘i’ is -1.
If you log the action directly with
B4X:
::Serial.println(wrappedStream->readBytes(((Byte*)Buffer->data + StartOffset + total), MaxCount));
the returned value is 4294967295 which is higher than the max value of the Int variable (2147483647) so is possibly why it returns -1 (overflow maybe?)
This in turn returns to the AsyncStream lib the value of read bytes as 0
So then in this code in AsyncStream
B4X:
if (index > 0 && (!me->prefixMode || index == maxSize)) { arr->length = index; sender->wrapPointer(b); B4R::StackMemory::cp += index; ::Serial.print("Lib - Data4"); me->NewDataSub(arr); }
Also, interestingly. When accessing the stream direct in b4r with
B4X:
If swserial.Stream.BytesAvailable> 1 Then Dim b(swserial.Stream.BytesAvailable) As Byte Dim len As Int = swserial.Stream.ReadBytes(b, 0, b.Length) Log ("b4r - ", b) Log ("Length = ", len) Else Log("No data") End If
Any thoughts on this
I think I’m about to give up on this.I have my new hardware and put it together. I tested with simple arduino project and get a loopback response so I know hardware is good.I have a small test project in b4r and spent about 3 hours last night going through the b4r libraries, mainly AsyncStreams and B4RStream.The issue as far as I can tell is that when the B4RStream library does readBytes with the lineThe returned value ‘i’ is -1.If you log the action directly withthe returned value is 4294967295 which is higher than the max value of the Int variable (2147483647) so is possibly why it returns -1 (overflow maybe?)This in turn returns to the AsyncStream lib the value of read bytes as 0So then in this code in AsyncStream’i’ is always 0 and so NewDataSub is never called.Also, interestingly. When accessing the stream direct in b4r within the log, Length = 0. Which again uses the B4RStream lib and returns 0 like when using AsyncStream.Any thoughts on this @Erel