tpag26 tpag26 - 3 years ago 86 Question

Sending serial byte data over TCP/UDP - Visual Basic

I'm building a .NET WinForms application to send serial commands over TCP/UDP to networked televisions on the same network. NEC (manufacturer) have created a tool called PD Comms that does just this and works very well, however it is too complex for end users. My interface will have a single button that sends all the necessary power/volume/input selection commands to all the TVs.

The issue I'm having is getting the TVs to accept my data stream. I believe the issue is to do with how I'm sending the data to the panel. As a trial, I've been working with a simple power on command to one of the four TVs. My application successfully opens a network stream when connected to the network so there is no issue with the IP address / port which I have inputted. My code to send this command is below.

Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Dim client As New TcpClient("", 7142)
Dim dataStream As NetworkStream = client.GetStream()
Dim commandData() As Byte = {1, 30, 41, 30, 41, 30, 43, 2, 43, 32, 30, 33, 44, 36, 30, 30, 30, 31, 3, 73, 0D}
dataStream.Write(commandData, 0, commandData.Length)
End Sub

I believe the line where I assign data to the commandData byte array is incorrect. The command goes through without any errors and establishes a connection with the panel. It seems as though it is sending the code successfully but the TV is simply not responding (turning on) which suggests the data I'm sending is not in the correct format. The byte data I'm using is the direct output from NEC's PD Comms Tool.

Answer Source

In case this issue catches anyone else... it was just with the way I was representing data types. Correct formatting is:

Dim commandData() As Byte = {&H30, &H30, "&H5F", &H64, &H31, "&H0D"}
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download