简体   繁体   English

通过TCP / UDP发送串行字节数据-Visual Basic

[英]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. 我正在构建.NET WinForms应用程序,以通过TCP / UDP将串行命令发送到同一网络上的联网电视。 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. NEC(制造商)已经创建了一个名为PD Comms的工具,可以很好地完成此任务,并且效果很好,但是对于最终用户来说太复杂了。 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. 连接到网络后,我的应用程序成功打开了网络流,因此我输入的IP地址/端口没有问题。 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("10.71.208.61", 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)
client.Close()
End Sub

I believe the line where I assign data to the commandData byte array is incorrect. 我相信将数据分配给commandData字节数组的行是错误的。 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. 我使用的字节数据是NEC的PD Comms Tool的直接输出。

使用Wireshark之类的工具来检查和比较NEC工具发送的TCP / UDP数据包以及代码发送的TCP / UDP数据包。

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"}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM