After doing some investigation, my BitConverter.GetBytes was returning a 4 byte array = {1, 16, 0, 0}
The integer passed to BitConverter.GetBytes was 4097.
I am not sure why the BitConverter.GetBytes is returning a 4 bite array, but {1, 16} is correct for LittleEndian, so (if I understand it correctly) i need to reverse it to pass WORD {16, 1}. Therefore, I have removed the loop and changed it to:
- Code: Select all
CODE REMOVED
Updated code in post below
Note:
I have tested with many MaxBuffer values and passing the reversed first 2 bytes are always correct for the (MaxBuffer * 2) + 1 value as long as the value is less then 65535. Any time it gets a value greater then 65535, it will then cause problems, so I set a cap of 32767.
I also added an If statement to handle a case if the MaxBuffer value was too low (smaller then line length).