private void toolStripButtonConnect_Click(object sender, EventArgs e) { if ("连接" == toolStripButtonConnect.Text) { /* 开启流速传感器 */ bool bRet = m_flowSensor.Open(toolStripComboBoxCom.Text); toolStripButtonStart.Enabled = bRet; //toolStripButtonLoadPresure.Enabled = !bRet; //toolStripButtonLoadFlow.Enabled = !bRet; //toolStripButtonSave.Enabled = !bRet; //toolStripButtonClear.Enabled = !bRet; toolStripButtonScan.Enabled = !bRet; toolStripComboBoxCom.Enabled = !bRet; toolStripButtonConnect.Text = bRet ? "断开" : "连接"; toolStripButtonCalibration1L.Enabled = bRet; toolStripButtonCalibration3L.Enabled = bRet; toolStripButtonVerification1L.Enabled = bRet; toolStripButtonVerification3L.Enabled = bRet; toolStripButtonFirmwareUpdate.Enabled = bRet; /* 尝试清空数据队列 */ TryClearDataQueue(); } else //if ("断开" == toolStripButtonConnect.Text) { /* 关闭流速传感器 */ m_flowSensor.Close(); toolStripButtonStart.Enabled = false; toolStripButtonLoadPresure.Enabled = true; toolStripButtonLoadFlow.Enabled = true; toolStripButtonSaveFlow.Enabled = true; toolStripButtonClear.Enabled = true; toolStripButtonScan.Enabled = true; toolStripComboBoxCom.Enabled = true; toolStripButtonCalibration1L.Enabled = false; toolStripButtonCalibration3L.Enabled = false; toolStripButtonVerification1L.Enabled = false; toolStripButtonVerification3L.Enabled = false; toolStripButtonFirmwareUpdate.Enabled = false; toolStripButtonConnect.Text = "连接"; toolStripButtonStart.Text = "开始"; /* 取消监听流量传感器数据收取事件 */ m_flowSensor.PresureRecved -= OnPresureRecved; /* 停止刷新定时器 */ m_refreshTimer.Stop(); /* 尝试清空数据队列 */ TryClearDataQueue(); } }
void FileTransProtocol_EndOfTransmit(object sender, EventArgs e) { SetEndTransmit(); TimeSpan ts = DateTime.Now - startTime; ShowTextReprot(string.Format("传输完成,用时{0:D2}:{1:D2}:{2:D2}.{3:D3}. 正在自动重启下位机...", ts.Hours, ts.Minutes, ts.Seconds, ts.Milliseconds)); this.BeginInvoke(new Action <FormFirmwareUpdate>(async(obj) => { m_flowSensor.DataRecved -= OnUartDataRecved; bool bRet = await m_flowSensor.StartOTARebootAsync(); if (bRet) { /* 重启前关闭串口 */ m_flowSensor.Close(); /* 等待重启完成 */ await Task.Delay(10000); /* 重新开启串口 */ bRet = m_flowSensor.Open(); if (bRet) { /* 获取固件版本号 */ string ver = await m_flowSensor.BoardVersionAsync(); ShowTextReprot(string.Format("传输完成,用时{0:D2}:{1:D2}:{2:D2}.{3:D3}. 下位机重启完成,固件版本号: " + ver, ts.Hours, ts.Minutes, ts.Seconds, ts.Milliseconds)); } else { ShowTextReprot(string.Format("传输完成,用时{0:D2}:{1:D2}:{2:D2}.{3:D3}. 获取下位机版本号失败!", ts.Hours, ts.Minutes, ts.Seconds, ts.Milliseconds)); } buttonStart.Text = "关闭"; } else { ShowTextReprot(string.Format("传输完成,用时{0:D2}:{1:D2}:{2:D2}.{3:D3}. 自动重启下位机失败!", ts.Hours, ts.Minutes, ts.Seconds, ts.Milliseconds)); } }), this); }