Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

to send hex codes to serial port

Tags:

c#

I am using posiflex customer display, and I am trying to clear the display. I have gone through the user's manual, and I found PST command mode, which uses hex codes. I don't know how to pass these hex codes to serial port to clear my display. From the manual, I need to send the following hex numbers: 14 0E

I tried the following code to send these bytes, but I don't know how to pass two bytes at the same time.

SerialPort sp = new SerialPort();

    sp.PortName = "COM6";
    sp.BaudRate = 9600;
    sp.Parity = Parity.None;
    sp.DataBits = 8;
    sp.StopBits = StopBits.One;
    sp.Open();
   byte[] bytestosend = new byte[1] { 0x0E };

    sp.Write(bytestosend, 0, 1);
    sp.Close();
    sp.Dispose();
    sp = null;

When i use this code, no operation is performed (display is not cleared).

like image 207
Ameena Avatar asked Dec 14 '22 16:12

Ameena


1 Answers

To send multiple bytes just use comma to separate the bytes. You should have something like this:

sp.PortName = "COM6";
sp.BaudRate = 9600;
sp.Parity = Parity.None;
sp.DataBits = 8;
sp.StopBits = StopBits.One;
sp.Open();
byte[] bytestosend = { 0x14, 0x0E };

sp.Write(bytestosend, 0, bytestosend.Length);
sp.Close();
sp.Dispose();
sp = null;
like image 59
Belogix Avatar answered Jan 04 '23 16:01

Belogix