如何从串行端口n读取二进制值,在文本框中显示其十六进制值. [英] How to read binary value from serial port n display its hex value in text box..

查看:59
本文介绍了如何从串行端口n读取二进制值,在文本框中显示其十六进制值.的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

例如"11101111",这是我要在转换后如何从串行端口n读取数据的方式,如何显示其十六进制值..

e.g "11101111" this is the data which i want to read it from serial port n after its conversion how to display its hex value ..

推荐答案

取决于关于它如何到达sreail prot:如果它以单个字节到达,则只需从端口读取它,并设置TextBox.Text属性:
Depends on how it arrives at the sreail prot: if it arrives as a single byte, then just read that from the port, and set the TextBox.Text property:
myTextBox.Text = myRecievedByte.ToString("X02");

如果它以字符串"0"和"1"到达,则读取整个字符串并首先进行转换:

If it arrives as a string of ''0'' and ''1'' characters then read the entire string and convert it first:

byte myRecievedByte = Convert.ToByte(myRecievedString, 2);


byte value = serialPort.ReadByte();
string hexString = value.ToString("x2");


这篇关于如何从串行端口n读取二进制值,在文本框中显示其十六进制值.的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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