private void btnCoder_Click(object sender, EventArgs e) //Coder { var msgCoder = new BSDB232() { ID = 0x01, CMD = 0xA0, AddrH = 0x70, AddrL = 0x70, ErrR = 0x00, Dat1 = 0x00, Dat2 = 0x00, Dat3 = 0x00, Dat4 = 0x00, //Check = 0x81 }; Serial1PcToMcu(msgCoder); }
//屏幕大小173 307 #region 读取驱动器实际直流母线电压 private void btnVoltage_Click(object sender, EventArgs e) //Voltage { var msgVol = new BSDB232() { ID = 0x01, CMD = 0xA0, AddrH = 0x50, AddrL = 0x01, ErrR = 0x00, Dat1 = 0x00, Dat2 = 0x00, Dat3 = 0x00, Dat4 = 0x00, //Check = 0xF2 }; Serial1PcToMcu(msgVol); }
}//刷新屏幕 #endregion #region 串口发送函数 #region IO模块发送函数(串口1) private void Serial1PcToMcu(BSDB232 msg) { arrMotor[0] = msg.ID; arrMotor[1] = msg.CMD; arrMotor[2] = msg.AddrH; arrMotor[3] = msg.AddrL; arrMotor[4] = msg.ErrR; arrMotor[5] = msg.Dat1; arrMotor[6] = msg.Dat2; arrMotor[7] = msg.Dat3; arrMotor[8] = msg.Dat4; for (int i = 0; i < arrMotor.Length - 1; i++) { msg.Check += arrMotor[i]; } arrMotor[9] = msg.Check;; serialPort1.Write(arrMotor, 0, 10); WriteToSendTextBox(serialPort1.PortName + ":" + GeneralConver.ToHexString(arrMotor)); }
private void btnMotor_Click(object sender, EventArgs e) //Motor { var msgRmp = new BSDB232() { ID = 0x01, CMD = 0x52, AddrH = 0x70, AddrL = 0xB1, ErrR = 0x00, Dat1 = GeneralConver.ToIntBytes(speedMotor)[3], //MSB Dat2 = GeneralConver.ToIntBytes(speedMotor)[2], Dat3 = GeneralConver.ToIntBytes(speedMotor)[1], Dat4 = GeneralConver.ToIntBytes(speedMotor)[0] //LSB //Dat3 = 0x01, //Dat4 = 0xF4, //Check = 0x69 }; Serial1PcToMcu(msgRmp); }
private void btnRpmDown_Click(object sender, EventArgs e) //RpmDown { speedMotor -= 50; if (speedMotor < 50) { MessageBox.Show("已超出最小转速!"); return; } var msgRmp = new BSDB232() { ID = 0x01, CMD = 0x52, AddrH = 0x70, AddrL = 0xB1, ErrR = 0x00, Dat1 = GeneralConver.ToIntBytes(speedMotor)[3], //MSB Dat2 = GeneralConver.ToIntBytes(speedMotor)[2], Dat3 = GeneralConver.ToIntBytes(speedMotor)[1], Dat4 = GeneralConver.ToIntBytes(speedMotor)[0] //LSB }; Serial1PcToMcu(msgRmp); }