private void ClosePort_Click(object sender, EventArgs e) { int port; string temp; ComboBox_AlreadyOpenCOM.Refresh(); RefreshStatus(); try { if (ComboBox_AlreadyOpenCOM.SelectedIndex < 0) { MessageBox.Show("Please Choose COM Port to close", "Information"); } else { temp = ComboBox_AlreadyOpenCOM.SelectedItem.ToString(); port = Convert.ToInt32(temp.Substring(3, temp.Length - 3)); fCmdRet = StaticClassReaderB.CloseSpecComPort(port); if (fCmdRet == 0) { ComboBox_AlreadyOpenCOM.Items.RemoveAt(0); if (ComboBox_AlreadyOpenCOM.Items.Count != 0) { temp = ComboBox_AlreadyOpenCOM.SelectedItem.ToString(); port = Convert.ToInt32(temp.Substring(3, temp.Length - 3)); StaticClassReaderB.CloseSpecComPort(port); fComAdr = 0xFF; StaticClassReaderB.OpenComPort(port, ref fComAdr, fBaud, ref frmcomportindex); fOpenComIndex = frmcomportindex; RefreshStatus(); Button3_Click(sender, e); //自动执行读取写卡器信息 } } else { MessageBox.Show("Serial Communication Error", "Information"); } } } finally { } if (ComboBox_AlreadyOpenCOM.Items.Count != 0) { ComboBox_AlreadyOpenCOM.SelectedIndex = 0; } else { fOpenComIndex = -1; ComboBox_AlreadyOpenCOM.Items.Clear(); ComboBox_AlreadyOpenCOM.Refresh(); RefreshStatus(); button2.Enabled = false; button2.Text = "Остановить"; ComOpen = false; timer1.Enabled = false; } }
//复位窗口 private void reset_view() { ComOpen = false; fCmdRet = 30; fOpenComIndex = -1; ComboBox_AlreadyOpenCOM.Items.Clear(); ComboBox_AlreadyOpenCOM.Refresh(); Button3.Enabled = false; ComOpen = false; Timer_Scan.Enabled = false; fIsInventoryScan = false; fIsInvoke = false; button2.Enabled = false; button2.Text = "开始"; ClosePort.Enabled = false; ComboBox_baud2.SelectedIndex = 3;//初始化波特率选项 }