From 10afb4f79299cae08344fd8245a7217ea49f712e Mon Sep 17 00:00:00 2001
From: wxr <464027401@qq.com>
Date: 星期三, 09 八月 2023 11:27:45 +0800
Subject: [PATCH] 空调,地暖温度类型支持
---
HDL_ON/DAL/DriverLayer/UdpSocket.cs | 42 +++++++++++++++++++++++++++++++++++-------
1 files changed, 35 insertions(+), 7 deletions(-)
diff --git a/HDL_ON/DAL/DriverLayer/UdpSocket.cs b/HDL_ON/DAL/DriverLayer/UdpSocket.cs
index e358428..17acf0f 100644
--- a/HDL_ON/DAL/DriverLayer/UdpSocket.cs
+++ b/HDL_ON/DAL/DriverLayer/UdpSocket.cs
@@ -27,17 +27,22 @@
/// </summary>
public void Start (int port = 0)
{
+ MainPage.Log("鍚姩Socket鎺ユ敹鍜屽彂閫佸姛鑳�0");
if (IsRunning)
{
- if (port == Port)
+ MainPage.Log("鍚姩Socket鎺ユ敹鍜屽彂閫佸姛鑳絰");
+ if (port == Port)
{
+ MainPage.Log("鍚姩Socket鎺ユ敹鍜屽彂閫佸姛鑳絪");
return;
- }
+ }
else
{
+ MainPage.Log("鍚姩Socket鎺ユ敹鍜屽彂閫佸姛鑳絘");
busSocket.Close();
- }
+ }
}
+ MainPage.Log("鍚姩Socket鎺ユ敹鍜屽彂閫佸姛鑳�1");
if (port != 0)
Port = port;
if (Port == 0)
@@ -49,9 +54,12 @@
busSocket.Bind(new IPEndPoint(IPAddress.Any, Port));
busSocket.SetSocketOption(SocketOptionLevel.IP, SocketOptionName.AddMembership, new MulticastOption(IPAddress.Parse("239.0.168.188")));
+ relinkCount = 0;
}
- catch{
- busSocket = null;
+ catch (Exception ex){
+ MainPage.Log ($"udp port bind error : {ex.Message}");
+
+ busSocket = null;
return;
}
@@ -65,6 +73,10 @@
/// </summary>
public void Stop()
{
+ if(busSocket == null)
+ {
+ return;
+ }
if (!IsRunning)
{
return;
@@ -72,10 +84,11 @@
try
{
busSocket.Close();
+ relinkCount = 0;
}
catch { }
busSocket = null;
- MainPage.Log("Socket鍏抽棴");
+ MainPage.Log("Socket鍏抽棴");
}
/// <summary>
@@ -98,6 +111,10 @@
{
return;
}
+ if(busSocket == null)
+ {
+ return;
+ }
try {
Packet packet = new Packet ();
@@ -105,10 +122,21 @@
}
catch (Exception e) {
System.Threading.Thread.Sleep (1);
- asyncBeginReceive ();
+ Console.WriteLine("asyncBeginReceive " + relinkCount );
+ if (relinkCount == 0)
+ {
+ relinkCount = 1;
+ asyncBeginReceive();
+ }
Console.WriteLine($"asyncBeginReceive {e.Message}");
}
}
+ /// <summary>
+ /// 閲嶈繛娆℃暟
+ /// </summary>
+ private int relinkCount = 0;
+
+
/// <summary>
/// 寮傛鎺ユ敹鏁版嵁缁撴潫
--
Gitblit v1.8.0