You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Well, I created a solution... Turns out it was to do with serialPort.ReadLine() and the way it converts to string. Not sure why it was adding question marks (completely ridiculous actually). But what I threw together reads in a line of bytes directly instead of using Readline()
SerialThreadLines.cs
/*OLD WAY
protected override object ReadFromWire(SerialPort serialPort)
{
return serialPort.ReadLine();
}
*/
/*NEW WAY*/
private List<byte> buffer = new List<byte>();
protected override object ReadFromWire(SerialPort serialPort)
{
buffer.Add( (byte)serialPort.ReadByte() );
// Search for the separator in the buffer
int index = System.Array.FindIndex<byte>(buffer.ToArray(), 0, buffer.Count, IsSeparator);
if (index == -1)
return null;
buffer.RemoveAt (buffer.Count - 1); //remove CR
buffer.RemoveAt (buffer.Count - 1); //remove LF
var output = buffer.ToArray ();
buffer.Clear ();
return output;
}
private bool IsSeparator(byte aByte)
{
return aByte == '\n';
}
Above could really use some optimization but it's simply conceptual.
Attempting to print an unprintable character (like 128) can yield weird outputs (because they are unprintable). Normally what you do with those characters is to print their ASCII value, not the character itself.
If I send the byte 128 (or anything higher) followed by a newline then I read that into Unity like so:
Outputs: "?" (or ascii 63).
This is just wrong!
The text was updated successfully, but these errors were encountered: