First, I know I should be using the async streams for the serial ports. I am doing that and it works very well. I wanted to explore just getting the serial data without using async streams and have run into two issues.
input = sp1.GetInputStream
Dim buffer(1024) As Byte
Dim count As Int
count = input.BytesAvailable
Log(count) - always zero here for some reason?
count = input.ReadBytes(buffer, 0, buffer.length) - hangs here forever if I unplug the serial port (not the USB), so there's no data.
If count > 0 Then
Main.read_knife_adjust_byte = buffer(count-1)
Main.knife_adjust_board_installed = True
End If
In the above code, I have a board that is continually sending just one byte of data at 9600 baud. The code works fine except for 2 odd issues.
1: The count in the input.bytesavailble line always returns 0 (zero) - don't know why?
2: If I unplug the serial port (not the USB side, its still plugged in), the program hangs at the readbytes line and never returns. Don't know why?
Its not the end of the world here, as I said, I implemented the this using async streams without any problems, I am just curious as to what I missed here?