论坛元老
 
- 积分
- 3071
- 金钱
- 3071
- 注册时间
- 2018-2-7
- 在线时间
- 285 小时
|
发表于 2020-3-26 20:59:00
|
显示全部楼层
byte[] sendDatas = { 0xa5, 0x5a, 0x01, 0x01, 0x03, 0xe8, 0x55, 0xaa };// 头1 头2 地址 命令 功率高 功率低 尾1 尾2
/// <summary>
/// 发送数据
/// </summary>
private void sendData()
{
txtReceiveData.SelectionColor = Color.Orange;
serialPort1.Write(sendDatas, 0, sendDatas.Count());
txtReceiveData.AppendText("发: ");
//string str = BitConverter.ToString(sendDatas).Replace("-", " 0x");//将接收到的字节数据转换为16进制
string str = BitConverter.ToString(sendDatas).Replace("-", " ");//将字节数据转换为16进制字符串
txtReceiveData.AppendText(str);
if (isShowTime)
{
string strDateTime = DateTime.Now.ToString() + ":" + DateTime.Now.Millisecond.ToString();//获取系统时间 获取当前毫秒 2015/4/9 星期四 20:11:18:895
txtReceiveData.AppendText(" [" + strDateTime + "]"); //显示接收时间
}
string s = System.Environment.NewLine;//获取系统的换行符
txtReceiveData.AppendText(s); //接收完一笔数据之后 重新换行显示
} |
|