C# read byte array from SerialPort -
i ask why program returns first byte instead of byte. usb port sending byte value of 23, however, when c# program reads it, receives value of 2. why happening? c# code below
private void button1_click(object sender, eventargs e) { serialport port = new serialport("com4", 9600); port.open(); byte[] buffer = new byte[2]; port.read(buffer, 0, 2); handleserialdata(buffer); port.close(); } private void handleserialdata(byte[] respbuffer) { string one, two; char a, b; = convert.tochar(respbuffer[0]); b = convert.tochar(respbuffer[1]); 1 = convert.tostring(a); 2 = convert.tostring(b); messagebox.show(one + two); }
Comments
Post a Comment