.net串行端口 [英] .net serial port

查看:80
本文介绍了.net串行端口的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用serialport-> write(myCharArray,offset,count)发送数据.

我将:: tochar 0x3E和0x02转换为unsigned char数组并将其发送,并且我使用serialPort-> read(myAnotherCharArray,offset,count)来回读反馈,但失败,它始终包含0.

我可以使用超级终端与我的设备进行通信.在超级终端中,我发送>"和''(我无法显示此内容,无论如何我按住alt键并输入02并释放alt键).我发送的这2个数据的格式是什么?

使用convert :: tochar将十六进制转换为char是错误的吗?

任何人都请教我如何通过串行端口发送与超级终端中相同的数据(超级终端中的设置为默认设置).

I use serialport->write(myCharArray,offset,count) to send my data.

I convert::tochar 0x3E and 0x02 to a unsign char array and send them,and i use serialPort->read(myAnotherCharArray,offset,count)to read back the feedback but fail,it always contain 0.

I can use hyper terminal to communicate with my device.In hyper terminal,i send ''>'' and '' ''(i cant show this in ,anyway i hold alt and key in 02 and release the alt key).What is the format of this 2 data i send?

Is it wrong to use convert::tochar to convert my hex to a char??

Anyone please teach me how to send the same data as in hyper terminal(the setting in hyper terminal is default) by using serial port.

推荐答案

值x02是一个字节值,尽管它在ASCII字符集中没有可视的表示形式(如果有内存,则为STX字符).如果您希望将此字节发送到远程设备,则只发送它,不要尝试将其转换为其他字节.
The value x02 is a byte value, although it has no visual representation in the ASCII character set (if memory serves it is the STX character). If you wish to send this byte to your remote device then just send it, do not try and convert it to something else.


这篇关于.net串行端口的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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