// set control para private void button5_Click(object sender, EventArgs e) { MotorPara.maxCurrent = Convert.ToUInt16(textBox17.Text); MotorPara.maxDegree = Convert.ToByte(textBox14.Text); if (checkBox1.Checked) { MotorPara.reversse = 1; } else { MotorPara.reversse = 0; } if (checkBox2.Checked) { MotorPara.run2zero = 1; } else { MotorPara.run2zero = 0; } CommProtocol.SendCmd(CommProtocol.CMD_SET_CONTROL_PARA); }
private void hall_Load(object sender, EventArgs e) { UploadData.max = 0; UploadData.min = 16384 * 10; InitTips(); CommProtocol.SetTraceMode(CommProtocol.TRACE_MODE_PC); InitTimer(); }
private void button4_Click(object sender, EventArgs e) { MotorPara.Kp = Convert.ToUInt16(textBox1.Text); MotorPara.Ki = Convert.ToUInt16(textBox5.Text); MotorPara.Ke1 = Convert.ToUInt16(textBox8.Text); MotorPara.Ke2 = Convert.ToUInt16(textBox11.Text); CommProtocol.SendCmd(CommProtocol.CMD_SET_PID_PARA); }
public void comm_DataReceived(object sender, SerialDataReceivedEventArgs e) { int i; try { byte[] framebuffer = new byte[128]; byte frametype = 0; int n = CVar.GetComm().BytesToRead;//先记录下来,避免某种原因,人为的原因,操作几次之间时间长,缓存不一致 if (n == 0) { return; } byte[] buf = new byte[n]; //声明一个临时数组存储当前来的串口数据 received_count += n; //增加接收计数 comm.Read(buf, 0, n); //读取缓冲数据 //Add receive data to que for (i = 0; i < n; i++) { FifoClass.EnFifo(buf[i]); } if (GetFrame(ref framebuffer, ref frametype) > 0) { st_CommParaSet commPara = new st_CommParaSet(); commPara = (st_CommParaSet)CommProtocol.BytesToStruct(framebuffer, commPara.GetType()); UploadData.hall_angle = commPara.hall_angle; UploadData.zeroAngle = commPara.hall_zero_angle; UploadData.hall_x = commPara.hall_x; UploadData.hall_y = commPara.hall_y; UploadData.maxDegree = commPara.maxDegree; UploadData.maxCurrent = commPara.maxCurrent; UploadData.Kp = commPara.pid_p; UploadData.Ki = commPara.pid_i; UploadData.Ke1 = commPara.pid_ke1; UploadData.Ke2 = commPara.pid_ke2; UploadData.reversse = commPara.reverse; UploadData.run2zero = commPara.run2zero; UploadData.traceMode = commPara.traceMode; } } finally { } }
private void button5_Click(object sender, EventArgs e) { if (comm.IsOpen) { CommProtocol.SendCmd(CommProtocol.CMD_SET_RESET_MCU); } Delay(500); comm.Close(); this.Close(); }
private void button1_Click(object sender, EventArgs e) { MotorPara.traceMode = CommProtocol.TRACE_MODE_NONE; if (radioButton4.Checked) { MotorPara.traceMode = CommProtocol.TRACE_MODE_PC; } else if (radioButton5.Checked) { MotorPara.traceMode = CommProtocol.TRACE_MODE_LOG; } else if (radioButton3.Checked) { MotorPara.traceMode = CommProtocol.TRACE_MODE_NONE; } CommProtocol.SendCmd(CommProtocol.CMD_SET_TRACE_MODE); }
private void para_Load(object sender, EventArgs e) { CommProtocol.SetTraceMode(CommProtocol.TRACE_MODE_PC); // Refresh data textBox1.Text = UploadData.Kp.ToString(); textBox5.Text = UploadData.Ki.ToString(); textBox8.Text = UploadData.Ke1.ToString(); textBox11.Text = UploadData.Ke2.ToString(); textBox17.Text = UploadData.maxCurrent.ToString(); textBox14.Text = UploadData.maxDegree.ToString(); radioButton4.Checked = false; radioButton5.Checked = false; radioButton3.Checked = false; if (UploadData.traceMode == CommProtocol.TRACE_MODE_LOG) { radioButton5.Checked = true; } else if (UploadData.traceMode == CommProtocol.TRACE_MODE_PC) { radioButton4.Checked = true; } else if (UploadData.traceMode == CommProtocol.TRACE_MODE_NONE) { radioButton3.Checked = true; } if (UploadData.run2zero > 0) { checkBox2.Checked = true; } if (UploadData.reversse > 0) { checkBox1.Checked = true; } InitTips(); }
public UInt16 GetFrame(ref byte[] buffer, ref byte type) { st_CommParaSet commPara = new st_CommParaSet(); int length = Marshal.SizeOf(commPara); int i; while (true) { if (FifoClass.FifoLen() >= length) { FifoClass.CheckFifo(ref buffer, 4); if (buffer[0] == CommProtocol.CMD_HEAD1 && buffer[1] == CommProtocol.CMD_HEAD2 && buffer[2] == CommProtocol.CMD_HEAD3 && buffer[3] == CommProtocol.CMD_HEAD4) { { for (i = 0; i < (length); i++) { buffer[i] = FifoClass.DeFifo(); } commPara = (st_CommParaSet)CommProtocol.BytesToStruct(buffer, commPara.GetType()); return((UInt16)length); } } else { FifoClass.DeFifo(); } } else { break; } } return(0); }
private void button6_Click(object sender, EventArgs e) { CommProtocol.SendCmd(CommProtocol.CMD_SET_ZERO_ANGLE); }