Most of the latest Televisions or signage displays which comes with network or RS-232 option can be controlled remotely using a computer or mobile by passing the required commands to the TV
The commands may vary for each tv brand and or modal. It will be provided by the TV manufacturer and it will be in hexadecimal form like 08 22 00 00 00 01 D5 for powering off the TV
Using Network
The TV will be listening to a particular port to receive the commands. So will have to find the port from the document or port scanning
Once the port is identified, create a socket connection and the command can be sent thought the output stream.
The hex code should be converted to byte array and we should be sending the byte array.
public static String sendCommand (String ip, String cmd) throws Exception
{
StringBuilder responseString = new StringBuilder();
Socket clientSocket = new Socket();
int timeout = 5000;
//check the listening port in the TV documentation
int port = 5000;
clientSocket.connect(new InetSocketAddress(ip, port), timeout);
clientSocket.setSoTimeout(timeout);
DataOutputStream outstream = new DataOutputStream(clientSocket.getOutputStream());
outstream.write(Util.hexStringToByteArray(cmd));
outstream.flush();
//read the response
DataInputStream bufferedReader = new DataInputStream(clientSocket.getInputStream());
int count = bufferedReader.available();
byte[] ary = new byte[count];
bufferedReader.read(ary);
for (byte bt : ary) {
responseString.append(String.format("%02X ", bt));
}
outstream.close();
bufferedReader.close();
clientSocket.close();
return responseString.toString();
}
Using RS-232 If the computer does not have RS-232 port, we can buy USB to RS-232 adapter. https://www.amazon.com/RS232-USB/s?k=RS232+to+USB Once it is connected, we have to find the COM port attached to it from the device manager on a Windows machine. Then create a serial port and write bytes converted from the hex code
public static String sendCommand (String cmd)
{
System.out.println(" RS232-- " + cmd);
String respmsg = "SUCCESS";
try {
SerialPort serialPort = new SerialPort(“COM5”);
serialPort.openPort();
serialPort.setParams(SerialPort.BAUDRATE_9600,
SerialPort.DATABITS_8,
SerialPort.STOPBITS_1,
SerialPort.PARITY_NONE);
serialPort.setFlowControlMode(SerialPort.FLOWCONTROL_RTSCTS_IN);
serialPort.writeBytes(Util.hexStringToByteArray(cmd));
serialPort.closePort();
}
catch (SerialPortException ex) {
respmsg ="ERROR:" + ex.getMessage();
}
return respmsg;
}
Note In Java, The hex code can be converted to byte array using ajavax.xml.bind.DatatypeConverter. parseHexBinary