serial port - C# SerialPort stops reading after reading a 0x0 -


i have small program writing serial command microcontroller mc returns sent command program. command outputs set on , off. if outputs off may happen command consists of zeros(hex) :

command    outputs            end of command l          0 0 0 0                   ;   

the programm should read in case

l          0 0 0 0                   ;  

but sp.bytestoread 2 , sp.read() function reads first 2 bytes(until first 0x0)

how can change serialport not stop reading after first zero.

update: here code how port openend

if (sp == null)     sp = new serialport() { portname = comportname, baudrate = 19200, databits = 8, stopbits = stopbits.one, parity = parity.none, readtimeout = 400 };  if (!sp.isopen)     sp.open(); 

and how read:

byte[] buffer = new byte[sp.bytestoread]; sp.read(buffer, 0, sp.bytestoread); 

the problem bytestoread should 8 less 8 if 1 byte 0. tried set discardnull true/false made no change.

thanks in advance!


Comments

Popular posts from this blog

javascript - Using jquery append to add option values into a select element not working -

Android soft keyboard reverts to default keyboard on orientation change -

Rendering JButton to get the JCheckBox behavior in a JTable by using images does not update my table -