1 地震仪告警记录中故障次数隐藏;电力载波机和光电交换机的供电状态隐藏; 2 除漏水和保护板事件的数据按照浮点数解析,别的按照整数解析; 3 解决TCP Server和Client存在的问题,包括无法监测到客户端连接,无法监测到服务端断开等问题;
557 lines
33 KiB
C#
557 lines
33 KiB
C#
using JiangsuEarthquake.Common;
|
||
using JiangsuEarthquake.DataAccess;
|
||
using JiangsuEarthquake.ViewModels;
|
||
using JiangsuEarthquake.Views.UserControls;
|
||
using LiveCharts.Defaults;
|
||
using LiveCharts.Wpf;
|
||
using LiveCharts;
|
||
using Microsoft.Win32;
|
||
using System;
|
||
using System.Collections.Generic;
|
||
using System.Linq;
|
||
using System.Text;
|
||
using System.Threading.Tasks;
|
||
using System.Windows;
|
||
using System.Windows.Media;
|
||
using Application = System.Windows.Application;
|
||
using MySql.Data.MySqlClient;
|
||
using Color = System.Windows.Media.Color;
|
||
using System.Reflection.Metadata;
|
||
|
||
namespace JiangsuEarthquake.Models
|
||
{
|
||
public class VolCurCollectorModel
|
||
{
|
||
private byte fromDeviceAddress { get; set; } //从设备地址
|
||
|
||
private byte functionCode { get; set; } //功能码
|
||
|
||
private byte[] startingRegisterAddress { get; set; } = new byte[2]; //起始寄存器地址
|
||
|
||
private byte[] registerNumber { get; set; } = new byte[2]; //寄存器个数
|
||
|
||
private byte[] checkCodeCRC { get; set; } = new byte[2]; //校验码
|
||
|
||
private List<byte> checkByte { get; set; } = new List<byte>(); //校验码Byte
|
||
|
||
private byte dataAreaBytes { get; set; } //数据区字节数
|
||
|
||
private List<byte> dataArea { get; set; } = new List<byte>(); //数据区
|
||
|
||
private float voltage { get; set; }
|
||
|
||
private float current { get; set; }
|
||
|
||
private float power { get; set; }
|
||
|
||
private float posEleDegree { get; set; }
|
||
|
||
private float revEleDegree { get; set; }
|
||
|
||
private float uVoltage { get; set; }
|
||
|
||
private float uCurrent { get; set; }
|
||
|
||
private int relayStatus { get; set; }
|
||
|
||
private float highResVoltage { get; set; }
|
||
|
||
private float highResCurrent { get; set; }
|
||
|
||
private float forAmpereHour { get; set; }
|
||
|
||
private float revAmpereHour { get; set; }
|
||
|
||
int ChartPointNum = 15;
|
||
|
||
public void ParsingData(List<byte> byteList, int id)
|
||
{
|
||
if (byteList.Count == 0)
|
||
return;
|
||
|
||
//原始数据存储
|
||
string sql = $"insert into boosterstation_state_originaldata(StationID,RecordTime,OriginalData) values('{id}','{DateTime.Now}','{BitConverter.ToString(byteList.ToArray())}');";
|
||
DBHelper.ExecuteNonQuery(sql, 1);
|
||
|
||
checkByte.Clear();
|
||
//CRC校验
|
||
for (int i = 0; i < byteList.Count - 2; i++)
|
||
checkByte.Add(byteList[i]);
|
||
checkCodeCRC = Tools.CRCCalcRev(checkByte.ToArray());
|
||
//CRC校验失败
|
||
if (!Tools.CompareByte(checkCodeCRC, new byte[2] { byteList[byteList.Count - 2], byteList[byteList.Count - 1] }))
|
||
{
|
||
string content = "升压站电控通信系统数据CRC校验失败";
|
||
|
||
sql = $"insert into alarm_run_info(StationID,RecordTime,ParaName,ParaContent) values('{id}','{DateTime.Now}','升压站电控通信系统数据校验','{content}');";
|
||
DBHelper.ExecuteNonQuery(sql, 1);
|
||
|
||
return;
|
||
}
|
||
|
||
|
||
if (byteList[1] == 0x03) //查询从设备寄存器内容
|
||
{
|
||
//目前为读取寄存器 0000H-000FH,即所有数据
|
||
//长度校验
|
||
dataAreaBytes = byteList[2];
|
||
if (dataAreaBytes + 5 != byteList.Count)
|
||
{
|
||
string content = "升压站电控通信系统状态数据长度校验失败";
|
||
|
||
sql = $"insert into alarm_run_info(StationID,RecordTime,ParaName,ParaContent) values('{id}','{DateTime.Now}','升压站电控通信系统数据校验','{content}');";
|
||
DBHelper.ExecuteNonQuery(sql, 1);
|
||
|
||
return;
|
||
}
|
||
|
||
DateTime recordTime = DateTime.Now;
|
||
|
||
try
|
||
{
|
||
//获取电压电流的量程;
|
||
int VoltageRange = int.Parse(Tools.GetAppSetting("SYZVoltageRange"));
|
||
int CurrentRange = int.Parse(Tools.GetAppSetting("SYZCurrentRange"));
|
||
|
||
voltage = BitConverter.ToInt16(new byte[2] { byteList[4], byteList[3] }) / 10000f * VoltageRange;
|
||
current = BitConverter.ToInt16(new byte[2] { byteList[6], byteList[5] }) / 10000f * CurrentRange;
|
||
//power = voltage * current;
|
||
power = BitConverter.ToInt16(new byte[2] { byteList[8], byteList[7] }) / 10000f * VoltageRange * CurrentRange;
|
||
posEleDegree = BitConverter.ToUInt32(new byte[4] { byteList[12], byteList[11], byteList[10], byteList[9] }) * VoltageRange * CurrentRange / (1000 * 3600);
|
||
revEleDegree = BitConverter.ToUInt32(new byte[4] { byteList[16], byteList[15], byteList[14], byteList[13] }) * VoltageRange * CurrentRange / (1000 * 3600);
|
||
uVoltage = BitConverter.ToUInt16(new byte[2] { byteList[18], byteList[17] }) / 10000f * VoltageRange;
|
||
uCurrent = BitConverter.ToUInt16(new byte[2] { byteList[20], byteList[19] }) / 10000f * VoltageRange;
|
||
relayStatus = byteList[21];
|
||
//highResVoltage = BitConverter.ToInt16(new byte[2] { byteList[23], byteList[22] }) / 50000f * VoltageRange;
|
||
//highResCurrent = BitConverter.ToInt16(new byte[2] { byteList[25], byteList[24] }) / 50000f * CurrentRange;
|
||
//forAmpereHour = BitConverter.ToUInt32(new byte[4] { byteList[29], byteList[28], byteList[27], byteList[26] }) * CurrentRange / 3600;
|
||
//revAmpereHour = BitConverter.ToUInt32(new byte[4] { byteList[33], byteList[32], byteList[31], byteList[30] }) * CurrentRange / 3600;
|
||
recordTime = DateTime.Now;
|
||
|
||
sql = $"insert into boosterstation_state(StationID,RecordTime,In_Vol,In_Cur,Power,PosEleDegree," +
|
||
$"RevEleDegree,uVoltage,uCurrent,RelayStatus,HighResVoltage,HighResCurrent,ForAmpereHour," +
|
||
$"RevAmpereHour) values('{id}','{recordTime}','{voltage}','{current}','{power}','{posEleDegree}'," +
|
||
$"'{revEleDegree}','{uVoltage}','{uCurrent}','{relayStatus}','{highResVoltage}'," +
|
||
$"'{highResCurrent}','{forAmpereHour}','{revAmpereHour}');";
|
||
DBHelper.ExecuteNonQuery(sql, 1);
|
||
|
||
//异常数据存储
|
||
if (voltage < TotalMessage.VolCurCollectorVoltageMin || voltage > TotalMessage.VolCurCollectorVoltageMax || current < TotalMessage.VolCurCollectorCurrentMin || current > TotalMessage.VolCurCollectorCurrentMax)
|
||
{
|
||
sql = $"insert into boosterstation_state_abnormaldata(StationID,RecordTime,In_Vol,In_Cur,Power,PosEleDegree," +
|
||
$"RevEleDegree,uVoltage,uCurrent,RelayStatus,HighResVoltage,HighResCurrent,ForAmpereHour," +
|
||
$"RevAmpereHour) values('{id}','{recordTime}','{voltage}','{current}','{power}','{posEleDegree}'," +
|
||
$"'{revEleDegree}','{uVoltage}','{uCurrent}','{relayStatus}','{highResVoltage}'," +
|
||
$"'{highResCurrent}','{forAmpereHour}','{revAmpereHour}');";
|
||
DBHelper.ExecuteNonQuery(sql, 1);
|
||
}
|
||
|
||
sql = $"insert into log_record(StationID,RecordTime,Device_Name,Operation_Type,Record) values('{id}','{DateTime.Now}','升压站电控通信系统','数据请求','请求升压站状态数据成功');";
|
||
DBHelper.ExecuteNonQuery(sql, 1);
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
string content = "升压站电控通信系统状态数据解析失败," + ex.Message;
|
||
|
||
sql = $"insert into alarm_run_info(StationID,RecordTime,ParaName,ParaContent) values('{id}','{DateTime.Now}','升压站电控通信系统数据解析','{content}');";
|
||
DBHelper.ExecuteNonQuery(sql, 1);
|
||
}
|
||
|
||
App.Current.Dispatcher.Invoke(() =>
|
||
{
|
||
if (id == 1)
|
||
{
|
||
MainViewModel.boosterStationStateDataViewModel1.AskDataBtnIsReceived = true;
|
||
MainViewModel.boosterStationStateDataViewModel1.AskDataBtnIsEnabled = true;
|
||
MainViewModel.boosterStationStateDataViewModel1.timerAskData.Stop();
|
||
MainViewModel.boosterStationStateDataViewModel1.AskDataMsgVisibility = Visibility.Visible;
|
||
MainViewModel.boosterStationStateDataViewModel1.AskDataMsg = "请求升压站状态数据成功!";
|
||
MainViewModel.boosterStationStateDataViewModel1.timerAskDataMsgCollapse.Start();
|
||
MainViewModel.boosterStationStateDataViewModel1.AskDataMsgForeground = new SolidColorBrush(Colors.Green);
|
||
|
||
if (relayStatus == 1)
|
||
MainViewModel.baseStationStateModel1.JunBox_Power = (ImageSource)Application.Current.FindResource("DeviceOn");
|
||
else
|
||
MainViewModel.baseStationStateModel1.JunBox_Power = (ImageSource)Application.Current.FindResource("DeviceOff");
|
||
|
||
MainViewModel.realTimeDataViewModel1.BaseStationStatus[2].Value = voltage.ToString();
|
||
MainViewModel.realTimeDataViewModel1.BaseStationStatus[5].Value = current.ToString();
|
||
MainViewModel.realTimeDataViewModel1.DataTimeBoosterStationVol = recordTime;
|
||
MainViewModel.realTimeDataViewModel1.DataTimeBoosterStationCur = recordTime;
|
||
|
||
var chartValuesBoosterStationVol = new ChartValues<DateTimePoint>();
|
||
var chartValuesBoosterStationCur = new ChartValues<DateTimePoint>();
|
||
sql = String.Format("select * from boosterstation_state where StationID = {0} ORDER by id desc limit {1}", 1, ChartPointNum);
|
||
MySqlDataReader dataReader = DBHelper.ExecuteReader(sql, 1);
|
||
while (dataReader.Read())
|
||
{
|
||
if (!Convert.IsDBNull(dataReader["In_Vol"]) && !Convert.IsDBNull(dataReader["In_Cur"]))
|
||
{
|
||
chartValuesBoosterStationVol.Add(new DateTimePoint
|
||
{
|
||
Value = Convert.ToSingle(dataReader["In_Vol"]),
|
||
DateTime = Convert.ToDateTime(dataReader["RecordTime"]),
|
||
});
|
||
chartValuesBoosterStationCur.Add(new DateTimePoint
|
||
{
|
||
Value = Convert.ToSingle(dataReader["In_Cur"]),
|
||
DateTime = Convert.ToDateTime(dataReader["RecordTime"]),
|
||
});
|
||
}
|
||
}
|
||
dataReader.Dispose();
|
||
MainViewModel.realTimeDataViewModel1.SeriesCollectionBoosterStationVol = new SeriesCollection
|
||
{
|
||
new LineSeries
|
||
{
|
||
Title = "输入电压",
|
||
Values = chartValuesBoosterStationVol,
|
||
LineSmoothness = 0,
|
||
ScalesYAt = 0,
|
||
Stroke = new SolidColorBrush(Color.FromArgb(255, 43, 237, 241)),
|
||
Fill = new SolidColorBrush(Colors.Transparent)
|
||
},
|
||
};
|
||
MainViewModel.realTimeDataViewModel1.SeriesCollectionBoosterStationCur = new SeriesCollection
|
||
{
|
||
new LineSeries
|
||
{
|
||
Title = "输入电流",
|
||
Values = chartValuesBoosterStationCur,
|
||
LineSmoothness = 0,
|
||
ScalesYAt = 0,
|
||
Stroke = new SolidColorBrush(Color.FromArgb(255, 43, 237, 241)),
|
||
Fill = new SolidColorBrush(Colors.Transparent)
|
||
},
|
||
};
|
||
}
|
||
else
|
||
{
|
||
MainViewModel.boosterStationStateDataViewModel2.AskDataBtnIsReceived = true;
|
||
MainViewModel.boosterStationStateDataViewModel2.AskDataBtnIsEnabled = true;
|
||
MainViewModel.boosterStationStateDataViewModel2.timerAskData.Stop();
|
||
MainViewModel.boosterStationStateDataViewModel2.AskDataMsgVisibility = Visibility.Visible;
|
||
MainViewModel.boosterStationStateDataViewModel2.AskDataMsg = "请求升压站状态数据成功!";
|
||
MainViewModel.boosterStationStateDataViewModel2.timerAskDataMsgCollapse.Start();
|
||
MainViewModel.boosterStationStateDataViewModel2.AskDataMsgForeground = new SolidColorBrush(Colors.Green);
|
||
|
||
if (relayStatus == 1)
|
||
MainViewModel.baseStationStateModel2.JunBox_Power = (ImageSource)Application.Current.FindResource("DeviceOn");
|
||
else
|
||
MainViewModel.baseStationStateModel2.JunBox_Power = (ImageSource)Application.Current.FindResource("DeviceOff");
|
||
|
||
MainViewModel.realTimeDataViewModel2.BaseStationStatus[2].Value = voltage.ToString();
|
||
MainViewModel.realTimeDataViewModel2.BaseStationStatus[5].Value = current.ToString();
|
||
MainViewModel.realTimeDataViewModel2.DataTimeBoosterStationVol = recordTime;
|
||
MainViewModel.realTimeDataViewModel2.DataTimeBoosterStationCur = recordTime;
|
||
|
||
var chartValuesBoosterStationVol = new ChartValues<DateTimePoint>();
|
||
var chartValuesBoosterStationCur = new ChartValues<DateTimePoint>();
|
||
sql = String.Format("select * from boosterstation_state where StationID = {0} ORDER by id desc limit {1}", 2, ChartPointNum);
|
||
MySqlDataReader dataReader = DBHelper.ExecuteReader(sql, 1);
|
||
while (dataReader.Read())
|
||
{
|
||
if (!Convert.IsDBNull(dataReader["In_Vol"]) && !Convert.IsDBNull(dataReader["In_Cur"]))
|
||
{
|
||
chartValuesBoosterStationVol.Add(new DateTimePoint
|
||
{
|
||
Value = Convert.ToSingle(dataReader["In_Vol"]),
|
||
DateTime = Convert.ToDateTime(dataReader["RecordTime"]),
|
||
});
|
||
chartValuesBoosterStationCur.Add(new DateTimePoint
|
||
{
|
||
Value = Convert.ToSingle(dataReader["In_Cur"]),
|
||
DateTime = Convert.ToDateTime(dataReader["RecordTime"]),
|
||
});
|
||
}
|
||
}
|
||
dataReader.Dispose();
|
||
MainViewModel.realTimeDataViewModel2.SeriesCollectionBoosterStationVol = new SeriesCollection
|
||
{
|
||
new LineSeries
|
||
{
|
||
Title = "输入电压",
|
||
Values = chartValuesBoosterStationVol,
|
||
LineSmoothness = 0,
|
||
ScalesYAt = 0,
|
||
Stroke = new SolidColorBrush(Color.FromArgb(255, 43, 237, 241)),
|
||
Fill = new SolidColorBrush(Colors.Transparent)
|
||
},
|
||
};
|
||
MainViewModel.realTimeDataViewModel2.SeriesCollectionBoosterStationCur = new SeriesCollection
|
||
{
|
||
new LineSeries
|
||
{
|
||
Title = "输入电流",
|
||
Values = chartValuesBoosterStationCur,
|
||
LineSmoothness = 0,
|
||
ScalesYAt = 0,
|
||
Stroke = new SolidColorBrush(Color.FromArgb(255, 43, 237, 241)),
|
||
Fill = new SolidColorBrush(Colors.Transparent)
|
||
},
|
||
};
|
||
}
|
||
});
|
||
}
|
||
else if (byteList[1] == 0x06) //对从设备单个寄存器置数
|
||
{
|
||
//长度校验
|
||
if (byteList.Count != 8)
|
||
{
|
||
string content = "升压站电控通信系统对从设备单个寄存器置数回复长度校验失败";
|
||
|
||
sql = $"insert into alarm_run_info(StationID,RecordTime,ParaName,ParaContent) values('{id}','{DateTime.Now}','升压站电控通信系统数据校验','{content}');";
|
||
DBHelper.ExecuteNonQuery(sql, 1);
|
||
|
||
return;
|
||
}
|
||
|
||
//需要判断发送内容和接收内容是否相同,相同则设置成功
|
||
//根据寄存器地址判断接收的到信息是对什么进行设置的
|
||
if (byteList[2] == 0x01 && byteList[3] == 0x2C) //继电器报警参数
|
||
{
|
||
if (id == 1)
|
||
{
|
||
if (Tools.CompareByte(byteList.ToArray(), MainViewModel.boosterStationStateDataViewModel1.AlarmParaRecv))
|
||
{
|
||
MainViewModel.boosterStationStateDataViewModel1.AlarmSetBtnIsReceived1 = true;
|
||
}
|
||
}
|
||
else
|
||
{
|
||
if (Tools.CompareByte(byteList.ToArray(), MainViewModel.boosterStationStateDataViewModel2.AlarmParaRecv))
|
||
{
|
||
MainViewModel.boosterStationStateDataViewModel2.AlarmSetBtnIsReceived1 = true;
|
||
}
|
||
}
|
||
}
|
||
else if (byteList[2] == 0x01 && byteList[3] == 0x2D) //继电器报警阀值 1
|
||
{
|
||
//下限报警、上限报警
|
||
if (id == 1)
|
||
{
|
||
if (Tools.CompareByte(byteList.ToArray(), MainViewModel.boosterStationStateDataViewModel1.AlarmThresholdRecv))
|
||
{
|
||
MainViewModel.boosterStationStateDataViewModel1.AlarmSetBtnIsReceived3 = true;
|
||
|
||
//若均为true,则说明报警设置成功
|
||
if (MainViewModel.boosterStationStateDataViewModel1.AlarmSetBtnIsReceived1 && MainViewModel.boosterStationStateDataViewModel1.AlarmSetBtnIsReceived2 && MainViewModel.boosterStationStateDataViewModel1.AlarmSetBtnIsReceived3)
|
||
{
|
||
App.Current.Dispatcher.Invoke(() =>
|
||
{
|
||
MainViewModel.boosterStationStateDataViewModel1.AlarmSetButtonIsEnabled = true;
|
||
MainViewModel.boosterStationStateDataViewModel1.timerAlarmSet.Stop();
|
||
MainViewModel.boosterStationStateDataViewModel1.AlarmSetMessage = "报警设置成功!";
|
||
MainViewModel.boosterStationStateDataViewModel2.timerAlarmSetMsgCollapse.Start();
|
||
MainViewModel.boosterStationStateDataViewModel1.AlarmSetMessageForeground = new SolidColorBrush(Colors.Green);
|
||
});
|
||
}
|
||
}
|
||
}
|
||
else
|
||
{
|
||
if (Tools.CompareByte(byteList.ToArray(), MainViewModel.boosterStationStateDataViewModel2.AlarmThresholdRecv))
|
||
{
|
||
MainViewModel.boosterStationStateDataViewModel2.AlarmSetBtnIsReceived3 = true;
|
||
|
||
//若均为true,则说明报警设置成功
|
||
if (MainViewModel.boosterStationStateDataViewModel2.AlarmSetBtnIsReceived1 && MainViewModel.boosterStationStateDataViewModel2.AlarmSetBtnIsReceived2 && MainViewModel.boosterStationStateDataViewModel2.AlarmSetBtnIsReceived3)
|
||
{
|
||
App.Current.Dispatcher.Invoke(() =>
|
||
{
|
||
MainViewModel.boosterStationStateDataViewModel2.AlarmSetButtonIsEnabled = true;
|
||
MainViewModel.boosterStationStateDataViewModel2.timerAlarmSet.Stop();
|
||
MainViewModel.boosterStationStateDataViewModel2.AlarmSetMessage = "报警设置成功!";
|
||
MainViewModel.boosterStationStateDataViewModel2.timerAlarmSetMsgCollapse.Start();
|
||
MainViewModel.boosterStationStateDataViewModel2.AlarmSetMessageForeground = new SolidColorBrush(Colors.Green);
|
||
});
|
||
}
|
||
}
|
||
}
|
||
|
||
}
|
||
else if (byteList[2] == 0x01 && byteList[3] == 0x2E) //继电器报警阀值 2
|
||
{
|
||
|
||
}
|
||
else if (byteList[2] == 0x01 && byteList[3] == 0x2F) //继电器报警功能
|
||
{
|
||
if (id == 1)
|
||
{
|
||
if (Tools.CompareByte(byteList.ToArray(), MainViewModel.boosterStationStateDataViewModel1.AlarmFuncRecv))
|
||
{
|
||
MainViewModel.boosterStationStateDataViewModel1.AlarmSetBtnIsReceived2 = true;
|
||
}
|
||
}
|
||
else
|
||
{
|
||
if (Tools.CompareByte(byteList.ToArray(), MainViewModel.boosterStationStateDataViewModel2.AlarmFuncRecv))
|
||
{
|
||
MainViewModel.boosterStationStateDataViewModel2.AlarmSetBtnIsReceived2 = true;
|
||
}
|
||
}
|
||
}
|
||
else if (byteList[2] == 0x01 && byteList[3] == 0x30) //继电器输出
|
||
{
|
||
string record = "";
|
||
|
||
//if (id == 1)
|
||
//{
|
||
if (Tools.CompareByte(byteList.ToArray(), MainWindow.mainViewModel.RelayActivationRecv))
|
||
{
|
||
App.Current.Dispatcher.Invoke(() =>
|
||
{
|
||
// 更新UI的代码
|
||
MainWindow.mainViewModel.BaseStationPowerOnIsReceived = true;
|
||
MainWindow.mainViewModel.BaseStationPowerOpenBtnIsEnabled = true;
|
||
MainWindow.mainViewModel.BaseStationPowerCloseBtnIsEnabled = true;
|
||
MainWindow.mainViewModel.timerBaseStationPowerOn.Stop();
|
||
MainWindow.mainViewModel.BaseStationMsgVisibility = Visibility.Visible;
|
||
MainWindow.mainViewModel.BaseStationMsg = "海底基站电源开启成功!";
|
||
MainWindow.mainViewModel.timerBaseStationMsgHidden.Start();
|
||
MainWindow.mainViewModel.BaseStationMsgForeground = new SolidColorBrush(Colors.Green);
|
||
|
||
if (id == 1)
|
||
MainViewModel.baseStationStateModel1.JunBox_Power = (ImageSource)Application.Current.FindResource("DeviceOn");
|
||
else
|
||
MainViewModel.baseStationStateModel2.JunBox_Power = (ImageSource)Application.Current.FindResource("DeviceOn");
|
||
|
||
record = "打开海底基站电源成功";
|
||
});
|
||
}
|
||
else if (Tools.CompareByte(byteList.ToArray(), MainWindow.mainViewModel.RelayShutdownRecv))
|
||
{
|
||
App.Current.Dispatcher.Invoke(() =>
|
||
{
|
||
// 更新UI的代码
|
||
MainWindow.mainViewModel.BaseStationPowerOnIsReceived = true;
|
||
MainWindow.mainViewModel.BaseStationPowerOpenBtnIsEnabled = true;
|
||
MainWindow.mainViewModel.BaseStationPowerCloseBtnIsEnabled = true;
|
||
MainWindow.mainViewModel.timerBaseStationPowerOn.Stop();
|
||
MainWindow.mainViewModel.BaseStationMsgVisibility = Visibility.Visible;
|
||
MainWindow.mainViewModel.BaseStationMsg = "海底基站电源关闭成功!";
|
||
MainWindow.mainViewModel.timerBaseStationMsgHidden.Start();
|
||
MainWindow.mainViewModel.BaseStationMsgForeground = new SolidColorBrush(Colors.Green);
|
||
|
||
if (id == 1)
|
||
MainViewModel.baseStationStateModel1.JunBox_Power = (ImageSource)Application.Current.FindResource("DeviceOff");
|
||
else
|
||
MainViewModel.baseStationStateModel2.JunBox_Power = (ImageSource)Application.Current.FindResource("DeviceOff");
|
||
|
||
record = "关闭海底基站电源成功";
|
||
});
|
||
}
|
||
else
|
||
{
|
||
App.Current.Dispatcher.Invoke(() =>
|
||
{
|
||
// 更新UI的代码
|
||
MainWindow.mainViewModel.BaseStationPowerOnIsReceived = true;
|
||
MainWindow.mainViewModel.BaseStationPowerOpenBtnIsEnabled = true;
|
||
MainWindow.mainViewModel.BaseStationPowerCloseBtnIsEnabled = true;
|
||
MainWindow.mainViewModel.timerBaseStationPowerOn.Stop();
|
||
MainWindow.mainViewModel.BaseStationMsgVisibility = Visibility.Visible;
|
||
MainWindow.mainViewModel.BaseStationMsg = "海底基站电源开启/关闭失败!";
|
||
MainWindow.mainViewModel.timerBaseStationMsgHidden.Start();
|
||
MainWindow.mainViewModel.BaseStationMsgForeground = new SolidColorBrush(Colors.Red);
|
||
|
||
record = "打开/关闭海底基站电源成功";
|
||
});
|
||
}
|
||
|
||
sql = $"insert into log_record(StationID,RecordTime,Device_Name,Operation_Type,Record) values('{id}','{DateTime.Now}','升压站电控通信系统','系统控制','{record}');";
|
||
DBHelper.ExecuteNonQuery(sql, 1);
|
||
|
||
//}
|
||
//else
|
||
//{
|
||
// if (Tools.CompareByte(byteList.ToArray(), MainViewModel.boosterStationStateDataViewModel2.RelayActivationRecv))
|
||
// {
|
||
// App.Current.Dispatcher.Invoke(() =>
|
||
// {
|
||
// // 更新UI的代码
|
||
// MainViewModel.boosterStationStateDataViewModel2.RelayActivationBtnIsReceived = true;
|
||
// MainViewModel.boosterStationStateDataViewModel2.RelayActivationBtnIsEnabled = true;
|
||
// MainViewModel.boosterStationStateDataViewModel2.timerRelayActivation.Stop();
|
||
// MainViewModel.boosterStationStateDataViewModel2.RelayControlMsgVisibility = Visibility.Visible;
|
||
// MainViewModel.boosterStationStateDataViewModel2.RelayControlMsg = "继电开启成功!";
|
||
// MainViewModel.boosterStationStateDataViewModel2.timerRelayControl.Start();
|
||
// MainViewModel.boosterStationStateDataViewModel2.RelayControlMsgForeground = new SolidColorBrush(Colors.Green);
|
||
|
||
// });
|
||
// }
|
||
|
||
// if (Tools.CompareByte(byteList.ToArray(), MainViewModel.boosterStationStateDataViewModel2.RelayShutdownRecv))
|
||
// {
|
||
// App.Current.Dispatcher.Invoke(() =>
|
||
// {
|
||
// // 更新UI的代码
|
||
// MainViewModel.boosterStationStateDataViewModel2.RelayShutdownBtnIsReceived = true;
|
||
// MainViewModel.boosterStationStateDataViewModel2.RelayShutdownBtnIsEnabled = true;
|
||
// MainViewModel.boosterStationStateDataViewModel2.timerRelayShutdown.Stop();
|
||
// MainViewModel.boosterStationStateDataViewModel2.RelayControlMsgVisibility = Visibility.Visible;
|
||
// MainViewModel.boosterStationStateDataViewModel2.RelayControlMsg = "继电关闭成功!";
|
||
// MainViewModel.boosterStationStateDataViewModel2.timerRelayControl.Start();
|
||
// MainViewModel.boosterStationStateDataViewModel2.RelayControlMsgForeground = new SolidColorBrush(Colors.Green);
|
||
// });
|
||
// }
|
||
//}
|
||
}
|
||
}
|
||
else if (byteList[1] == 0x10) //对从设备多个寄存器置数
|
||
{
|
||
//长度校验
|
||
if (byteList.Count != 8)
|
||
return;
|
||
|
||
if (byteList[2] == 0x01 && byteList[3] == 0x2D) //继电器报警阀值 1
|
||
{
|
||
//上下限报警、区间报警
|
||
if (id == 1)
|
||
{
|
||
if (Tools.CompareByte(byteList.ToArray(), MainViewModel.boosterStationStateDataViewModel1.AlarmThresholdRecv))
|
||
{
|
||
MainViewModel.boosterStationStateDataViewModel1.AlarmSetBtnIsReceived3 = true;
|
||
|
||
//若均为true,则说明报警设置成功
|
||
if (MainViewModel.boosterStationStateDataViewModel1.AlarmSetBtnIsReceived1 && MainViewModel.boosterStationStateDataViewModel1.AlarmSetBtnIsReceived2 && MainViewModel.boosterStationStateDataViewModel1.AlarmSetBtnIsReceived3)
|
||
{
|
||
App.Current.Dispatcher.Invoke(() =>
|
||
{
|
||
// 更新UI的代码
|
||
MainViewModel.boosterStationStateDataViewModel1.AlarmSetButtonIsEnabled = true;
|
||
MainViewModel.boosterStationStateDataViewModel1.timerAlarmSet.Stop();
|
||
MainViewModel.boosterStationStateDataViewModel1.AlarmSetMessage = "报警设置成功!";
|
||
MainViewModel.boosterStationStateDataViewModel1.AlarmSetMessageForeground = new SolidColorBrush(Colors.Green);
|
||
MainViewModel.boosterStationStateDataViewModel2.timerAlarmSetMsgCollapse.Start();
|
||
});
|
||
}
|
||
}
|
||
}
|
||
else
|
||
{
|
||
if (Tools.CompareByte(byteList.ToArray(), MainViewModel.boosterStationStateDataViewModel2.AlarmThresholdRecv))
|
||
{
|
||
MainViewModel.boosterStationStateDataViewModel2.AlarmSetBtnIsReceived3 = true;
|
||
|
||
//若均为true,则说明报警设置成功
|
||
if (MainViewModel.boosterStationStateDataViewModel2.AlarmSetBtnIsReceived1 && MainViewModel.boosterStationStateDataViewModel2.AlarmSetBtnIsReceived2 && MainViewModel.boosterStationStateDataViewModel2.AlarmSetBtnIsReceived3)
|
||
{
|
||
App.Current.Dispatcher.Invoke(() =>
|
||
{
|
||
// 更新UI的代码
|
||
MainViewModel.boosterStationStateDataViewModel2.AlarmSetButtonIsEnabled = true;
|
||
MainViewModel.boosterStationStateDataViewModel2.timerAlarmSet.Stop();
|
||
MainViewModel.boosterStationStateDataViewModel2.AlarmSetMessage = "报警设置成功!";
|
||
MainViewModel.boosterStationStateDataViewModel2.AlarmSetMessageForeground = new SolidColorBrush(Colors.Green);
|
||
MainViewModel.boosterStationStateDataViewModel2.timerAlarmSetMsgCollapse.Start();
|
||
});
|
||
}
|
||
}
|
||
}
|
||
}
|
||
}
|
||
}
|
||
}
|
||
}
|