예제 #1
0
        //private void ComHandler()
        //{
        //    // Console.WriteLine(DateTime.Now.ToLongTimeString() + " SiemensCom => Thread started : " + _destIP);
        //    while (!stopThread)
        //    {
        //        try
        //        {
        //            { // forever
        //                try
        //                {
        //                    if (_s7client == null)
        //                        OpenSockets();

        //                    if (_s7client != null && !_s7client.Connected)
        //                        CloseSockets();
        //                }
        //                catch (Exception ex)
        //                {
        //                    Console.WriteLine("ComHandler()" + ex.Message);
        //                    // error ??
        //                }
        //                Thread.Sleep(50);
        //            }
        //        }
        //        catch
        //        {
        //            // Console.WriteLine(DateTime.Now.ToLongTimeString() + " SiemensCom => Thread abborted : " + _destIP);
        //        }

        //    }
        //}

        private void OpenSockets()
        {
            //Console.WriteLine(DateTime.Now.ToLongTimeString() + " SiemensCom => OpenSockets : " + _destIP);
            try
            {
                lock (threading)
                {
                    _s7client = new Sharp7.S7Client();
                    int result = _s7client.ConnectTo(_destIP, 0, 2);
                }
            }
            catch //(Exception ex)
            {
                //Console.WriteLine("SiemensCom : OpenSockets failed -> " + ex.Message);
                CloseSockets();
            }
        }
예제 #2
0
        private void toolStripButton3_Click(object sender, EventArgs e)
        {
            int Result;
            int Rack = System.Convert.ToInt32(Loader._Instance.TxtRack.Text);
            int Slot = System.Convert.ToInt32(Loader._Instance.TxtSlot.Text);

            Result = Client.ConnectTo(Loader._Instance.TxtIP.Text, Rack, Slot);
            Client.ShowResult(Result);
            if (Result == 0)
            {
                Loader._Instance.output.Text           = Loader._Instance.output.Text + " PDU Negotiated : " + Client.PduSizeNegotiated.ToString();
                Loader._Instance.TxtIP.Enabled         = false;
                Loader._Instance.TxtRack.Enabled       = false;
                Loader._Instance.TxtSlot.Enabled       = false;
                Loader._Instance.ConnectBtn.Enabled    = false;
                Loader._Instance.DisconnectBtn.Enabled = true;
                Loader._Instance.Status.Value          = 100;
            }
        }
예제 #3
0
        private void ConnectBtn_Click(object sender, EventArgs e)
        {
            int Result;
            int Rack = System.Convert.ToInt32(TxtRack.Text);
            int Slot = System.Convert.ToInt32(TxtSlot.Text);

            Result = Client.ConnectTo(TxtIP.Text, Rack, Slot);
            Client.ShowResult(Result);
            if (Result == 0)
            {
                output.Text           = output.Text + " PDU Negotiated : " + Client.PduSizeNegotiated.ToString();
                TxtIP.Enabled         = false;
                TxtRack.Enabled       = false;
                TxtSlot.Enabled       = false;
                ConnectBtn.Enabled    = false;
                DisconnectBtn.Enabled = true;
                Status.Value          = 100;
                Connected             = true;
            }
        }