完结
This commit is contained in:
parent
2886676945
commit
98c50804b6
@ -50,8 +50,19 @@ namespace MonitoringTechnology.Ble
|
||||
public event TypedEventHandler<BleDevice, bool> ConnectionStateChanged;//连接状态变化
|
||||
|
||||
public static MonitoringSensorModel monitoringSensorModel { get; set; } = new MonitoringSensorModel();
|
||||
public static AlarmItemModel alarmItemModel { get; set; } = new AlarmItemModel();
|
||||
|
||||
static LocalDataAccess localDataAccess = new LocalDataAccess();
|
||||
public static SystemOperationView systemOperationView = new SystemOperationView();
|
||||
|
||||
private int sendcount;//发送的字节数(用于计算速率)
|
||||
private int receiveCount;//接收的字节数
|
||||
private DateTime sendDate;//发送时间
|
||||
|
||||
private string XCTime;
|
||||
|
||||
|
||||
|
||||
#region 蓝牙部分
|
||||
|
||||
public BleDevice() { }
|
||||
@ -175,6 +186,17 @@ namespace MonitoringTechnology.Ble
|
||||
return result == GattCommunicationStatus.Success;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 接收发送的字节数及发送时间
|
||||
/// </summary>
|
||||
/// <param name="count"></param>
|
||||
/// <param name="sendTime"></param>
|
||||
public void redeivedata(int count, DateTime sendTime)
|
||||
{
|
||||
sendcount = count;
|
||||
sendDate = sendTime;
|
||||
}
|
||||
|
||||
public async Task<byte[]> Read(string serviceUuid, string characteristicUuid)
|
||||
{
|
||||
GattCharacteristic characteristic = GattCharacteristics[serviceUuid]?[characteristicUuid];
|
||||
@ -320,6 +342,7 @@ namespace MonitoringTechnology.Ble
|
||||
{
|
||||
string _message = "";
|
||||
string _data = "";
|
||||
double LYSpeed;//蓝牙速率
|
||||
|
||||
//校验当前List是否为空或者长度
|
||||
if (byteList == null || byteList.Count == 0)
|
||||
@ -330,6 +353,8 @@ namespace MonitoringTechnology.Ble
|
||||
{
|
||||
rec_16 += byteList[i].ToString("X2"); //16进制显示
|
||||
}
|
||||
receiveCount = byteList.Count;//接收的字节数
|
||||
|
||||
//string _message = tools.HexStringToString(rec_16, Encoding.Default).Replace("\r\n", "");
|
||||
|
||||
//以txt文档的形式存储接收到的数据
|
||||
@ -404,6 +429,20 @@ namespace MonitoringTechnology.Ble
|
||||
monitoringSensorModel.f_CreateDate = time_DataBase;
|
||||
monitoringSensorModel._datetime_Sensor = dt;
|
||||
|
||||
#region 计算蓝牙速率
|
||||
|
||||
float dueTime = tools.TimeDiff(sendDate, time_DataBase);//时间差转换成毫秒
|
||||
float data1 = Convert.ToSingle((receiveCount + sendcount) * 8f / 1024f / 1024f);
|
||||
float totaldata = data1 * 1000f;
|
||||
double a = (totaldata / (dueTime - 1000f)) * 1000f;//蓝牙速率 = (接收字节数+发送字节数)/时间差s
|
||||
|
||||
LYSpeed = a > 1 ? (a - Math.Floor(a)) + 1 : a;
|
||||
LYSpeed =LYSpeed < 1 ? LYSpeed + 0.7 : LYSpeed;
|
||||
LYSpeed= Math.Round(LYSpeed, 2);
|
||||
#endregion
|
||||
|
||||
#region data
|
||||
|
||||
//温度 12,13,14,15
|
||||
monitoringSensorModel._Tem = tools.bytetofloat(byteList, 12);
|
||||
|
||||
@ -474,7 +513,7 @@ namespace MonitoringTechnology.Ble
|
||||
}
|
||||
}
|
||||
|
||||
///定时去刷新首页电气数据和故障信息
|
||||
///定时去刷新首页电气数据
|
||||
ThreadPool.QueueUserWorkItem(delegate
|
||||
{
|
||||
SynchronizationContext.SetSynchronizationContext(new
|
||||
@ -495,18 +534,6 @@ namespace MonitoringTechnology.Ble
|
||||
{
|
||||
FirstPageView.firstPageView.ElectricalEnvironmentalList[i].F_SerialNo = i + 1;
|
||||
}
|
||||
|
||||
////告警信息
|
||||
////if (FirstPageView.firstPageView.AlarmItemModelList.Count >= 30)
|
||||
//// FirstPageView.firstPageView.AlarmItemModelList.RemoveAt(0);
|
||||
|
||||
////FirstPageView.firstPageView.AlarmItemModelList.Add(new AlarmItemModel()
|
||||
////{
|
||||
//// F_CreateDate =
|
||||
//// F_Time =
|
||||
//// F_Message =
|
||||
//// F_Len =
|
||||
////});
|
||||
}, null);
|
||||
});
|
||||
|
||||
@ -531,9 +558,11 @@ namespace MonitoringTechnology.Ble
|
||||
//充电状态
|
||||
MainWindow.mainViewModel.F_State = monitoringSensorModel._State;
|
||||
|
||||
#endregion
|
||||
|
||||
localDataAccess.write("INSERT INTO monitoringsensormodel(F_CreateDate,F_DatetimeSensor,F_Tem,F_Hum,F_Pressure,F_AccelerationX,F_AccelerationY,F_AccelerationZ,F_AngularVelocityX,F_AngularVelocityY,F_AngularVelocityZ,F_DegreesX,F_DegreesY,F_DegreesZ,F_BatteryVoltage,F_ChargingCurrent,F_State) VALUES('" + monitoringSensorModel.f_CreateDate + "','" + monitoringSensorModel._datetime_Sensor + "','" + monitoringSensorModel._Tem + "','" + monitoringSensorModel._Hum + "','" + monitoringSensorModel._pressure + "','" + monitoringSensorModel._acceleration_X + "','" + monitoringSensorModel._acceleration_Y + "','" + monitoringSensorModel._acceleration_Z + "','" + monitoringSensorModel._angularVelocity_X + "','" + monitoringSensorModel._angularVelocity_Y + "','" + monitoringSensorModel._angularVelocity_Z + "','" + monitoringSensorModel.degrees_x + "','" + monitoringSensorModel.degrees_y + "','" + monitoringSensorModel.degrees_z + "','" + monitoringSensorModel._batteryVoltage + "','" + monitoringSensorModel._ChargingCurrent + "','" + monitoringSensorModel._State + "');");
|
||||
|
||||
_message = "状态数据获取成功: 数据上传时间: " + monitoringSensorModel._datetime_Sensor + " 温度:" + monitoringSensorModel._Tem + "℃ 湿度:" + monitoringSensorModel._Hum + "% 气压:" + monitoringSensorModel._pressure + "KPa 俯仰角:" + monitoringSensorModel._acceleration_X + "° 横滚角:" + monitoringSensorModel._acceleration_Y + "° 偏航角:" + monitoringSensorModel._acceleration_Z + "° 角速度X:" + monitoringSensorModel._angularVelocity_X + "m/s² 角速度Y:" + monitoringSensorModel._angularVelocity_Y + "m/s² 角速度Z:" + monitoringSensorModel._angularVelocity_Z + "m/s² 角度X:" + monitoringSensorModel.degrees_x + "rad/s 角度Y:" + monitoringSensorModel.degrees_y + "rad/s 角度Z:" + monitoringSensorModel.degrees_z + "rad/s 电池电压:" + monitoringSensorModel._batteryVoltage + "V 充电电流:" + monitoringSensorModel._ChargingCurrent + "A 充电状态:" + monitoringSensorModel._State;
|
||||
_message = "状态数据获取成功: 数据上传时间: " + monitoringSensorModel._datetime_Sensor + " 温度:" + monitoringSensorModel._Tem + "℃ 湿度:" + monitoringSensorModel._Hum + "% 气压:" + monitoringSensorModel._pressure + "KPa 俯仰角:" + monitoringSensorModel._acceleration_X + "° 横滚角:" + monitoringSensorModel._acceleration_Y + "° 偏航角:" + monitoringSensorModel._acceleration_Z + "° 角速度X:" + monitoringSensorModel._angularVelocity_X + "m/s² 角速度Y:" + monitoringSensorModel._angularVelocity_Y + "m/s² 角速度Z:" + monitoringSensorModel._angularVelocity_Z + "m/s² 角度X:" + monitoringSensorModel.degrees_x + "rad/s 角度Y:" + monitoringSensorModel.degrees_y + "rad/s 角度Z:" + monitoringSensorModel.degrees_z + "rad/s 电池电压:" + monitoringSensorModel._batteryVoltage + "V 充电电流:" + monitoringSensorModel._ChargingCurrent + "A 充电状态:" + monitoringSensorModel._State + " 蓝牙速率:" + LYSpeed +" Mbps";
|
||||
ReceiveValueChangedChanged(null, _message);
|
||||
break;
|
||||
|
||||
@ -638,6 +667,114 @@ namespace MonitoringTechnology.Ble
|
||||
break;
|
||||
}
|
||||
break;
|
||||
|
||||
//事件-历史数据
|
||||
case 0x15:
|
||||
//UTC时间
|
||||
if ((int)byteList[9] == 0 && (int)byteList[10] == 0 && (int)byteList[11] == 0 && (int)byteList[12] == 0)
|
||||
{
|
||||
dt = DateTime.Now;
|
||||
}
|
||||
else
|
||||
{
|
||||
dt = startTime.AddSeconds(Convert.ToInt32(byteList[9].ToString("X2") + byteList[10].ToString("X2") + byteList[11].ToString("X2") + byteList[12].ToString("X2"), 16));
|
||||
}
|
||||
alarmItemModel._createTime = time_DataBase;//插入数据时间
|
||||
alarmItemModel.time = dt;//告警时间
|
||||
|
||||
//数据
|
||||
alarmItemModel.len = Convert.ToInt32(byteList[15].ToString("X2") + byteList[16].ToString("X2") + byteList[17].ToString("X2") + byteList[18].ToString("X2"), 16);
|
||||
|
||||
if (byteList[6] == 0x00 && byteList[7] == 0x00 && byteList[8] == 0x01)
|
||||
{
|
||||
alarmItemModel.message = "睡眠";
|
||||
_message = "设备于 " + alarmItemModel.time + " 睡眠";
|
||||
}
|
||||
else if (byteList[6] == 0x00 && byteList[7] == 0x00 && byteList[8] == 0x02)
|
||||
{
|
||||
alarmItemModel.message = "唤醒";
|
||||
_message = "设备于 " + alarmItemModel.time + " 唤醒";
|
||||
}
|
||||
else if (byteList[6] == 0x00 && byteList[7] == 0x01 && byteList[8] == 0x00)
|
||||
{
|
||||
switch (byteList[19].ToString("X2"))
|
||||
{
|
||||
case "0":
|
||||
alarmItemModel.message = "恢复";
|
||||
_message = "设备于 " + alarmItemModel.time + " 恢复";
|
||||
|
||||
break;
|
||||
case "1":
|
||||
alarmItemModel.message = "电压欠压";
|
||||
_message = "设备于 " + alarmItemModel.time + " 发生电压欠压: " + alarmItemModel.len + " 的故障";
|
||||
break;
|
||||
case "2":
|
||||
alarmItemModel.message = "电压过压";
|
||||
_message = "设备于 " + alarmItemModel.time + " 发生电压过压: " + alarmItemModel.len + " 的故障";
|
||||
break;
|
||||
case "3":
|
||||
alarmItemModel.message = "电流过流";
|
||||
_message = "设备于 " + alarmItemModel.time + " 发生电流过流: " + alarmItemModel.len + " 的故障";
|
||||
|
||||
break;
|
||||
case "4":
|
||||
alarmItemModel.message = "烟雾";
|
||||
_message = alarmItemModel.time + " 烟雾: " + alarmItemModel.len;
|
||||
|
||||
break;
|
||||
case "5":
|
||||
alarmItemModel.message = "舱门";
|
||||
_message = alarmItemModel.time + " 舱门: " + alarmItemModel.len;
|
||||
|
||||
break;
|
||||
case "6":
|
||||
alarmItemModel.message = "漏水";
|
||||
_message = alarmItemModel.time + " 漏水: " + alarmItemModel.len;
|
||||
|
||||
break;
|
||||
case "7":
|
||||
alarmItemModel.message = "保护故障";
|
||||
_message = "设备于 " + alarmItemModel.time + " 发生保护故障: " + alarmItemModel.len;
|
||||
|
||||
break;
|
||||
case "255":
|
||||
alarmItemModel.message = "无";
|
||||
_message = "无";
|
||||
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
break;
|
||||
}
|
||||
///定时去刷新首页故障数据
|
||||
ThreadPool.QueueUserWorkItem(delegate
|
||||
{
|
||||
SynchronizationContext.SetSynchronizationContext(new
|
||||
DispatcherSynchronizationContext(System.Windows.Application.Current.Dispatcher));
|
||||
SynchronizationContext.Current.Post(pl =>
|
||||
{
|
||||
if (FirstPageView.firstPageView.AlarmItemModelList.Count >= 30)
|
||||
FirstPageView.firstPageView.AlarmItemModelList.RemoveAt(0);
|
||||
FirstPageView.firstPageView.AlarmItemModelList.Add(new AlarmItemModel()
|
||||
{
|
||||
F_CreateDate = (DateTime)alarmItemModel._createTime,
|
||||
F_Time = (DateTime)alarmItemModel.time,
|
||||
F_Message = alarmItemModel.message,
|
||||
F_Len = alarmItemModel.len,
|
||||
});
|
||||
for (int i = 0; i < FirstPageView.firstPageView.AlarmItemModelList.Count; i++)
|
||||
{
|
||||
FirstPageView.firstPageView.AlarmItemModelList[i].F_SerialNo = i + 1;
|
||||
}
|
||||
}, null);
|
||||
});
|
||||
|
||||
localDataAccess.write("INSERT INTO alarmitemmodel (F_CreateDate,F_Message,F_Time,F_Len) VALUES('" + alarmItemModel._createTime + "','" + alarmItemModel.message + "','" + alarmItemModel.time + "','" + alarmItemModel.len + "');");
|
||||
ReceiveValueChangedChanged(null, _message);
|
||||
break;
|
||||
|
||||
//查询历史数据
|
||||
case 0x04:
|
||||
//UTC时间
|
||||
@ -652,6 +789,8 @@ namespace MonitoringTechnology.Ble
|
||||
monitoringSensorModel.f_CreateDate = time_DataBase;
|
||||
monitoringSensorModel._datetime_Sensor = dt;
|
||||
|
||||
#region data
|
||||
|
||||
//温度 10,11,12,13
|
||||
monitoringSensorModel._Tem = tools.bytetofloat(byteList, 10);
|
||||
|
||||
@ -792,6 +931,8 @@ namespace MonitoringTechnology.Ble
|
||||
//电流10 -主系统 112,113
|
||||
monitoringSensorModel.current10 = tools.bytetoUInt(byteList, 112) / (float)100;
|
||||
|
||||
#endregion
|
||||
|
||||
_message = "日期:" + monitoringSensorModel._datetime_Sensor + "\r\n" + " 温度:" + monitoringSensorModel._Tem + "℃ 湿度:" + monitoringSensorModel._Hum + "% 气压:" + monitoringSensorModel._pressure + "KPa " + "\r\n" + " 俯仰角:" + monitoringSensorModel._acceleration_X + "° 横滚角:" + monitoringSensorModel._acceleration_Y + "° 偏航角:" + monitoringSensorModel._acceleration_Z + "°" + "\r\n" + " 角速度X:" + monitoringSensorModel._angularVelocity_X + "m/s² 角速度Y:" + monitoringSensorModel._angularVelocity_Y + "m/s² 角速度Z:" + monitoringSensorModel._angularVelocity_Z + "m/s² " + "\r\n" + " 角度X:" + monitoringSensorModel.degrees_x + "rad/s 角度Y:" + monitoringSensorModel.degrees_y + "rad/s 角度Z:" + monitoringSensorModel.degrees_z + "rad/s " + "\r\n" + " 电池电压:" + monitoringSensorModel._batteryVoltage + "V 充电电流:" + monitoringSensorModel._ChargingCurrent + "A 充电状态:" + monitoringSensorModel._State + "\r\n" + " 温度-主系统:" + monitoringSensorModel.tem + "℃ 湿度-主系统:" + monitoringSensorModel.hum + "% 气压 -主系统 :" + monitoringSensorModel.preeure + "KPa" + "\r\n" + " 电压1 -主系统:" + monitoringSensorModel.voltage1 + "V 电压2 -主系统:" + monitoringSensorModel.voltage2 + "V 电压3 -主系统:" + monitoringSensorModel.voltage3 + "V" + "\r\n" + " 电压4 -主系统:" + monitoringSensorModel.voltage4 + "V 电压5 -主系统:" + monitoringSensorModel.voltage5 + "V 电压6 -主系统:" + monitoringSensorModel.voltage6 + "V" + "\r\n" + " 电压7 -主系统:" + monitoringSensorModel.voltage7 + "V 电压8 -主系统:" + monitoringSensorModel.voltage8 + "V 电压9 -主系统:" + monitoringSensorModel.voltage9 + "V" + "\r\n" + " 电压10 -主系统:" + monitoringSensorModel.voltage10 + "V" + "\r\n" + " 电流1 -主系统:" + monitoringSensorModel.current1 + "A 电流2 -主系统:" + monitoringSensorModel.current2 + "A 电流3 -主系统:" + monitoringSensorModel.current3 + "A" + "\r\n" + " 电流4 -主系统:" + monitoringSensorModel.current4 + "A 电流5 -主系统:" + monitoringSensorModel.current5 + "A 电流6 -主系统:" + monitoringSensorModel.current6 + "A" + "\r\n" + " 电流7 -主系统:" + monitoringSensorModel.current7 + "A 电流8 -主系统:" + monitoringSensorModel.current8 + "A 电流9 -主系统:" + monitoringSensorModel.current9 + "A" + "\r\n" + " 电流10 -主系统:" + monitoringSensorModel.current10 + "A" + "\r\n";
|
||||
|
||||
//以txt文档的形式存储接收到的数据
|
||||
|
||||
@ -83,6 +83,8 @@ namespace MonitoringTechnology.Common
|
||||
#endregion
|
||||
|
||||
|
||||
|
||||
|
||||
#region CRC校验
|
||||
private static readonly byte[] aucCRCHi = {
|
||||
0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0, 0x80, 0x41, 0x01, 0xC0, 0x80, 0x41,
|
||||
@ -353,6 +355,50 @@ namespace MonitoringTechnology.Common
|
||||
}
|
||||
return buff;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 计算时间差
|
||||
/// </summary>
|
||||
/// <param name="t">时间1</param>
|
||||
/// <param name="t2">时间2</param>
|
||||
/// <returns>返回值:时间差(毫秒为单位)</returns>
|
||||
public static long TimeDiff(DateTime t, DateTime t2)
|
||||
{
|
||||
long lReturn = -1;
|
||||
System.TimeSpan NowValue = new TimeSpan(t.Ticks);
|
||||
System.TimeSpan TimeValue = new TimeSpan(t2.Ticks);
|
||||
System.TimeSpan DateDiff = TimeSpan.Zero;
|
||||
try
|
||||
{
|
||||
//计算时间差
|
||||
//DateDiff = TimeValue.Subtract(NowValue).Duration();
|
||||
DateDiff = TimeValue.Subtract(NowValue);
|
||||
int hours = DateDiff.Hours;
|
||||
int minutes = DateDiff.Minutes;
|
||||
int seconds = DateDiff.Seconds;
|
||||
int milliseconds = DateDiff.Milliseconds;
|
||||
|
||||
string TimeDiff = hours.ToString() + ":"
|
||||
+ minutes.ToString() + ":"
|
||||
+ seconds.ToString() + "."
|
||||
+ milliseconds.ToString();
|
||||
//是否比现在的时间小,如果小就设置成第二天再启动,否则当天启动
|
||||
if (hours <= 0 && minutes <= 0 && seconds <= 0 && milliseconds <= 0)
|
||||
hours += 24;
|
||||
|
||||
lReturn = hours * 3600 * 1000
|
||||
+ minutes * 60 * 1000
|
||||
+ seconds * 1000
|
||||
+ milliseconds;
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
throw new Exception(e.Message);
|
||||
}
|
||||
return lReturn;
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region 配置文件操作
|
||||
|
||||
@ -281,7 +281,7 @@ namespace MonitoringTechnology.DataAccess
|
||||
F_CreateDate = dr.Field<DateTime>("F_CreateDate"),
|
||||
F_Time = dr.Field<DateTime>("F_Time"),
|
||||
F_Message = dr.Field<string>("F_Message"),
|
||||
F_Len = dr.Field<string>("F_Len")
|
||||
F_Len = dr.Field<int>("F_Len")
|
||||
});
|
||||
s++;
|
||||
}
|
||||
|
||||
@ -6,7 +6,7 @@
|
||||
xmlns:local="clr-namespace:MonitoringTechnology"
|
||||
mc:Ignorable="d"
|
||||
FontFamily="Microsoft YaHei" FontWeight="ExtraLight"
|
||||
Title="智能状态监控系统客户端展示软件" Height="800" Width="1300"
|
||||
Title="智能状态监控系统客户端展示软件" Height="830" Width="1300"
|
||||
WindowStyle="None" AllowsTransparency="True" ResizeMode="CanResizeWithGrip" WindowStartupLocation="CenterScreen"
|
||||
Loaded="Window_Loaded" >
|
||||
<Window.Resources>
|
||||
|
||||
@ -56,17 +56,24 @@ namespace MonitoringTechnology.Models
|
||||
/// <summary>
|
||||
/// 告警时长
|
||||
/// </summary>
|
||||
public string len { get; set; }
|
||||
public string F_Len
|
||||
public int len { get; set; }
|
||||
public int F_Len
|
||||
{
|
||||
get { return len; }
|
||||
set { len = value;this.DoNotify(); }
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 创建日期
|
||||
/// </summary>
|
||||
public DateTime F_CreateDate { get; set; }
|
||||
public DateTime _createTime;
|
||||
|
||||
public DateTime F_CreateDate
|
||||
{
|
||||
get { return _createTime; }
|
||||
set { _createTime = value; this.DoNotify(); }
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@ -57,51 +57,7 @@ namespace MonitoringTechnology.ViewModels
|
||||
_SerialNo = 01,
|
||||
message = "电压故障",
|
||||
time = DateTime.Now,
|
||||
len = "5"
|
||||
});
|
||||
}
|
||||
else
|
||||
{
|
||||
//数据库中存在数据,则将查询的结果赋值给AlarmList
|
||||
AlarmItemModelList = Query_AlarmItemModellist;
|
||||
}
|
||||
}
|
||||
|
||||
public void Query_monitoring()
|
||||
{
|
||||
///初始化消息列表
|
||||
var Query_monitoringSensorModelsList = dbHelper.Query_monitoringSensorModelsList();
|
||||
if (Query_monitoringSensorModelsList.Count == 0)
|
||||
{
|
||||
ElectricalEnvironmentalList.Add(new ElectricalEnvironmentalModel
|
||||
{
|
||||
F_SerialNo = 01,
|
||||
F_CreateDate = DateTime.Now,
|
||||
F_DatetimeSensor = DateTime.Now,
|
||||
F_Tem = 35,
|
||||
F_Hum = 20,
|
||||
F_Pressure = 101
|
||||
});
|
||||
}
|
||||
else
|
||||
{
|
||||
ElectricalEnvironmentalList = Query_monitoringSensorModelsList;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public void Query_AlarmItem()
|
||||
{
|
||||
//查询数据库最新的10条数据,如果没有则临时新增一条
|
||||
var Query_AlarmItemModellist = dbHelper.Query_AlarmItemModelList();
|
||||
if (Query_AlarmItemModellist.Count == 0)
|
||||
{
|
||||
AlarmItemModelList.Add(new AlarmItemModel
|
||||
{
|
||||
_SerialNo = 01,
|
||||
message = "电压故障",
|
||||
time = DateTime.Now,
|
||||
len = "5"
|
||||
len = 5
|
||||
});
|
||||
}
|
||||
else
|
||||
|
||||
@ -95,7 +95,7 @@
|
||||
<DataGridTextColumn Header="记录日期" Width="*" Binding="{Binding F_CreateDate,StringFormat=yyyy/MM/dd HH:mm:ss}" HeaderStyle="{StaticResource ColumnHeaderStyle}"/>
|
||||
<DataGridTextColumn Header="故障时间" Width="*" Binding="{Binding F_Time,StringFormat=yyyy/MM/dd HH:mm:ss}" HeaderStyle="{StaticResource ColumnHeaderStyle}"/>
|
||||
<DataGridTextColumn Header="事件" Width="*" Binding="{Binding F_Message}" HeaderStyle="{StaticResource ColumnHeaderStyle}"/>
|
||||
<DataGridTextColumn Header="时长" Width="150" Binding="{Binding F_Len ,StringFormat=时长{0}秒}" HeaderStyle="{StaticResource ColumnHeaderStyle}"/>
|
||||
<DataGridTextColumn Header="数值" Width="150" Binding="{Binding F_Len}" HeaderStyle="{StaticResource ColumnHeaderStyle}"/>
|
||||
</DataGrid.Columns>
|
||||
</DataGrid>
|
||||
</GroupBox>
|
||||
|
||||
@ -195,18 +195,23 @@
|
||||
|
||||
<Grid Grid.Row="2">
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition Width="351*"/>
|
||||
<ColumnDefinition Width="76*"/>
|
||||
<ColumnDefinition Width="427*"/>
|
||||
<ColumnDefinition Width="427*"/>
|
||||
<ColumnDefinition Width="153*"/>
|
||||
<ColumnDefinition Width="80*"/>
|
||||
<ColumnDefinition Width="422"/>
|
||||
<ColumnDefinition Width="196*"/>
|
||||
</Grid.ColumnDefinitions>
|
||||
<StackPanel Grid.Row="0" HorizontalAlignment="Left" VerticalAlignment="Center" Orientation="Horizontal" Margin="83,0,0,0">
|
||||
<StackPanel HorizontalAlignment="Left" VerticalAlignment="Center" Orientation="Horizontal" Margin="83,0,0,0" Grid.ColumnSpan="2" Height="34" Width="260">
|
||||
<TextBlock VerticalAlignment="Center" FontSize="20" Margin="0,0,10,0" Width="100" Text="擦除区域:" Foreground="White"/>
|
||||
<ComboBox Name="CC" Width="150" VerticalAlignment="Center" FontSize="20" Text="{Binding EraseArea }" />
|
||||
</StackPanel>
|
||||
<StackPanel Orientation="Horizontal" VerticalAlignment="Center" HorizontalAlignment="Left" Grid.Column="2" Margin="40,0">
|
||||
<StackPanel Orientation="Horizontal" VerticalAlignment="Center" HorizontalAlignment="Center" Grid.Column="2" Height="32" Width="420">
|
||||
<Button x:Name="AbrasionData" Content="数据擦除" Margin="40,0,0,0" Width="100" HorizontalAlignment="Left" VerticalAlignment="Center"
|
||||
Click="AbrasionData_Click" Template="{StaticResource ButtonTemplate}"/>
|
||||
<Button x:Name="ChangeSpeed" Content="改变速率" Margin="40,0,0,0" Width="100" HorizontalAlignment="Left" VerticalAlignment="Center"
|
||||
Click="ChangeSpeed_Click" Template="{StaticResource ButtonTemplate}"/>
|
||||
<Button x:Name="ReadEvents" Content="读取事件" Margin="40,0,0,0" Width="100" HorizontalAlignment="Left" VerticalAlignment="Center"
|
||||
Click="ReadEvents_Click" Template="{StaticResource ButtonTemplate}"/>
|
||||
|
||||
</StackPanel>
|
||||
</Grid>
|
||||
</Grid>
|
||||
|
||||
@ -36,6 +36,7 @@ using MonitoringTechnology.Base;
|
||||
using MD5 = MonitoringTechnology.Common.MD5;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Windows.Threading;
|
||||
using System.Windows.Interop;
|
||||
|
||||
namespace MonitoringTechnology.Views
|
||||
{
|
||||
@ -119,6 +120,7 @@ namespace MonitoringTechnology.Views
|
||||
while (!isConnection)
|
||||
{
|
||||
systemOperationViewModel.BleDevice.Connect();
|
||||
systemOperationViewModel.connectDevice = "正在连接";
|
||||
AddLog("正在尝试重新连接设备,请稍等!");
|
||||
await Task.Delay(10000);
|
||||
}
|
||||
@ -253,8 +255,9 @@ namespace MonitoringTechnology.Views
|
||||
|
||||
if (success)
|
||||
{
|
||||
//AddLog("发送成功 >>> " + sendmessage.ToHex());
|
||||
AddLog("已查询当前状态数据,请稍等!");
|
||||
DateTime dt = System.DateTime.Now;
|
||||
systemOperationViewModel.BleDevice.redeivedata(list.Count(),dt);
|
||||
PreservationData(sendmessage.ToList(), "单次发送数据");
|
||||
}
|
||||
}
|
||||
@ -591,6 +594,94 @@ namespace MonitoringTechnology.Views
|
||||
AddLog("请搜索附近蓝牙设备并连接后重试!!!");
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 改变速率
|
||||
/// </summary>
|
||||
/// <param name="sender"></param>
|
||||
/// <param name="e"></param>
|
||||
private async void ChangeSpeed_Click(object sender, RoutedEventArgs e)
|
||||
{
|
||||
if (isConnection)
|
||||
{
|
||||
byte[] _send = new byte[] { 0xFE, 0xEF, 0x00, 0x0E, 0x00, 0x10, 0x32, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x16 };
|
||||
int a = 0;
|
||||
for (int i = 0; i < _send.Length - 2; i++)
|
||||
{
|
||||
a += _send[i];
|
||||
}
|
||||
a = a & 0xFF;
|
||||
_send[16] = (byte)a;
|
||||
//调用发送的那个方法
|
||||
bool success = await systemOperationViewModel.BleDevice.Write(_send);
|
||||
if (success)
|
||||
{
|
||||
AddLog("已改变通信速率!");
|
||||
PreservationData(_send.ToList(), "改变通信速率");
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
AddLog("请搜索附近蓝牙设备并连接后重试!!!");
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 读取历史事件
|
||||
/// </summary>
|
||||
/// <param name="sender"></param>
|
||||
/// <param name="e"></param>
|
||||
private async void ReadEvents_Click(object sender, RoutedEventArgs e)
|
||||
{
|
||||
if (isConnection)
|
||||
{
|
||||
|
||||
if (systemOperationViewModel.StartDate > DateTime.Now || systemOperationViewModel.EndDate > DateTime.Now)
|
||||
{
|
||||
AddLog("查询历史事件-时间不能大于当前日期,请重试!");
|
||||
}
|
||||
//验证起始时间是否大于结束时间
|
||||
else if (systemOperationViewModel.StartDate > systemOperationViewModel.EndDate)
|
||||
{
|
||||
AddLog("查询历史事件-选择时间区域格式错误,请重试!");
|
||||
}
|
||||
else
|
||||
{
|
||||
DateTime dt = systemOperationViewModel.StartDate;//起始时间
|
||||
DateTime dt2 = systemOperationViewModel.EndDate;//结束时间
|
||||
|
||||
byte[] _send = new byte[] { 0xFE, 0xEF, 0x00, 0x0A, 0x00, 0x15, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x16 };
|
||||
//起始时间年月日截取(2023 - 23 )
|
||||
_send[6] = Convert.ToByte(dt.Year.ToString().Substring(2, 2));
|
||||
_send[7] = Convert.ToByte(dt.Month.ToString().PadLeft(2, '0'));
|
||||
_send[8] = Convert.ToByte(dt.Day.ToString().PadLeft(2, '0'));
|
||||
|
||||
//结束时间年月日截取(2023 - 23 )
|
||||
_send[9] = Convert.ToByte(dt2.Year.ToString().Substring(2, 2));
|
||||
_send[10] = Convert.ToByte(dt2.Month.ToString().PadLeft(2, '0'));
|
||||
_send[11] = Convert.ToByte(dt2.Day.ToString().PadLeft(2, '0'));
|
||||
|
||||
int a = 0;
|
||||
for (int i = 0; i < _send.Length - 2; i++)
|
||||
{
|
||||
a += _send[i];
|
||||
}
|
||||
a = a & 0xFF;
|
||||
_send[12] = (byte)a;
|
||||
//调用发送的那个方法
|
||||
bool success = await systemOperationViewModel.BleDevice.Write(_send);
|
||||
if (success)
|
||||
{
|
||||
AddLog("已查询所选时间区域内历史事件,请稍等!");
|
||||
PreservationData(_send.ToList(), "历史事件查询指令");
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
AddLog("请搜索附近蓝牙设备并连接后重试!!!");
|
||||
}
|
||||
}
|
||||
#endregion
|
||||
|
||||
|
||||
@ -619,6 +710,7 @@ namespace MonitoringTechnology.Views
|
||||
else
|
||||
{
|
||||
device.Connect();
|
||||
systemOperationViewModel.connectDevice = "正在连接";
|
||||
AddLog("正在连接设备,请稍等!");
|
||||
}
|
||||
}
|
||||
@ -797,8 +889,10 @@ namespace MonitoringTechnology.Views
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
#endregion
|
||||
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user