And it works fine except when no change is detected, and I press the button to read the frame. Since there is no new frame, the program waits for a new frame. When the new frame is received (a change is detected) it’s transmitted incompletely. Such as 7E 00 00 00 00… 00, and then the next frames gets ruined as well, because the incomplete frame “offsets” it.
I believe this is because it only updates on a button press. If I somehow got it to run continuously in a while loop I think that would solve the problem - or if there’s a way to add a delay so that it takes the time to read the whole frame.
Edit: There’s also a problem with the frames stacking up, so if I turn the switch on/off several times, then update in my program, I have to update once for every switch I did. This would also be solved with a real time update of the serialPort1.Read(buffer, 0, buffer.Length) function.
What bothers me is that it waits for a new frame when it’s read the last one.
But the problem is the serialPort1.Read(buffer, 0, buffer.Length); function. When that specific line of code runs, it waits for a new frame. The code stops there to wait. That’s the frustrating part.