Now most of the LG TV comes with a serial port (RS232), in fact, through this serial port can completely manipulate the LG TV, and the function than with the remote control powerful. By using the serial port to send instructions, you can do some simple operation of the TV, such as Switch TV, adjust the volume, Exchange channels. You can also perform complex controls such as a tuning table. In addition to the implementation of some remote control can not achieve functions, such as black screen (screenmute), lock screen (after the remote control and TV panel buttons will not work). Through the serial port can also send each button command, so the function can completely replace the TV remote control.
Details the official provides a document that can be downloaded on my Resources page http://download.csdn.net/detail/shallen320/8572513
Command format
General is the PC to send commands to the TV, the PC is the serial connection of the main, TV is from. The command format issued by the PC is [command] [space] [target device number] [space] [Data (multibyte)] [carriage return] square brackets are only used for fragmentation, not part of the actual command
[Command]: 2-byte command. Different function instructions This part is not the same as the power control is KA, the volume is KC
[Target device number]: The general LG TV default is 1, this number can be set in the TV options. If you use 0, it is sent to all LG TVs connected. Note that PCs can be connected to multiple LG TVs. Some TVs have 2 serial ports, so the PC can connect multiple LG TVs.
[Data]: The data portion of the instruction, which can be multibyte. For some instructions, the data segment is "FF" to query the state of the directive. For example, adjust the volume command, the data segment is "FF" can query the current volume.
[Enter]:ASCII code of 0x20, essential, TV by this character to identify the end of the packet
The TV will answer when it receives a properly formatted command, the answer format is [instruction after one byte] [space] [device number][ok/ng][data][x]
[instruction after one byte]: 2 byte instruction sent after one byte
[Ok/ng]: instruction status. OK indicates that the instruction is valid, and NG (No good) does not represent an instruction.
[x] Fixed character x
Hardware connection
I used a usb-rs232 converter, a USB port connected to the PC, and the other end of the serial interface behind the LG TV.
Connection test
Use any one serial terminal to be able to send and receive instructions. I have used the Windows-brought super Terminal HyperTerminal. Use HyperTerminal to set up a good serial port. My serial port is COM4, just select COM4 in the attribute. According to the official instructions, set the baud rate to 9600, 8 bytes, no parity, 1 bit stop bit. Basic is the default value. In addition to the ASCII settings I also hook up echotyped characters locally, so I can see their input. It's also hooked up to send lines ends with line feeds so it's easier to read.
After setting up test the Power Control command, can control the TV start, close, prove that the hardware connection is ready. In the figure Ka 0 1 is the boot command. A01 ok01x is the TV answer, stating that the device number is 01, the instruction is valid, the command current value is 01.
Control software Programming Implementation
After the hardware is ready, you can start programming software. Windows has the API to control the serial port, but more complex, interested readers can refer to a Microsoft 95 article, after 20 years, the article is still considered serial programming textbooks:
Https://msdn.microsoft.com/en-us/library/ff802693.aspx
I began to use QT to implement control software graphical interface parts, and later found that QT itself has a good support for the serial port. QT Internal Qtserial Port library to achieve the serial port read and write. It also provides an example of a serial terminal:
Http://doc.qt.io/qt-5/qtserialport-terminal-example.html
So I decided to use this example to add a control interface to the LG TV on this basis.
Adding a control interface is not difficult because the QT paradigm already implements the underlying serial communication. I added two menu options under Tools, the Tvcontrol option provides TV overall control, remote option for analog TV remotes (see)
Summarize
LG industry Conscience, provides a serial connection to control the TV. Using the serial port can fully control the LG TV with the computer. Imagine joining the network function, you can even use the office computer or mobile phone to control home TV. (A little excited to think about it)
Reprint please specify. Do not intend to open the code, need QT code can contact me.
LG TV controlled via RS232 serial port