private void BTN_IDN3_Click(object sender, EventArgs e) { if (!lamda.Connect) { return; } Txt_Lamda.Text = ""; mainform.strReadPower[2] = ""; strReadLamda = ""; lamda.IDN(); DateTime NowTime = DateTime.Now; TimeSpan WaitTime = new TimeSpan(0, 0, 0, 0, 500); DateTime EndTime = NowTime.Add(WaitTime); while (NowTime <= EndTime) { Application.DoEvents(); if (mainform.strReadPower[2] != "") { Txt_Lamda.Text = mainform.strReadPower[2]; break; } NowTime = DateTime.Now; } }
private void DeviceConnect() { oda = new ODA(ODA_, ini.Read("POWER1", "PortName", ""), Convert.ToInt32(ini.Read("POWER1", "BaudRate", "9600"))); oda.Open(); oda.IDN(); DateTime NowTime = DateTime.Now; TimeSpan WaitTime = new TimeSpan(0, 0, 0, 0, 500); DateTime EndTime = NowTime.Add(WaitTime); while (EndTime >= NowTime) { Application.DoEvents(); if (oda.Connect) { break; } NowTime = DateTime.Now; } sorensen = new SorensenXG(Sorensen_, ini.Read("POWER2", "PortName", ""), Convert.ToInt32(ini.Read("POWER2", "BaudRate", "9600"))); sorensen.Open(); sorensen.ADR(); sorensen.IDN(); NowTime = DateTime.Now; EndTime = NowTime.Add(WaitTime); while (EndTime >= NowTime) { Application.DoEvents(); if (sorensen.Connect) { break; } NowTime = DateTime.Now; } lamda = new TDKLamdaGENH(Lamda_, ini.Read("POWER3", "PortName", ""), Convert.ToInt32(ini.Read("POWER3", "BaudRate", "9600"))); lamda.Open(); lamda.ADR(); lamda.IDN(); NowTime = DateTime.Now; EndTime = NowTime.Add(WaitTime); while (EndTime >= NowTime) { Application.DoEvents(); if (lamda.Connect) { break; } NowTime = DateTime.Now; } }