0

The following code shows how to connect to a serial port using a C# and write a "Hello World!!!" message to the serial device "Customer Display".

public Form1()
    {
        ComPort = new SerialPort();
        
        ComPort.PortName = "COM2";
        ComPort.BaudRate = 9600;
        ComPort.DataBits = 8;
        ComPort.StopBits = StopBits.One;
        ComPort.Handshake = Handshake.None;
        ComPort.Parity = Parity.None;
        ComPort.DtrEnable = true;
        ComPort.RtsEnable = true;
        ComPort.PinChanged += new SerialPinChangedEventHandler(PinChanged);
        ComPort.DataReceived += new SerialDataReceivedEventHandler(port_DataReceived_1);
        
        ComPort.Open();
        
        ComPort.Write("Hello World!!!");
    }
    
    private void port_DataReceived_1(object sender, SerialDataReceivedEventArgs e)
    {
        InputData = ComPort.ReadExisting();
    }
    
    private void PinChanged(object sender, SerialPinChangedEventArgs e)
    {
        //some code
    }

Unfortunately, a DataReceived event does not fire, Why?

Bassam Najeeb
  • 607
  • 2
  • 7
  • 16
  • You are using the wrong port or the cable is bad. You are sending but other device is not returning data. I would take a paper clip and connect pins 2 & 3 of serial connector on PC and see if code works. Jumping 2 & 3 will return what you send. – jdweng Jun 16 '22 at 09:54
  • Please check the specifications of the customer display. When you send a string display command to the customer display, is it designed to not only display it but also return a response? Most of these devices do not return a response, or even if they do, they are likely to be non-printing characters such as ACK (0x06). – kunif Jun 16 '22 at 11:54

1 Answers1

0

A customer display device is like a monitor, so it receives a text or command message from a PC via a serial port but doesn't send anything to the PC.

Bassam Najeeb
  • 607
  • 2
  • 7
  • 16