C# 串口通信工具,返回值转换,电机转速反馈

廖大锤 廖大锤 墨衍会员 · AI 创作全网分发 墨衍智能分发 通过墨衍一键同步至各平台 可同步平台 CSDN微信公众号微博知乎掘金百家号博客园抖音小红书 你的文章也可以这样分发 墨衍会员 ¥399起/年,写一次发全网 我也要 + 加入社区
byte[] byteRead = new byte[serialPort.BytesToRead];
serialPort.Read(byteRead, 0, byteRead.Length);
serialPort.DiscardInBuffer();
string strRcv = null;

if (byteRead.Length > 20)
{
for (int i = 21; i < 25; i++) // 总长44
{
strRcv += byteRead[i].ToString("X2"); //16进制显示 转速21-24

}
Seri_mes_reci.Text += strRcv + "\r\n";
}

这是通过C#串口获取返回值的代码,返回的是44字节的数据,其中一段是我要的转速信息,
就是strRcv 对应的一串4个字节的十六进制的数,请问我怎么样把它转换为实际转速。
以下是我在C++采用的方法,试用过可行
float get;
char *p;
p = (char*)&get;
...全文

相关推荐

评论 6
收藏 已收藏
分享
返回顶部
廖大锤
C# 111,129 成员 642,538 内容