在comport写入字节 [英] Write byte at comport
本文介绍了在comport写入字节的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想在comport中从字节数组中逐个写入一个字节.
我有这样的数据:
I want to write one by one byte at comport from byte array.
I have data like this:
byte[] tempdata = FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF 02 80 00 00 82 CD
我要写FF,然后写FF ....像这样
一个接一个的不打孔的字符串
I want to write FF then write FF.... one by one not hole string together like this
comPort.Write(tempdata,0,tempdata.Length);
我不想从此代码中编写.
我使用此代码:
I don''t want to write from this code.
I use this code:
for (int i = 0; i < tempdata.Length; i++)
{
comPort.Write(tempdata,i,i);
}
但是这不起作用,我不知道该怎么写.
But this will not work i don''e know how to write this as i want.
推荐答案
只需更改一个参数
Just change one parameter
for (int i = 0; i < tempdata.Length; i++)
{
comPort.Write(tempdata, i, 1);
}
一次写入 1 字节而不是 i 字节.
to write 1 byte at a time instead of i bytes.
使用此命令:
Use this:
for (int i = 0; i < tempdata.Length; i++)
{
comPort.Write(tempdata,i,1); // Here 1 instead i
}
问候
Regards
这看起来像是学术问题;与正在进行的项目无关.从此列表中将其删除.
It looks like academic question; not related to live project. Remove it from this list.
这篇关于在comport写入字节的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文