Ejemplo n.º 1
0
        //服务开启
        private void btn_Start_Click(object sender, EventArgs e)
        {
            try
            {
                if (test_connection() == false)
                {
                    listBox1.Items.Add("连接数据库失败");
                    listBox1.Items.Add("请确保数据库服务已开启,并且数据库连接填写正确");
                    return;
                }

                ServerSocketHelper.Init();
                ServerSocketHelper.StartListen(txt_ServerIp.Text.Trim(), txt_Port_SWS.Text.Trim());


                GPRSControl.DTU_NetServer.Init();
                // GPRSControl.GPRSControlNetServer.StartListen("192.168.1.8","5678");
                GPRSControl.DTU_NetServer.StartListen(txt_ServerIp.Text.Trim(), txt_port_DTU.Text.Trim());

                V88CommunicationThread.getInstance().Start();
                UdpV88Server.getInstance().StartListen(txt_ServerIp.Text.Trim(), txt_port_udp.Text.Trim());

                //心跳线程开启
                HeartbeatThread.Start();
                //主动发指令的线程开启
                ControlCommandThread.Start();
                //定时发指令的线程开启
                AutoCollectionThread.Start();

                save();

                btn_Start.Enabled = false;
                btn_Stop.Enabled  = true;

                ///关闭自动启动服务的定时器
                if (AutoStartTimer != null)
                {
                    AutoStartTimer.Stop();
                }
                listBox1.Items.Add("服务已成功开启");
            }
            catch (Exception ex)
            {
                ServerSocketHelper.Close();
                //  DTU_NetServer.Close();

                LogMg.AddError(ex);
                listBox1.Items.Add(ex.Message);
                //  MessageBox.Show(ex.Message);
            }
        }
Ejemplo n.º 2
0
        //服务停止
        private void btn_Stop_Click(object sender, EventArgs e)
        {
            try
            {
                ServerSocketHelper.Close();
                //  DTU_NetServer.Close();

                UdpV88Server.getInstance().close();

                btn_Start.Enabled = true;
                btn_Stop.Enabled  = false;
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }