bool InitialComportATG() { string strSQL = "select" + " t.comp_id,t.comport_no,t.comport_setting" + " from tas.VIEW_ATG_CONFIG_COMPORT t " + " order by t.atg_id"; DataSet vDataset = null; DataTable dt; bool vRet = false; try { if (OraDb.OpenDyns(strSQL, "TableName", ref vDataset)) { dt = vDataset.Tables["TableName"]; CRComport = new Comport[dt.Rows.Count]; crSerialPort = new SerialPort[dt.Rows.Count]; for (int i = 0; i < dt.Rows.Count; i++) { atgSerialPort[i] = new SerialPort(); ATGComport[i] = new Comport(this, ref crSerialPort[i], Convert.ToDouble(dt.Rows[i]["comp_id"].ToString())); ATGComport[i].InitialPort(); } } vRet = true; } catch (Exception exp) { LogFile.WriteErrLog(exp.Message); } vDataset = null; dt = null; return(vRet); }
bool OpenDys(string pStrSQL, ref OleDbDataReader pDataReader) { OleDbCommand oleCommand; bool vCheck = false; if (oleConn.State == ConnectionState.Open) { try { oleCommand = new OleDbCommand(pStrSQL, oleConn); oleCommand.CommandTimeout = 1; pDataReader = oleCommand.ExecuteReader(); vCheck = true; } catch (Exception exp) { Logfile logFile = new Logfile(); logFile.WriteErrLog("[ExecuteSQL]" + pStrSQL); logFile.WriteErrLog("[ExecuteSQL]" + exp.Message); logFile = null; } } return(vCheck); }
private bool OpenPort() { bool vIsAvailable = true; try { if (comportBuffer.IsTCP) { comportMsg = "Open comport =" + comportBuffer.IP_Address + " : " + comportBuffer.IP_Port + "."; Application.DoEvents(); IPGlobalProperties ipGlobalProperties = IPGlobalProperties.GetIPGlobalProperties(); TcpConnectionInformation[] tcpConnInfoArray = ipGlobalProperties.GetActiveTcpConnections(); foreach (TcpConnectionInformation tcpi in tcpConnInfoArray) { if (tcpi.LocalEndPoint.Port == comportBuffer.IP_Port) { vIsAvailable = false; break; } } if (vIsAvailable) { tcpPort = new TcpClient(comportBuffer.IP_Address, comportBuffer.IP_Port); //tc = new TcpClient("192.168.1.193", 7734); tcpPort.SendTimeout = 1000; stm = tcpPort.GetStream(); comportMsg = "Comport =" + comportBuffer.IP_Address + " : " + comportBuffer.IP_Port + " Open successfull."; RaiseEvents(comportMsg); comportBuffer.IsOpen = true; } } else//serial port { if (Sp.IsOpen) { //ComportMember.IsOpen = true; comportMsg = "Port is opened by another application!"; RaiseEvents(comportMsg); return(true); } comportMsg = "Open comport =" + comportBuffer.PortNo + ":" + comportBuffer.PortSetting + "."; RaiseEvents(comportMsg); string[] spli = comportBuffer.PortSetting.Split(','); //9600,N,8,1 -> baud,parity,data,stop if (spli.Length != 4) { return(false); } //mSp = new SerialPort(); //mSp.DataReceived += SerialPort_DataReceived; Sp.PortName = comportBuffer.PortNo; Sp.BaudRate = Int32.Parse(spli[0]); switch (spli[1].ToString().ToUpper().Trim()) { case "E": Sp.Parity = Parity.Even; break; case "M": Sp.Parity = Parity.Mark; break; case "O": Sp.Parity = Parity.Odd; break; case "S": Sp.Parity = Parity.Space; break; default: Sp.Parity = Parity.None; break; } Sp.DataBits = Int32.Parse(spli[2]); switch (spli[3].Trim()) { case "1": Sp.StopBits = StopBits.One; break; case "1.5": Sp.StopBits = StopBits.OnePointFive; break; case "2": Sp.StopBits = StopBits.Two; break; default: Sp.StopBits = StopBits.None; break; } Sp.ReadTimeout = 100; Sp.WriteTimeout = 500; Sp.Open(); Sp.DiscardInBuffer(); Sp.DiscardOutBuffer(); } comportBuffer.IsOpen = true; comportBuffer.IsIdle = true; connect = true; comportMsg = "Comport =" + comportBuffer.PortNo + ":" + comportBuffer.PortSetting + " Open successfull."; RaiseEvents(comportMsg); } catch (Exception exp) { //Addlistbox(exp.Message.ToString()); if (countWriteLog > 120) { countWriteLog = 0; logFile.WriteErrLog(exp.ToString()); comportBuffer.IsOpen = false; } else { countWriteLog += 1; } return(false); } InitialCharacterTime(); return(true); }