Ejemplo n.º 1
0
        //Ping
        private void btnPingDevice_Click(object sender, EventArgs e)
        {
            //save compare config info
            expressions.Add("EPON" + " Software: " + tBx_EponSoftware.Text.ToString() + " FPGA: " + tBx_EponFPGA.Text.ToString()
                            + " GPON" + " Software: " + tBx_GponSoftware.Text.ToString() + " FPGA: " + " " + DateTime.Now.ToString("yyyy-MM-dd-HH-mm-ss-fff"));

            Thread.Sleep(10);
            writeInfo();

            ShowStatusBar(string.Empty, true);

            string ipAddress = tbxDeviceIP.Text.Trim();

            bool isValidIpA = UniversalStatic.ValidateIP(ipAddress);

            if (!isValidIpA)
            {
                throw new Exception("The Device IP is invalid !!");
            }

            isValidIpA = UniversalStatic.PingTheDevice(ipAddress);
            if (isValidIpA)
            {
                ShowStatusBar("The device is active", true);
            }
            else
            {
                ShowStatusBar("Could not read any response", false);
            }
        }
Ejemplo n.º 2
0
 private void pnlHeader_Paint(object sender, PaintEventArgs e)
 {
     UniversalStatic.DrawLineInFooter(pnlHeader, Color.FromArgb(204, 204, 204), 2);
 }
Ejemplo n.º 3
0
        //btnConnect_Click

        private void btnConnect_Click(object sender, EventArgs e)
        {
            try
            {
                this.Cursor = Cursors.WaitCursor;
                ShowStatusBar(string.Empty, true);

                if (IsDeviceConnected)
                {
                    IsDeviceConnected = false;
                    this.Cursor       = Cursors.Default;

                    return;
                }

                string ipAddress = tbxDeviceIP.Text.Trim();
                string port      = tbxPort.Text.Trim();
                string login     = tbxLogin.Text.Trim();
                string password  = tbxPassword.Text.Trim();
                if (ipAddress == string.Empty || port == string.Empty || login == string.Empty || password == string.Empty)
                {
                    throw new Exception("The Device IP Port Login and Password is mandotory !!");
                }

                //int portNumber = 23;
                //if (!int.TryParse(port, out portNumber))
                //    throw new Exception("Not a valid port number");

                bool isValidIpA = UniversalStatic.ValidateIP(ipAddress);
                if (!isValidIpA)
                {
                    throw new Exception("The Device IP is invalid !!");
                }

                isValidIpA = UniversalStatic.PingTheDevice(ipAddress);
                if (!isValidIpA)
                {
                    throw new Exception("The device at " + ipAddress + ":" + port + " did not respond!!");
                }

                tcpclient         = new TcpClient(ipAddress, int.Parse(port)); // connect server
                stream            = tcpclient.GetStream();                     // get net stream
                IsDeviceConnected = true;

                //objZkeeper = new ZkemClient(RaiseDeviceEvent);
                //IsDeviceConnected = objZkeeper.Connect_Net(ipAddress, portNumber);
                //string result = string.Empty;
                if (IsDeviceConnected && stream.DataAvailable)     //connected and receive data
                {
                    Byte[] output         = new Byte[1024];
                    String responseoutput = String.Empty;
                    Byte[] cmd            = System.Text.Encoding.ASCII.GetBytes(""); //"\n"
                    stream.Write(cmd, 0, cmd.Length);

                    cmd = System.Text.Encoding.ASCII.GetBytes("get device info" + "\r\n");       //first try to get info
                    stream.Write(cmd, 0, cmd.Length);

                    Thread.Sleep(100);
                    Int32 bytes = stream.Read(output, 0, output.Length);
                    responseoutput = System.Text.Encoding.ASCII.GetString(output, 0, bytes);
                    // rtbShowInfo.Text += responseoutput;

                    Regex objToMatch = new Regex("Login:"******"\r\n");
                        stream.Write(cmd, 0, cmd.Length);
                    }
                    Thread.Sleep(100);
                    bytes          = stream.Read(output, 0, output.Length);
                    responseoutput = System.Text.Encoding.ASCII.GetString(output, 0, bytes);
                    //  rtbShowInfo.Text += responseoutput;

                    objToMatch = new Regex("Passwd:");
                    if (objToMatch.IsMatch(responseoutput))
                    {
                        cmd = System.Text.Encoding.ASCII.GetBytes(password + "\r\n");
                        stream.Write(cmd, 0, cmd.Length);
                    }
                    Thread.Sleep(100);
                    bytes          = stream.Read(output, 0, output.Length);
                    responseoutput = System.Text.Encoding.ASCII.GetString(output, 0, bytes);
                    // rtbShowInfo.Text += responseoutput;

                    objToMatch = new Regex("-->");
                    if (objToMatch.IsMatch(responseoutput))
                    {
                        cmd = System.Text.Encoding.ASCII.GetBytes("get device info" + "\r\n");
                        stream.Write(cmd, 0, cmd.Length);
                    }
                    Thread.Sleep(100);
                    bytes          = stream.Read(output, 0, output.Length);
                    responseoutput = System.Text.Encoding.ASCII.GetString(output, 0, bytes);
                    //rtbShowInfo.Text += responseoutput;



                    //save info log
                    StreamWriter file = new StreamWriter("log.txt", true);
                    file.WriteLine(DateTime.Now.ToString("yyyy-MM-dd-HH-mm-ss-fff") + "        " + responseoutput);
                    file.Close();
                }
            }
            catch (Exception ex)
            {
                ShowStatusBar(ex.Message, false);
                //rtbShowInfo.Text += "Device has been connected, and connot be connected twice at one time!!";
            }
            this.Cursor = Cursors.Default;
            Thread.Sleep(200);
        }