serial port - C#: SerialPort communication -
I want to write serialport com1
01 00 00 02 37 30 04
< P> This is the command for initialization.When I have a four array or byte array
c [0] = (char) 01; // c [1] = (four) 00; C [2] = (four) 00; C [3] = (four) 02; C [4] = (four) 37; C [5] = (four) 30; C [6] = (four) 04; Serial port 1 Write (C, 0, C. Lang); Byte [] BB1 = SystemTek Encoding.Default Getbytes (c);
I can see the serial port in the monitor: 01 00 00 02 25 1 E4 is clearly converted from 37 to 25 and 30 to 1 a ... I have 37 more How to cross 30 and not hex values ... I tried many ways ...
The serial port monitor is showing values in hexadecimal, therefore They match those values that you actually send. No conversions are running, decimal value is 37 in hexadecimal, and decimal value is 1E in 30 hexadecimal.
When you create an array, use hexadecimal notation (0x) for literal values, then you see that the value is expected in the serial port monitor:
Byte [] c = new byte [] {0x01, 0x00, 0x00, 0x02, 0x37, 0x30, 0x04}; Serial port 1 Write (C, 0, C. Lang);
Comments
Post a Comment