/// <summary> /// 氧气校准 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void id_set_btn_Click(object sender, EventArgs e) { string hex = Decimal.ToInt32(id.Value).ToString("x2"); string pre = "ff10001000010200"; string msg = pre + hex + Crc16_modbus.ToModbusCRC16(pre + hex, true);//得到加了crc校验的消息 //发送设置指令 SendStrCmd(msg); }
private void setting_ValueChanged(object sender, EventArgs e) { NumericUpDown nu = (NumericUpDown)sender; string name = nu.Name; int value = Decimal.ToInt32(nu.Value); string pre = cmdSetThreshold.Single(k => k.Key == name).Value;//获取到前缀 string hex = value.ToString("x2"); string msg = pre + hex + Crc16_modbus.ToModbusCRC16(pre + hex, true);//得到加了crc校验的消息 //发送设置指令 SendStrCmd(msg); }
public void SendCmd(string cmd) { if (MessageBox.Show("发送的指令为【" + cmd + "】\r\n确认无误后发送", "发送确认", MessageBoxButtons.OKCancel) == DialogResult.OK) { string cmd_t = cmd.Replace(" ", string.Empty); string cmd_crc = cmd_t + Crc16_modbus.ToModbusCRC16(cmd_t, true); bool staus = parentForm.SendStrCmd(cmd_crc); if (staus) { MessageBox.Show("指令【" + cmd_crc + "】发送成功!", "操作提示", MessageBoxButtons.OK, MessageBoxIcon.Information); } else { MessageBox.Show("指令【" + cmd_crc + "】发送失败!\r\n 请检查串口工作状态。", "操作提示", MessageBoxButtons.OKCancel, MessageBoxIcon.Warning); } } }