示例#1
0
        public ConnectPort(PortManager portManager, PORTData portData)
        {
            bUseComm   = portData.bUseComm;
            bUseTelnet = portData.bUseTelnet;

            bIsStarted    = false;
            bIsStoped     = false;
            bIsActive     = false;
            bIsConnect    = false;
            bIsDisConnect = false;

            this.m_portManager = portManager;
            this.m_PortData    = portData;
            strEncode          = "Default";
        }
示例#2
0
        public void StatusChange(ConnectPort pConnect, string strPortName, string strText)
        {
            for (int i = 0; i < PORTDatas.Count; i++)
            {
                PORTData portData = PORTDatas[i];
                if (strPortName == portData.PortName)
                {
                    portData.bIsConnected    = pConnect.bIsConnect;
                    portData.bIsDisConnected = pConnect.bIsDisConnect;
                    portData.bIsLoged        = pConnect.bIsLogon;
                    portData.bIsStarted      = pConnect.bIsStarted;
                    portData.bIsStoped       = pConnect.bIsStoped;
                    portData.RunStatus       = strText;

                    this.MainForm.portListChangeStatus(portData);

                    break;
                }
            }
        }
示例#3
0
文件: frmConfig.cs 项目: skicomp/SITP
        private void DispPort()
        {
            string strPort = this.cmbPort.Text;

            for (int i = 0; i < mainForm.portManager.PORTDatas.Count; i++)
            {
                PORTData portData = mainForm.portManager.PORTDatas[i];
                if (strPort == portData.PortName)
                {
                    if (portData.bUseComm)
                    {
                        this.chkSerial.Checked = true;
                    }
                    else
                    {
                        this.chkSerial.Checked = false;
                    }

                    this.cmbData.Text   = portData.CommData;
                    this.cmbFlow.Text   = portData.CommFlow;
                    this.cmbParity.Text = portData.CommParity;
                    this.cmbSpeed.Text  = Convert.ToString(portData.nCommSpeed);
                    this.cmbStop.Text   = portData.CommStop;

                    if (portData.bUseTelnet)
                    {
                        this.chkTelnet.Checked = true;
                    }
                    else
                    {
                        this.chkTelnet.Checked = false;
                    }

                    this.txtTelnetAddr.Text = portData.TelnetServer;
                    this.txtID.Text         = portData.UserID;
                    this.txtPassword.Text   = portData.Password;
                    this.cmbEncode.Text     = portData.Encoding;
                }
            }
        }
示例#4
0
        public void Connect(PORTData portData)
        {
            try
            {
                this.m_PortData = portData;

                if (this.m_PortData.UserID == "")
                {
                    MessageBox.Show("시리얼연결 아이디가 정확하지 않습니다");
                    return;
                }
                if (this.m_PortData.Password == "")
                {
                    MessageBox.Show("시리얼연결 패스워드가 정확하지 않습니다");
                    return;
                }

                if (this.m_PortData.bUseComm)
                {
                    if (CommPort != null)
                    {
                        CommPort.Close();
                        CommPort = null;
                    }

                    CommPort          = new SerialPort(this.m_PortData.PortName);
                    CommPort.BaudRate = this.m_PortData.nCommSpeed;

                    if (this.m_PortData.CommData == "7 Bit")
                    {
                        CommPort.DataBits = 7;
                    }
                    else if (this.m_PortData.CommData == "8 Bit")
                    {
                        CommPort.DataBits = 8;
                    }

                    if (this.m_PortData.CommParity == "none")
                    {
                        CommPort.Parity = Parity.None;
                    }
                    else if (portData.CommParity == "odd")
                    {
                        CommPort.Parity = Parity.Odd;
                    }
                    else if (portData.CommParity == "even")
                    {
                        CommPort.Parity = Parity.Even;
                    }
                    else if (portData.CommParity == "mark")
                    {
                        CommPort.Parity = Parity.Mark;
                    }
                    else if (portData.CommParity == "space")
                    {
                        CommPort.Parity = Parity.Space;
                    }

                    if (this.m_PortData.CommStop == "1 bit")
                    {
                        CommPort.StopBits = StopBits.One;
                    }
                    else if (this.m_PortData.CommStop == "1.5 bit")
                    {
                        CommPort.StopBits = StopBits.OnePointFive;
                    }
                    else if (this.m_PortData.CommStop == "2 bit")
                    {
                        CommPort.StopBits = StopBits.Two;
                    }

                    if (this.m_PortData.CommFlow == "Xon/Xoff")
                    {
                        CommPort.Handshake = Handshake.XOnXOff;
                    }
                    else if (this.m_PortData.CommFlow == "hardware")
                    {
                        CommPort.Handshake = Handshake.None;
                    }
                    else if (this.m_PortData.CommFlow == "none")
                    {
                        CommPort.Handshake = Handshake.None;
                    }

                    CommPort.RtsEnable = true;

                    CommPort.DataReceived += new SerialDataReceivedEventHandler(CommPort_DataReceived);

                    CommPort.Open();
                    Thread.Sleep(2000);

                    if (CommPort == null || !CommPort.IsOpen)
                    {
                        DisConnect(false);
                        MessageBox.Show("시리얼포트 연결에 실패하였습니다.");
                        return;
                    }

                    MessageBox.Show("시리얼포트 연결에 성공하였습니다.");
                } //UseComm

                if (this.m_PortData.bUseTelnet)
                {
                    if (this.m_PortData.TelnetServer == "")
                    {
                        MessageBox.Show("텔렛주소가 정확하지 않습니다");
                        return;
                    }
                    if (this.m_PortData.UserID == "")
                    {
                        MessageBox.Show("텔렛 아이디가 정확하지 않습니다");
                        return;
                    }
                    if (this.m_PortData.Password == "")
                    {
                        MessageBox.Show("텔렛 패스워드가 정확하지 않습니다");
                        return;
                    }

                    if (tc != null && tc.IsConnected)
                    {
                        tc.Close();
                    }
                    tc = null;

                    tc           = new TelnetConnection(this.m_PortData.TelnetServer, 23);
                    tc.strEncode = this.strEncode;
                    Thread.Sleep(2000);

                    if (tc == null || !tc.IsConnected)
                    {
                        DisConnect(false);
                        MessageBox.Show("텔렛 연결에 실패하였습니다.");
                        return;
                    }

                    MessageBox.Show("텔렛 연결에 성공하였습니다.");
                } //Use Telnet

                bIsConnect    = true;
                bIsDisConnect = false;
                bIsLogon      = false;
                bIsStarted    = false;
                bIsStoped     = false;

                returnStatus("Connected");
            }
            catch (Exception ex)
            {
                DisConnect(false);
                MessageBox.Show("연결이 실패하였습니다:" + ex.ToString());
            }
        }
示例#5
0
        public void initialzeList()
        {
            int nPortCount = this.MainForm._clsInfo.nPortCnt;

            for (int i = 0; i < nPortCount; i++)
            {
                try
                {
                    string   strData = this.MainForm._clsInfo.arrPort[i];
                    string[] arrData = strData.Split(';');
                    if (arrData.Length < this.MainForm._clsInfo.nPortSplitCnt)
                    {
                        continue;
                    }
                    string strTemp = "";

                    PORTData portData = new PORTData();

                    portData.Seq = Convert.ToInt32(arrData[0]);
                    strTemp      = arrData[1];
                    if (strTemp == "Empty")
                    {
                        portData.PortName = "";
                    }
                    else
                    {
                        portData.PortName = strTemp;
                    }
                    strTemp = arrData[2];
                    if (strTemp == "Empty")
                    {
                        portData.RunStatus = "";
                    }
                    else
                    {
                        portData.RunStatus = strTemp;
                    }
                    strTemp = arrData[3];
                    if (strTemp == "Empty")
                    {
                        portData.Category = "";
                    }
                    else
                    {
                        portData.Category = strTemp;
                    }
                    strTemp = arrData[4];
                    if (strTemp == "Empty")
                    {
                        portData.FertCode = "";
                    }
                    else
                    {
                        portData.FertCode = strTemp;
                    }
                    strTemp = arrData[5];
                    if (strTemp == "Empty")
                    {
                        portData.FertSN = "";
                    }
                    else
                    {
                        portData.FertSN = strTemp;
                    }
                    strTemp = arrData[6];
                    if (strTemp == "Empty")
                    {
                        portData.UmpSN = "";
                    }
                    else
                    {
                        portData.UmpSN = strTemp;
                    }
                    strTemp = arrData[7];
                    if (strTemp == "Empty")
                    {
                        portData.ECP1SN = "";
                    }
                    else
                    {
                        portData.ECP1SN = strTemp;
                    }
                    strTemp = arrData[8];
                    if (strTemp == "Empty")
                    {
                        portData.ECP2SN = "";
                    }
                    else
                    {
                        portData.ECP2SN = strTemp;
                    }
                    strTemp = arrData[9];
                    if (strTemp == "Empty")
                    {
                        portData.ECP3SN = "";
                    }
                    else
                    {
                        portData.ECP3SN = strTemp;
                    }
                    strTemp = arrData[10];
                    if (strTemp == "check")
                    {
                        portData.Au_Rssi = true;
                    }
                    else
                    {
                        portData.Au_Rssi = false;
                    }
                    strTemp = arrData[11];
                    if (strTemp == "check")
                    {
                        portData.Au_311 = true;
                    }
                    else
                    {
                        portData.Au_311 = false;
                    }
                    strTemp = arrData[12];
                    if (strTemp == "Empty")
                    {
                        portData.IEMISN = "";
                    }
                    else
                    {
                        portData.IEMISN = strTemp;
                    }
                    strTemp = arrData[13];
                    if (strTemp == "check")
                    {
                        portData.USIM = true;
                    }
                    else
                    {
                        portData.USIM = false;
                    }
                    strTemp = arrData[14];
                    if (strTemp == "check")
                    {
                        portData.CHOnly = true;
                    }
                    else
                    {
                        portData.CHOnly = false;
                    }
                    strTemp        = arrData[15];
                    portData.Alarm = strTemp;
                    strTemp        = arrData[16];
                    if (strTemp == "Empty")
                    {
                        portData.TelnetServer = "";
                    }
                    else
                    {
                        portData.TelnetServer = strTemp;
                    }
                    strTemp = arrData[17];
                    if (strTemp == "Empty")
                    {
                        portData.StartTime = "";
                    }
                    else
                    {
                        portData.StartTime = strTemp;
                    }
                    strTemp = arrData[18];
                    if (strTemp == "Empty")
                    {
                        portData.EndTime = "";
                    }
                    else
                    {
                        portData.EndTime = strTemp;
                    }
                    strTemp = arrData[19];
                    if (strTemp == "Empty")
                    {
                        portData.WorkPC = "";
                    }
                    else
                    {
                        portData.WorkPC = strTemp;
                    }
                    strTemp = arrData[20];
                    if (strTemp == "Empty")
                    {
                        portData.Result = "";
                    }
                    else
                    {
                        portData.Result = strTemp;
                    }

                    portData.bIsConnected    = false;
                    portData.bIsDisConnected = true;
                    portData.bIsLoged        = false;
                    portData.bIsStarted      = false;
                    portData.bIsStoped       = true;

                    portData.portMan = null;

                    PORTDatas.Add(portData);
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.ToString());
                }
            }

            int nCommCount = this.MainForm._clsInfo.nCommCnt;

            for (int i = 0; i < nCommCount; i++)
            {
                try
                {
                    string   strData = this.MainForm._clsInfo.arrComm[i];
                    string[] arrData = strData.Split(';');
                    if (arrData.Length < this.MainForm._clsInfo.nCommSplitCnt)
                    {
                        continue;
                    }

                    string strName = arrData[0];
                    string strTemp = "";

                    for (int k = 0; k < PORTDatas.Count; k++)
                    {
                        strTemp = PORTDatas[k].PortName;
                        if (strName == strTemp)
                        {
                            strTemp = arrData[1];
                            if (strTemp == "checked")
                            {
                                PORTDatas[k].bUseComm = true;
                            }
                            else
                            {
                                PORTDatas[k].bUseComm = false;
                            }
                            strTemp = arrData[2];
                            PORTDatas[k].nCommSpeed = Convert.ToInt32(strTemp);
                            strTemp = arrData[3];
                            if (strTemp == "Empty")
                            {
                                PORTDatas[k].CommData = "";
                            }
                            else
                            {
                                PORTDatas[k].CommData = strTemp;
                            }
                            strTemp = arrData[4];
                            if (strTemp == "Empty")
                            {
                                PORTDatas[k].CommParity = "";
                            }
                            else
                            {
                                PORTDatas[k].CommParity = strTemp;
                            }
                            strTemp = arrData[5];
                            if (strTemp == "Empty")
                            {
                                PORTDatas[k].CommStop = "";
                            }
                            else
                            {
                                PORTDatas[k].CommStop = strTemp;
                            }
                            strTemp = arrData[6];
                            if (strTemp == "Empty")
                            {
                                PORTDatas[k].CommFlow = "";
                            }
                            else
                            {
                                PORTDatas[k].CommFlow = strTemp;
                            }
                            strTemp = arrData[7];
                            if (strTemp == "Empty")
                            {
                                PORTDatas[k].TelnetServer = "";
                            }
                            else
                            {
                                PORTDatas[k].TelnetServer = strTemp;
                            }
                            strTemp = arrData[8];
                            if (strTemp == "checked")
                            {
                                PORTDatas[k].bUseTelnet = true;
                            }
                            else
                            {
                                PORTDatas[k].bUseTelnet = false;
                            }
                            strTemp = arrData[9];
                            if (strTemp == "Empty")
                            {
                                PORTDatas[k].UserID = "";
                            }
                            else
                            {
                                PORTDatas[k].UserID = strTemp;
                            }
                            strTemp = arrData[10];
                            if (strTemp == "Empty")
                            {
                                PORTDatas[k].Password = "";
                            }
                            else
                            {
                                PORTDatas[k].Password = strTemp;
                            }
                            strTemp = arrData[11];
                            if (strTemp == "Empty")
                            {
                                PORTDatas[k].Encoding = "Default";
                            }
                            else
                            {
                                PORTDatas[k].Encoding = strTemp;
                            }
                        }
                    }
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.ToString());
                }
            }

            ////////////////////////////////////////////////////
            /// PortData Initializing
            ////////////////////////////////////////////////////
            for (int k = 0; k < nPortCount; k++)
            {
                try
                {
                    ConnectPort clsPort = new ConnectPort(this, PORTDatas[k]);
                    clsPort.ProcessRun += new ProcessRunHandler(ProcessRun_Return);
                    ConnectPorts.Add(clsPort);
                    PORTDatas[k].portMan = clsPort;
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.ToString());
                }
            }
        } //class initialize