From 402831c2ce954b487392f1ed3c6cc5e621caf47f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=A4=A7=E7=9F=B3=E5=A4=B4?= Date: Tue, 26 Dec 2023 00:32:07 +0800 Subject: [PATCH] =?UTF-8?q?A2=E7=B1=BB=E6=94=AF=E6=8C=81=E8=8E=B7=E5=8F=96?= =?UTF-8?q?=E7=BD=91=E7=BB=9C=E4=BF=A1=E6=81=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- SmartA2/A2.cs | 19 +++++++++++++++++++ SmartA2/Net/NetInfo.cs | 13 +++++++++++++ SmartA2/Net/NetModule.cs | 16 ++++++++++++++++ Test/Program.cs | 10 ++++++++++ 4 files changed, 58 insertions(+) create mode 100644 SmartA2/Net/NetInfo.cs diff --git a/SmartA2/A2.cs b/SmartA2/A2.cs index fb1d9b6..3384d90 100644 --- a/SmartA2/A2.cs +++ b/SmartA2/A2.cs @@ -2,6 +2,7 @@ using NewLife; using NewLife.IoT.Controllers; using NewLife.Serial.Protocols; +using SmartA2.Net; namespace SmartA2; @@ -144,5 +145,23 @@ public void SetHostName(String name) if (!flag) File.AppendAllText(file, $"\r\n127.0.0.1\t{name}\t{name}\r\n"); } } + + /// 获取网络信息 + /// + public NetInfo GetNetInfo() + { + using var module = new NetModule(); + module.Open(); + + for (var i = 0; i < 3; i++) + { + var inf = module.GetNetInfo(); + if (!inf.IMEI.IsNullOrEmpty()) return inf; + + if (i < 3 - 1) Thread.Sleep(1000); + } + + return null; + } #endregion } \ No newline at end of file diff --git a/SmartA2/Net/NetInfo.cs b/SmartA2/Net/NetInfo.cs new file mode 100644 index 0000000..e80c353 --- /dev/null +++ b/SmartA2/Net/NetInfo.cs @@ -0,0 +1,13 @@ +namespace SmartA2.Net; + +/// 网络信息 +public class NetInfo +{ + public String IMEI { get; set; } + + public String IMSI { get; set; } + + public String ICCID { get; set; } + + public Int32 CSQ { get; set; } +} diff --git a/SmartA2/Net/NetModule.cs b/SmartA2/Net/NetModule.cs index 3d39256..c96fd95 100644 --- a/SmartA2/Net/NetModule.cs +++ b/SmartA2/Net/NetModule.cs @@ -161,4 +161,20 @@ public String GetState() return rs.Message; } #endregion + + #region 复合功能 + /// 获取网络信息 + /// + public NetInfo GetNetInfo() + { + var inf = new NetInfo + { + IMEI = GetIMEI(), + IMSI = GetIMSI(), + ICCID = GetICCID(), + CSQ = GetCSQ().ToInt(), + }; + return inf; + } + #endregion } diff --git a/Test/Program.cs b/Test/Program.cs index 1eedcb8..43184d7 100644 --- a/Test/Program.cs +++ b/Test/Program.cs @@ -1,6 +1,7 @@ using NewLife.IoT.Drivers; using NewLife.IoT.ThingModels; using NewLife.Log; +using NewLife.Serialization; using SmartA2; using SmartA2.Drivers; using SmartA2.Net; @@ -93,4 +94,13 @@ static void Test3() //Thread.Sleep(1000); XTrace.WriteLine("LBS:\t{0}", module.GetLBS()); + + module.Close(); + + var n = "-1"; + XTrace.WriteLine("n={0} n2={1}", n, n.ToInt()); + + var a2 = new A2(); + var inf = a2.GetNetInfo(); + XTrace.WriteLine(inf.ToJson(true)); } \ No newline at end of file