|
|
|
@ -71,6 +71,9 @@ namespace SocketExample
|
|
|
|
|
private string _linkstate;//链接状态文本
|
|
|
|
|
public string LinkState { get => _linkstate; set { _linkstate = value; OnPropertyChanged(); } }
|
|
|
|
|
|
|
|
|
|
public string LinkButtonText { get => _linkbuttontext; set { _linkbuttontext = value; OnPropertyChanged(); } }
|
|
|
|
|
private string _linkbuttontext { get; set; }
|
|
|
|
|
|
|
|
|
|
private string _infotext;//信息框
|
|
|
|
|
public string Infotext { get => _infotext; set
|
|
|
|
|
{
|
|
|
|
@ -207,6 +210,7 @@ namespace SocketExample
|
|
|
|
|
MessageText = string.Empty;
|
|
|
|
|
IPtext = "192.168.0.7";//默认IP
|
|
|
|
|
Porttext = "20108";//默认端口
|
|
|
|
|
LinkButtonText = "连接";
|
|
|
|
|
StateColour = "Red";
|
|
|
|
|
LinkState = "未连接";
|
|
|
|
|
RSSIinfo = "##";
|
|
|
|
@ -356,6 +360,7 @@ namespace SocketExample
|
|
|
|
|
//获取GPIO状态,16进制转二进制
|
|
|
|
|
string GPIBinInfo = Convert.ToString(Convert.ToInt32(readStateString.Substring(12, 2), 16), 2).PadLeft(8, '0');
|
|
|
|
|
string GPOBinInfo = Convert.ToString(Convert.ToInt32(readStateString.Substring(10, 2), 16), 2).PadLeft(8, '0');
|
|
|
|
|
bool GPIchange = false;
|
|
|
|
|
string GPI1string = "";
|
|
|
|
|
string GPI2string = "";
|
|
|
|
|
string GPI3string = "";
|
|
|
|
@ -378,6 +383,7 @@ namespace SocketExample
|
|
|
|
|
{
|
|
|
|
|
GPI4 = "低";
|
|
|
|
|
GPI4string = "GPI4:" + GPIChangeLog(GPI4);
|
|
|
|
|
GPIchange = true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
@ -385,6 +391,7 @@ namespace SocketExample
|
|
|
|
|
{
|
|
|
|
|
GPI4 = "高";
|
|
|
|
|
GPI4string = "GPI4:" + GPIChangeLog(GPI4);
|
|
|
|
|
GPIchange = true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
break;
|
|
|
|
@ -399,14 +406,16 @@ namespace SocketExample
|
|
|
|
|
if (GPI3 != "低")
|
|
|
|
|
{
|
|
|
|
|
GPI3 = "低";
|
|
|
|
|
GPI3string = "GPI3:" + GPIChangeLog(GPI3) + " ";
|
|
|
|
|
GPI3string = "GPI3:" + GPIChangeLog(GPI3) + " ";
|
|
|
|
|
GPIchange = true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
if (GPI3 != "高")
|
|
|
|
|
{
|
|
|
|
|
GPI3 = "高";
|
|
|
|
|
GPI3string = "GPI3:" + GPIChangeLog(GPI3) + " ";
|
|
|
|
|
GPI3string = "GPI3:" + GPIChangeLog(GPI3) + " ";
|
|
|
|
|
GPIchange = true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
break;
|
|
|
|
@ -421,14 +430,16 @@ namespace SocketExample
|
|
|
|
|
if (GPI2 != "低")
|
|
|
|
|
{
|
|
|
|
|
GPI2 = "低";
|
|
|
|
|
GPI2string = "GPI2:" + GPIChangeLog(GPI2) + " ";
|
|
|
|
|
GPI2string = "GPI2:" + GPIChangeLog(GPI2) + " ";
|
|
|
|
|
GPIchange = true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
if (GPI2 != "高")
|
|
|
|
|
{
|
|
|
|
|
GPI2 = "高";
|
|
|
|
|
GPI2string = "GPI2:" + GPIChangeLog(GPI2) + " ";
|
|
|
|
|
GPI2string = "GPI2:" + GPIChangeLog(GPI2) + " ";
|
|
|
|
|
GPIchange = true;
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
case 7:
|
|
|
|
@ -442,14 +453,16 @@ namespace SocketExample
|
|
|
|
|
if (GPI1 != "低")
|
|
|
|
|
{
|
|
|
|
|
GPI1 = "低";
|
|
|
|
|
GPI1string = "GPI1:" + GPIChangeLog(GPI1) + " ";
|
|
|
|
|
GPI1string = "GPI1:" + GPIChangeLog(GPI1) + " ";
|
|
|
|
|
GPIchange = true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
if (GPI1 != "高")
|
|
|
|
|
{
|
|
|
|
|
GPI1 = "高";
|
|
|
|
|
GPI1string = "GPI1:" + GPIChangeLog(GPI1) + " ";
|
|
|
|
|
GPI1string = "GPI1:" + GPIChangeLog(GPI1) + " ";
|
|
|
|
|
GPIchange = true;
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
@ -457,12 +470,16 @@ namespace SocketExample
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if(GPIchange == true)
|
|
|
|
|
{
|
|
|
|
|
EnsureFolderExists($"日志文件夹/{GPIyear}/{Text}");
|
|
|
|
|
string temppath = $"日志文件夹/{GPIyear}/{Text}/" + Text + "GPI" + "(" + IPtext + ")" + ".txt";
|
|
|
|
|
EnsureTxtExists(temppath, Text, IPtext, Porttext);
|
|
|
|
|
string currenttime = DateTime.Now.ToString();
|
|
|
|
|
writeToTxt(temppath, $"{GPI1string}{GPI2string}{GPI3string}{GPI4string}\n当前状态:GPI1:{GPI1} GPI2:{GPI2} GPI3:{GPI3} GPI4:{GPI4}\n当前时间:{currenttime}\n ______________________________");
|
|
|
|
|
GPIchange = false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
EnsureFolderExists($"日志文件夹/{GPIyear}/{Text}");
|
|
|
|
|
string temppath = $"日志文件夹/{GPIyear}/{Text}/" + Text + "GPI" + "(" + IPtext + ")" + ".txt";
|
|
|
|
|
EnsureTxtExists(temppath, Text, IPtext, Porttext);
|
|
|
|
|
string currenttime = DateTime.Now.ToString();
|
|
|
|
|
writeToTxt(temppath, $"{GPI1string}{GPI2string}{GPI3string}{GPI4string}\n当前状态:GPI1:{GPI1} GPI2:{GPI2} GPI3:{GPI3} GPI4:{GPI4}\n当前时间:{currenttime}\n ______________________________");
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case "72":
|
|
|
|
@ -684,6 +701,8 @@ namespace SocketExample
|
|
|
|
|
#region 动态界面控件功能
|
|
|
|
|
async void Button_Link()//链接按钮的事件
|
|
|
|
|
{
|
|
|
|
|
if(LinkButtonText == "连接")
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
@ -695,7 +714,7 @@ namespace SocketExample
|
|
|
|
|
//连接事件
|
|
|
|
|
client.Connected += onConnected;
|
|
|
|
|
//断连事件
|
|
|
|
|
client.Closed = (client, e) => { GPIOthread.Abort(); Infotext += "已断开!\n"; StateColour = "Red"; LinkState = "未连接"; return EasyTask.CompletedTask; };
|
|
|
|
|
client.Closed = (client, e) => { try { GPIOthread.Abort(); Infotext += "已断开!\n"; StateColour = "Red"; LinkState = "未连接"; } catch (Exception ex) { Infotext += ex; } return EasyTask.CompletedTask; };
|
|
|
|
|
//接收事件
|
|
|
|
|
client.Received += onRecieved;
|
|
|
|
|
|
|
|
|
@ -704,7 +723,7 @@ namespace SocketExample
|
|
|
|
|
{
|
|
|
|
|
a.AddConsoleLogger();//添加一个日志注入
|
|
|
|
|
}));
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//开启连接
|
|
|
|
|
await client.ConnectAsync();
|
|
|
|
|
}
|
|
|
|
@ -712,6 +731,13 @@ namespace SocketExample
|
|
|
|
|
{
|
|
|
|
|
Infotext += $"处理请求时出错: {ex.Message}\n";
|
|
|
|
|
}
|
|
|
|
|
LinkButtonText = "断开";
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
client.Close();
|
|
|
|
|
LinkButtonText = "连接";
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void Button_Read()
|
|
|
|
@ -772,7 +798,7 @@ namespace SocketExample
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void Button_GetPower()
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|