通过TCP发送十六进制 [英] Sending Hex over TCP

查看:117
本文介绍了通过TCP发送十六进制的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我尝试通过TCP将十六进制数据发送到LCD监视器.但是我无法发送.
例如,"32 00 01"是监视器的测试十六进制.
我如何通过tcp发送它.
谢谢

我使用了这条鳕鱼,但无法正常工作
你还有其他想法吗
谢谢

Hi,

I try to send hex data to a LCD monitor over TCP.But I could not send.
For exampla "32 00 01" is a test hex for monitor.
How can ı send it over tcp.
Thank you

I use this cod but itis not working
do you any other idea
thank you

        m_socClient = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
string szIPSelected  = txtIPAddress.Text;
String szPort = txtPort.Text;
int  alPort = System.Convert.ToInt16 (szPort,10);

System.Net.IPAddress    remoteIPAddress  = System.Net.IPAddress.Parse(szIPSelected);
System.Net.IPEndPoint   remoteEndPoint = new System.Net.IPEndPoint(remoteIPAddress, alPort);
m_socClient.Connect(remoteEndPoint);
        byte[] message = new byte[] { 32, 0, 1 };
        m_socClient.Send(message);



[edit]已添加代码块-OriginalGriff [/edit]



[edit]Code block added - OriginalGriff[/edit]

推荐答案

十六进制"不是您要发送的东西,它只是一种查看数字的方式.例如,112与一百一十二是相同的数字-它们只是用不同的表示形式.

相反,请使用字节并发送这些字节(假设您要发送的是十六进制32):
"Hex" is not something you send, it is just a way of looking at the numbers. For example, 112 is the same number as one hundred and twelve - they are just in different representations.

Instead, use bytes and send those (assuming it is Hex 32 you want to send):
byte start = 0x32;
byte middle = 0x00;
byte end = 0x01;

现在发送那些字节,看看它是否有效!

您可以将它们创建为数组并将其发送:

Now send those bytes and see if it works!

You can create them as an array and send that instead:

byte[] message = new byte[] { 0x32, 0x0, 0x1};




我使用此鳕鱼,但无法正常工作
你还有其他想法吗
谢谢"



查看您的代码,然后查看我的等效代码:




"I use this cod but itis not working
do you any other idea
thank you"



Look at your code, then look at my equivalent:

byte[] message = new byte[] { 32, 0, 1 };


byte[] message = new byte[] { 0x32, 0x0, 0x1};

前缀"0x"表示要遵循的数据为十六进制-即以16为底.
如果未指定,则假定为十进制-即以10为底.
32十六进制是十进制的50!

就像112等于274一样!
(十六进制的112是十进制的274)

The "0x" prefix says that the data to follow is Hexadecimal - i.e. base sixteen.
If you do not specify, then decimal is assumed - i.e. base 10.
32 Hex is 50 in decimal!

It''s like saying that 112 is the same number as two hundred and seventy-four!
(112 in hexadecimal is 274 in decimal)


使用字节数组将十六进制数据发送到硬件
use byte array to send the Hex data to the Hardware
byte[] mybyte = new byte[] { 32, 0, 1 };



使用上面的字节数组将数据发送到LCD屏幕



use the above byte array to send data to the LCD Screen


这篇关于通过TCP发送十六进制的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆