Exemple #1
0
        private void mainThread()
        {
            //启动Console信息同步进程
            ConsoleThread = new ExThread(ConsoleFunc);
            ConsoleThread.Start();

            MyConsole.Add("系统启动中...");

            MyConsole.Add(string.Format("服务器地址:{0}", UdpSever.ServerAddress));
            MyConsole.Add(string.Format("设备数:{0}", UdpSever.DeviceNum));
            MyConsole.Add(string.Format("寄存器数:{0}", UdpSever.RegisterNum));
            MyConsole.Add(string.Format("单帧数据长度:{0}", UdpSever.FrameLen));
            MyConsole.Add(string.Format("心跳周期:{0}秒", UdpSever.HeartCycle));
            MyConsole.Add(string.Format("重发次数:{0}", UdpSever.RepeatNum));
            MyConsole.Add(string.Format("超时时间:{0}", UdpSever.ResponseTimeout));
            MyConsole.Add(string.Format("响应帧缓冲池容量:{0}", UdpSever.RESPONSE_MAX_LEN));
            MyConsole.Add(string.Format("设备总数:{0}", UdpSever.DeviceNum));

            //测试ModbusTcp服务器连接
            Ping      pingSender = new Ping();
            PingReply reply      = pingSender.Send("192.168.250.102", 100);//第一个参数为ip地址,第二个参数为ping的时间

            if (reply.Status == IPStatus.Success)
            {
                MyConsole.Add("ModbusTcp服务器连接成功!", Color.Green);
            }
            else
            {
                MyConsole.Add("ModbusTcp服务器连接失败!", Color.Red);
            }

            #region 获取本机IP,自动开启Dbus服务器
            string      name      = Dns.GetHostName();
            IPAddress[] ipadrlist = Dns.GetHostAddresses(name);
            foreach (IPAddress ipa in ipadrlist)
            {
                if (ipa.AddressFamily == AddressFamily.InterNetwork)
                {
                    MyConsole.Add(string.Format("本机IP:[{0}]", ipa));
                    UdpSever.ipaddress = ipa;
                }
            }

            //自动启动服务器
            UdpSever.Resault rs = UdpSever.Start();
            //更新界面
            udpConfigForm_MyEvent();
            #endregion

            #region 启动任务界面
            this.Invoke(new MethodInvoker(delegate
            {
                taskForm.TopLevel = false;
                taskForm.Parent   = splitContainer3.Panel1;
                taskForm.Show();  //弹出这个窗口
                taskForm.Focus(); //激活显示
            }));
            #endregion
        }
Exemple #2
0
        private void MDIParent1_Load(object sender, EventArgs e)
        {
            //初始化系统参数
            XmlHelper.InitDebug();

            int delay = 30;

            UdpSever.Shell.WriteNotice(delay, "系统消息", "系统启动...");
            UdpSever.Shell.WriteNotice(delay, "系统消息", "加载调试信息...");

            UdpSever.Shell.WriteNotice(delay, "系统消息", "获取本机IP...");


            UdpSever.Shell.WriteNotice(delay, "系统消息", "加载服务器配置...");

            UdpSever.Shell.WriteLine(delay, "[服务器][服务器地址][ServerAddress][{0}]", UdpSever.ServerAddress);
            UdpSever.Shell.WriteLine(delay, "[服务器][设备数][DeviceNum][{0}]", UdpSever.DeviceNum);
            UdpSever.Shell.WriteLine(delay, "[服务器][寄存器数][RegisterNum][{0}]", UdpSever.RegisterNum);
            UdpSever.Shell.WriteLine(delay, "[服务器][单帧数据长度][FrameLen][{0}]", UdpSever.FrameLen);
            UdpSever.Shell.WriteLine(delay, "[服务器][心跳周期][HeartCycle][{0}]秒", UdpSever.HeartCycle);
            UdpSever.Shell.WriteLine(delay, "[服务器][重发次数][RepeatNum][{0}]", UdpSever.RepeatNum);
            UdpSever.Shell.WriteLine(delay, "[服务器][超时时间][ResponseTimeout][{0}]", UdpSever.ResponseTimeout);
            UdpSever.Shell.WriteLine(delay, "[服务器][响应帧缓冲池容量][RESPONSE_MAX_LEN][{0}]", UdpSever.RESPONSE_MAX_LEN);
            UdpSever.Shell.WriteLine(delay, "[服务器][设备总数][DeviceNum][{0}]\r\n", UdpSever.DeviceNum);

            #region 获取本机IP,自动开启服务器
            string      name      = Dns.GetHostName();
            IPAddress[] ipadrlist = Dns.GetHostAddresses(name);
            foreach (IPAddress ipa in ipadrlist)
            {
                if (ipa.AddressFamily == AddressFamily.InterNetwork)
                {
                    UdpSever.ipaddress = ipa;
                    UdpSever.Shell.WriteNotice(delay, "系统消息", "本机IP:[{0}]", ipa.ToString());

                    string str = Ini.Read("网络配置", "Port");
                    if (str != "null")
                    {
                        UdpSever.port = int.Parse(str);
                    }
                    UdpSever.Shell.WriteNotice(delay, "系统消息", "本机端口:[{0}]", str);
                }
            }
            //自动启动服务器
            UdpSever.Resault rs = UdpSever.Start();
            //更新界面
            udpConfigForm_MyEvent();
            #endregion


            treeView1.Nodes.Clear();
        }
Exemple #3
0
 // 启动或停止服务
 private void UdpStartStop(object sender, EventArgs e)
 {
     if (UdpSever.State)//启动状态
     {
         UdpSever.Resault rs = UdpSever.Stop();
         if (rs.Reault)
         {
             buttonStart.Text     = "启动";
             textBoxIP.ReadOnly   = false;
             textBoxPort.ReadOnly = false;
             //MessageBox.Show(rs.Message, "提示");
             this.Close();
         }
         else
         {
             MessageBox.Show(rs.Message, "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
         }
     }
     else//停止状态
     {
         UdpSever.ipaddress = IPAddress.Parse(textBoxIP.Text);
         UdpSever.port      = int.Parse(textBoxPort.Text);
         UdpSever.Resault rs = UdpSever.Start();
         if (rs.Reault)
         {
             buttonStart.Text     = "停止";
             textBoxIP.ReadOnly   = true;
             textBoxPort.ReadOnly = true;
             this.Close();
             //MessageBox.Show(rs.Message, "提示");
         }
         else
         {
             MessageBox.Show(rs.Message, "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
         }
     }
     //触发事件
     MyEvent();
 }
Exemple #4
0
        private void MDIParent1_Load(object sender, EventArgs e)
        {
            //初始化系统参数
            XmlHelper.InitDebug();

            int delay = 30;

            UdpSever.Shell.WriteNotice(delay, "系统消息", "系统启动...");
            UdpSever.Shell.WriteNotice(delay, "系统消息", "加载调试信息...");

            UdpSever.Shell.WriteNotice(delay, "系统消息", "获取本机IP...");


            UdpSever.Shell.WriteNotice(delay, "系统消息", "加载服务器配置...");

            UdpSever.Shell.WriteLine(delay, "[服务器][服务器地址][ServerAddress][{0}]", UdpSever.ServerAddress);
            UdpSever.Shell.WriteLine(delay, "[服务器][设备数][DeviceNum][{0}]", UdpSever.DeviceNum);
            UdpSever.Shell.WriteLine(delay, "[服务器][寄存器数][RegisterNum][{0}]", UdpSever.RegisterNum);
            UdpSever.Shell.WriteLine(delay, "[服务器][单帧数据长度][FrameLen][{0}]", UdpSever.FrameLen);
            UdpSever.Shell.WriteLine(delay, "[服务器][心跳周期][HeartCycle][{0}]秒", UdpSever.HeartCycle);
            UdpSever.Shell.WriteLine(delay, "[服务器][重发次数][RepeatNum][{0}]", UdpSever.RepeatNum);
            UdpSever.Shell.WriteLine(delay, "[服务器][超时时间][ResponseTimeout][{0}]", UdpSever.ResponseTimeout);
            UdpSever.Shell.WriteLine(delay, "[服务器][响应帧缓冲池容量][RESPONSE_MAX_LEN][{0}]", UdpSever.RESPONSE_MAX_LEN);
            UdpSever.Shell.WriteLine(delay, "[服务器][设备总数][DeviceNum][{0}]\r\n", UdpSever.DeviceNum);

            #region 获取本机IP,自动开启服务器
            string      name      = Dns.GetHostName();
            IPAddress[] ipadrlist = Dns.GetHostAddresses(name);
            foreach (IPAddress ipa in ipadrlist)
            {
                if (ipa.AddressFamily == AddressFamily.InterNetwork)
                {
                    UdpSever.Shell.WriteNotice(delay, "系统消息", "本机IP:[{0}]", ipa.ToString());
                    UdpSever.ipaddress = ipa;
                }
            }
            //自动启动服务器
            UdpSever.Resault rs = UdpSever.Start();
            //更新界面
            udpConfigForm_MyEvent();
            #endregion


            treeView1.Nodes.Clear();

            try
            {
                if (listenForm.IsDisposed != true)
                {
                    listenForm.Show();  //弹出这个窗口
                    listenForm.Focus(); //激活显示
                }
                else
                {
                    listenForm = new ListenForm();
                    listenForm.Show();  //弹出这个窗口
                    listenForm.Focus(); //激活显示
                }
            }
            catch
            {
            }
        }