delphipostcomport

How to clear a customer display using TComPort with Delphi 10.2?


I am using TComPort v6.0 from Winsoft to connect to my COM5 device which is a customer display from Oxhoo.(Prolific PL2303 USB-to-Serial Com Port)

I would like to simply display some text on it and then clear the entire display when a button is pressed. I've already searched for a clear command but it doesn't seem to work like that.

For now I can successfully send text to display using Comport1.WriteString() but I can't clear the display or get the text displayed.

Also, sending long string of spaces does visually clear the display but the next text that will be displayed will be at a random position. (last text length + added spaces).

According to the manufacturer it should support ESC/POS commands but I can't figure out which and how to use them in my Delphi code.

The display consists of 2 lines of 20 characters.

> [][][][][][][][][][][][][][][][][][][][]
> [][][][][][][][][][][][][][][][][][][][]

How can I clear the display and again write text from the first line?


Solution

  • In order to simply clear the display we need to send an ESC/POS command wich is :

    CLR 0C Clear display screen 
    

    -> 0C in hex converts to 12 in decimal.

    So for Delphi it is as simple as that :

    Comport1.WriteLine(#12);