Update: I've solved it but I don't know how so I can't write a solution for this question
At least I think that's what is happening. It is rough to find out which end the code seems to be failing on.
Basically I have a C# application sending data to an ESP32 once a second over USB CDC serial using the SerialPort class at 4x115200 baud. (8N1)
It sends the title packet okay, which is very small, dependent on the length of the title string.
It also sends a 2052 byte icon packet and that's where the trouble is.
It will function if I drop to the debugger and break on that line, and then continue.
It used to function at least at one point when I dropped a Thread.Sleep in there (after i found out debugging made it go)
So I thought it might be the size of the write buffer, which I increased to 16kB, and the read buffer on the other end, same
Then I figured maybe it's because the UI timer fires on a separate thread? So I thunked my SerialPort calls down to the UI thread using Control.Invoke
Then I thought, maybe I'll try chunking it, writing 64 bytes at a time, so I did that. It seemed to make it so not even the text sent (even though I'm not chunking the text portion)
Stranger still If I keep sending the icon packet once a second it seems to force it, but if I put a keepalive packet in there just to keep things alive when no data has changed the icon stops working.
What I have tried:
here's the meat of it (after all the data is prepared)
string title = Path.GetFileNameWithoutExtension(path);
if (!port.IsOpen)
{
port.WriteTimeout = 1000;
port.WriteBufferSize = 16384;
port.Open();
}
var ba = new byte[5 + title.Length];
ba[0] = 1;
BitConverter.GetBytes(title.Length).CopyTo(ba, 1);
Encoding.ASCII.GetBytes(title).CopyTo(ba, 5);
port.Write(ba, 0, ba.Length);
port.BaseStream.Flush();
if (iconBuffer != null)
{
if (!port.IsOpen)
{
port.WriteTimeout = 1000;
port.WriteBufferSize = 16384;
port.Open();
}
ba = new byte[iconBuffer.Length + 5];
ba[0] = 2;
BitConverter.GetBytes(iconBuffer.Length).CopyTo(ba, 1);
iconBuffer.CopyTo(ba, 5);
System.Threading.Thread.Sleep(100);
port.Write(ba, 0, ba.Length);
port.BaseStream.Flush();
}