public bool connectDevice() { if (Code == 11) { return(false); } try { string comname = SerialHelper.GetOneCom(); ReadDone = false; if (comname.Length > 0) { SerialPortFixer.Execute(comname); spt = new SerialPortTran(comname, false); return(true); } else { //throw new Exception("can not found any device connected"); _tracing.Error("can not found any device connected"); return(false); } } catch { return(false); } }
public bool disconnectDevice() { ReadDone = false; try { if (spt != null) { spt.Dispose(); } spt = null; return(true); } catch { return(false); } }
public string Report() { { SerialPortTran spt = this.ITAG.spt; var dinfo = new DeviceInfo(spt.SendGetInfo()); string filename = dinfo.sn + ".txt"; if (File.Exists(filename)) { File.Delete(filename); } StreamWriter sw = new StreamWriter(filename); Console.WriteLine("===============" + DateTime.Now.ToString() + "==========================================================================="); sw.WriteLine("===============" + DateTime.Now.ToString() + "==========================================================================="); string deviceinfo = dinfo.ToString(); Console.WriteLine(deviceinfo); sw.WriteLine(deviceinfo); var dsetting = new DeviceSetting(spt.SentGetSetting()); string devicesetting = dsetting.ToString(); Console.WriteLine(devicesetting); sw.WriteLine(devicesetting); string temps = spt.SentGetRecords(); //Console.WriteLine(temps); string s = TempSenHelper.GetTempListCString(temps, spt.ItemCount, dinfo.RecordDateTime, dsetting.recordIntervalInSecond); sw.WriteLine(s); //Console.WriteLine(s); Console.WriteLine("===============end" + DateTime.Now.ToString() + "==========================================================================="); sw.WriteLine("===============end" + DateTime.Now.ToString() + "==========================================================================="); sw.Close(); this.textBox1.Text = File.ReadAllText(filename, Encoding.UTF8); Process vProcess = Process.Start(Directory.GetCurrentDirectory() + "\\" + filename); return(""); } }