/// <summary> /// UDP服务 /// </summary> private void btnUDP_Click(object sender, EventArgs e) { btnUDP.Enabled = false; if (UdpServer == null) { UdpServer = new AsyncUDPServer(); } if (!UdpServer.IsStartListening) { UdpServer.Start(); txtMsg.AppendText(DateTime.Now + Environment.NewLine + "UDP服务器启动" + Environment.NewLine); lblUDP.Text = "UDP服务器地址:" + HelpCommonLib.NetworkAddress.GetIPAddress() + ":" + UdpServer.ListenProt; PicBoxUDP.BackgroundImage = Properties.Resources._07822_48x48x8BPP_; btnUDP.Text = "UDP停止服务"; btnUDP.Enabled = true; } else { txtMsg.AppendText(DateTime.Now + Environment.NewLine + "UDP服务器停止" + Environment.NewLine); UdpServer.Close(); PicBoxUDP.BackgroundImage = Properties.Resources._07821_48x48x8BPP_; btnUDP.Text = "UDP端口错误"; } }
/// <summary> /// UDP服务 /// </summary> private void btnUDP_Click(object sender, EventArgs e) { btnUDP.Enabled = false; if (UdpServer == null) { UdpServer = new AsyncUDPServer(); } // AsyncUDPServer UdpServer2 = new AsyncUDPServer(6001); //UdpServer2.Start(ref m_np); if (!UdpServer.IsStartListening) { // UdpServer.Start(); UdpServer.Start(ref m_np); //// 尝试自动开始串口信息处理 //PortSettings setting = AddPortForm.AutoPortSetting; //if (setting != null) //{ // // 添加新的设备页 // controlPage = new AisControl(setting,UdpServer); // if (controlPage.IsOpen()) // { // controlPage.Dock = DockStyle.Fill; // TabPage page = new TabPage(setting.PortName); // tabPageEx6.Controls.Add(controlPage); // } //} // lblUDP.Text = "UDP服务器地址:" + HelpCommonLib.NetworkAddress.GetIPAddress() + ":" + UdpServer.ListenProt; string str = "地址:" + HelpCommonLib.NetworkAddress.GetIPAddress() + ":" + UdpServer.ListenProt; txtMsg.AppendText(DateTime.Now + Environment.NewLine + "UDP服务器启动 " + str + Environment.NewLine); //str = "地址:" + HelpCommonLib.NetworkAddress.GetIPAddress() + ":" + UdpServer2.ListenProt; //txtMsg.AppendText(DateTime.Now + Environment.NewLine + "UDP服务器启动 " + str + Environment.NewLine); // lblUDP.Text = "UDP服务器地址:" + HelpCommonLib.NetworkAddress.GetIPAddress() + ":" + UdpServer2.ListenProt; PicBoxUDP.BackgroundImage = Properties.Resources._07822_48x48x8BPP_; btnUDP.Text = "UDP停止服务"; btnUDP.Enabled = true; //timer1.Start(); } else { txtMsg.AppendText(DateTime.Now + Environment.NewLine + "UDP服务器停止" + Environment.NewLine); UdpServer.Close(); PicBoxUDP.BackgroundImage = Properties.Resources._07821_48x48x8BPP_; btnUDP.Text = "UDP端口错误"; // UdpServer2.Close(); } }
public AisControl(PortSettings setting, AsyncUDPServer udpServer) { InitializeComponent(); try { m_asyncudpServer = udpServer; m_AISCollection = udpServer.m_np.m_AISCollection; //m_tcpClient = new SyncSocketClient(); //m_tcpClient.Connect("192.168.20.40", 50000); //Program.g_client = m_tcpClient; // m_ais = new jsonParse.AisMessage(); // tcpClient.SendCommand("1111111111111111"); // 设置事件入口 m_wndSaveDataWorker.DoWork += new DoWorkEventHandler(m_wndSaveDataWorker_DoWork); m_wndSaveDataWorker.RunWorkerCompleted += new RunWorkerCompletedEventHandler(m_wndSaveDataWorker_RunWorkerCompleted); // 绑定消息 m_SerialPort.PortName = setting.PortName; m_SerialPort.BaudRate = setting.BaudRate; m_SerialPort.DataBits = setting.DataSize; m_SerialPort.StopBits = setting.StopBits; m_SerialPort.Parity = setting.Parity; m_SerialPort.DataReceived += new SerialDataReceivedEventHandler(m_SerialPort_DataReceived); m_AISParser.DynamicInformationReceived += new DynamicInformationReceivedHandler(m_AISParser_DynamicInformationReceived); m_AISParser.StaticInformationReceived += new StaticInformationReceivedHandler(m_AISParser_StaticInformationReceived); m_AISParser.NMEAStringReceived += new DataReceivedHandler(m_AISParser_NMEAStringReceived); m_AISParser.RawStringReceived += new DataReceivedHandler(m_AISParser_RawStringReceived); // 打开串口 m_SerialPort.Open(); } catch (System.Exception ex) { MessageBox.Show("打开串口失败, 串口名称:" + setting.PortName + "\n详细信息:\n" + ex.Message); } }