From 3a279d73a0ca336f91dcd10c4937557f542d560c Mon Sep 17 00:00:00 2001
From: maqiao <625215135@qq.com>
Date: Tue, 2 Jul 2024 16:29:00 +0800
Subject: [PATCH] =?UTF-8?q?=E5=86=B0=E7=AE=B1=E6=8C=87=E4=BB=A4=E6=A0=B9?=
=?UTF-8?q?=E6=8D=AE=E5=9C=B0=E5=9D=80=E9=80=89=E6=8B=A9=E5=8F=91=E9=80=81?=
=?UTF-8?q?=E6=8C=87=E4=BB=A4=E4=BF=A1=E6=81=AF?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
DM_Weight/Port/PortUtil.cs | 122 +++++++++++++++---
DM_Weight/ViewModels/FridgeWindowViewModel.cs | 24 ++--
2 files changed, 113 insertions(+), 33 deletions(-)
diff --git a/DM_Weight/Port/PortUtil.cs b/DM_Weight/Port/PortUtil.cs
index 3180486..e9dc7f7 100644
--- a/DM_Weight/Port/PortUtil.cs
+++ b/DM_Weight/Port/PortUtil.cs
@@ -27,6 +27,7 @@ using DM_Weight.HIKVISION;
using PreviewDemo;
using System.Runtime.InteropServices;
using DM_Weight.Common;
+using System.Net;
namespace DM_Weight.Port
{
@@ -1317,12 +1318,21 @@ namespace DM_Weight.Port
/// 冰箱使能
///
///
- public async Task FridegOpen()
+ public async Task FridegOpen(int iIndex)
{
try
{
fridgeSerial.DiscardInBuffer();
- byte[] buffer = new byte[] { 0x01, 0x06, 0x10, 0xD4, 0x00, 0x01, 0x0C, 0xF2 };
+ byte bAddress;
+ if (iIndex == 1)
+ {
+ bAddress = 0x01;
+ }
+ else
+ {
+ bAddress = 0x02;
+ }
+ byte[] buffer = new byte[] { bAddress, 0x06, 0x10, 0xD4, 0x00, 0x01, 0x0C, 0xF2 };
//byte[] buffer = new byte[] { 0x01, 0x06, 0x10, 0xD4, 0x00, 0x01 };
////获取数组CRC校验码
//byte[] byteDate = CRC16MODBUS.CrcModBus(buffer);
@@ -1347,12 +1357,21 @@ namespace DM_Weight.Port
/// 冰箱失能
///
///
- public async Task FridgeOff()
+ public async Task FridgeOff(int iIndex)
{
try
{
- fridgeSerial.DiscardInBuffer();
- byte[] buffer = new byte[] { 0x01, 0x06, 0x10, 0xD4, 0x00, 0x00, 0xCD, 0x32 };
+ fridgeSerial.DiscardInBuffer();
+ byte bAddress;
+ if (iIndex == 1)
+ {
+ bAddress = 0x01;
+ }
+ else
+ {
+ bAddress = 0x02;
+ }
+ byte[] buffer = new byte[] { bAddress, 0x06, 0x10, 0xD4, 0x00, 0x00, 0xCD, 0x32 };
//byte[] buffer = new byte[] { 0x01, 0x06, 0x10, 0xD4, 0x00, 0x01 };
////获取数组CRC校验码
//byte[] byteDate = CRC16MODBUS.CrcModBus(buffer);
@@ -1377,12 +1396,21 @@ namespace DM_Weight.Port
/// 冰箱报警使能
///
///
- public async Task FridgeAlarmOn()
+ public async Task FridgeAlarmOn(int iIndex)
{
try
{
- fridgeSerial.DiscardInBuffer();
- byte[] buffer = new byte[] { 0x01, 0x06, 0x10, 0xD5, 0x00, 0x01, 0x5D, 0x32 };
+ fridgeSerial.DiscardInBuffer();
+ byte bAddress;
+ if (iIndex == 1)
+ {
+ bAddress = 0x01;
+ }
+ else
+ {
+ bAddress = 0x02;
+ }
+ byte[] buffer = new byte[] { bAddress, 0x06, 0x10, 0xD5, 0x00, 0x01, 0x5D, 0x32 };
//byte[] buffer = new byte[] { 0x01, 0x06, 0x10, 0xD5, 0x00, 0x01 };
////获取数组CRC校验码
//byte[] byteDate = CRC16MODBUS.CrcModBus(buffer);
@@ -1409,12 +1437,21 @@ namespace DM_Weight.Port
/// 冰箱报警失能
///
///
- public async Task FridgeAlarmOff()
+ public async Task FridgeAlarmOff(int iIndex)
{
try
{
fridgeSerial.DiscardInBuffer();
- byte[] buffer = new byte[] { 0x01, 0x06, 0x10, 0xD5, 0x00, 0x00, 0x9C, 0xF2 };
+ byte bAddress;
+ if (iIndex == 1)
+ {
+ bAddress = 0x01;
+ }
+ else
+ {
+ bAddress = 0x02;
+ }
+ byte[] buffer = new byte[] { bAddress, 0x06, 0x10, 0xD5, 0x00, 0x00, 0x9C, 0xF2 };
//byte[] buffer = new byte[] { 0x01, 0x06, 0x10, 0xD5, 0x00, 0x00 };
////获取数组CRC校验码
//byte[] byteDate = CRC16MODBUS.CrcModBus(buffer);
@@ -1439,7 +1476,7 @@ namespace DM_Weight.Port
/// 冰箱温度设定最小
///
///
- public async Task FridgeMinSetting(float min)
+ public async Task FridgeMinSetting(float min,int iIndex)
{
try
{
@@ -1447,7 +1484,16 @@ namespace DM_Weight.Port
int iMix = Convert.ToInt32(min * 10);
fridgeSerial.DiscardInBuffer();
//byte[] bufferMin = new byte[] { 0x01, 0x06, 0x10, 0xC9, 0x00, 0x15, 0x9C, 0xFB };
- byte[] bufferMin = new byte[] { 0x01, 0x06, 0x10, 0xC9, 0x00, (byte)(iMix & 0xff) };
+ byte bAddress;
+ if (iIndex == 1)
+ {
+ bAddress = 0x01;
+ }
+ else
+ {
+ bAddress = 0x02;
+ }
+ byte[] bufferMin = new byte[] { bAddress, 0x06, 0x10, 0xC9, 0x00, (byte)(iMix & 0xff) };
//获取数组CRC校验码
byte[] byteDate = CRC16MODBUS.CrcModBus(bufferMin);
//Array.Reverse(byteDate);
@@ -1469,14 +1515,23 @@ namespace DM_Weight.Port
/// 冰箱温度设定最大
///
///
- public async Task FridgeMaxSetting(float max)
+ public async Task FridgeMaxSetting(float max,int iIndex)
{
try
{
int iMax = Convert.ToInt32(max * 10);
fridgeSerial.DiscardInBuffer();
//byte[] bufferMin = new byte[] { 0x01, 0x06, 0x10, 0xC9, 0x00, 0x15, 0x9C, 0xFB };
- byte[] bufferMax = new byte[] { 0x01, 0x06, 0x10, 0xC8, 0x00, (byte)(iMax & 0xff) };
+ byte bAddress;
+ if (iIndex == 1)
+ {
+ bAddress = 0x01;
+ }
+ else
+ {
+ bAddress = 0x02;
+ }
+ byte[] bufferMax = new byte[] { bAddress, 0x06, 0x10, 0xC8, 0x00, (byte)(iMax & 0xff) };
//获取数组CRC校验码
byte[] byteDate = CRC16MODBUS.CrcModBus(bufferMax);
//Array.Reverse(byteDate);
@@ -1504,8 +1559,16 @@ namespace DM_Weight.Port
try
{
fridgeSerial.DiscardInBuffer();
-
- byte[] buffer = new byte[] { 0x01, 0x03, 0x10, 0x02, 0x00, 0x01, 0x21, 0x0A };
+ byte bAddress;
+ if (iIndex == 1 )
+ {
+ bAddress=0x01;
+ }
+ else
+ {
+ bAddress = 0x02;
+ }
+ byte[] buffer = new byte[] { bAddress, 0x03, 0x10, 0x02, 0x00, 0x01, 0x21, 0x0A };
//byte[] buffer = new byte[] { 0x01, 0x03, 0x10, 0x02, 0x00, 0x01 };
////获取数组CRC校验码
@@ -1545,7 +1608,7 @@ namespace DM_Weight.Port
/// 设置冰箱温度
///
///
- public async Task SetFridgeTemperature(float temperature)
+ public async Task SetFridgeTemperature(float temperature,int iIndex)
{
int tpt = (int)temperature * 10;
byte Temperature = (byte)(tpt & 0xff);
@@ -1554,9 +1617,17 @@ namespace DM_Weight.Port
//if (!FridgeOperate)
{
fridgeSerial.DiscardInBuffer();
-
+ byte bAddress;
+ if (iIndex == 1)
+ {
+ bAddress = 0x01;
+ }
+ else
+ {
+ bAddress = 0x02;
+ }
//byte[] buffer = new byte[] { 0x01, 0x03, 0x10, 0x02, 0x00, 0x01, 0x21,0x0A };
- byte[] buffer = new byte[] { 0x01, 0x06, 0x10, 0x02, 0x00, (byte)Temperature };
+ byte[] buffer = new byte[] { bAddress, 0x06, 0x10, 0x02, 0x00, (byte)Temperature };
//获取数组CRC校验码
byte[] byteDate = CRC16MODBUS.CrcModBus(buffer);
@@ -1584,14 +1655,23 @@ namespace DM_Weight.Port
/// 冰箱延迟报警
///
///
- public async Task FridgeDelayWarm()
+ public async Task FridgeDelayWarm(int iIndex)
{
try
{
//if (!FridgeOperate)
{
fridgeSerial.DiscardInBuffer();
- byte[] buffer = new byte[] { 0x01, 0x06, 0x10, 0xCD, 0x00, 0x01, 0xDD, 0x35 };
+ byte bAddress;
+ if (iIndex == 1)
+ {
+ bAddress = 0x01;
+ }
+ else
+ {
+ bAddress = 0x02;
+ }
+ byte[] buffer = new byte[] { bAddress, 0x06, 0x10, 0xCD, 0x00, 0x01, 0xDD, 0x35 };
//byte[] buffer = new byte[] { 0x01, 0x06, 0x10, 0xCD, 0x00, 0x01 };
////获取数组CRC校验码
//byte[] byteDate = CRC16MODBUS.CrcModBus(buffer);
diff --git a/DM_Weight/ViewModels/FridgeWindowViewModel.cs b/DM_Weight/ViewModels/FridgeWindowViewModel.cs
index e5ccaea..8e2f4f4 100644
--- a/DM_Weight/ViewModels/FridgeWindowViewModel.cs
+++ b/DM_Weight/ViewModels/FridgeWindowViewModel.cs
@@ -139,13 +139,13 @@ namespace DM_Weight.ViewModels
//发送冰箱使能/失能指令
if (_fridgeState)
{
- await _portUtil.FridgeOff();
+ await _portUtil.FridgeOff(1);
Thread.Sleep(100);
CommonClass.SaveAppSetting("FridgeState", "0");
}
else
{
- await _portUtil.FridegOpen();
+ await _portUtil.FridegOpen(1);
Thread.Sleep(100);
CommonClass.SaveAppSetting("FridgeState", "1");
}
@@ -153,13 +153,13 @@ namespace DM_Weight.ViewModels
//冰箱2 发送冰箱使能/失能指令
if (_fridgeState2)
{
- await _portUtil.FridgeOff();
+ await _portUtil.FridgeOff(2);
Thread.Sleep(100);
CommonClass.SaveAppSetting("FridgeState2", "0");
}
else
{
- await _portUtil.FridegOpen();
+ await _portUtil.FridegOpen(2);
Thread.Sleep(100);
CommonClass.SaveAppSetting("FridgeState2", "1");
}
@@ -170,13 +170,13 @@ namespace DM_Weight.ViewModels
//发送警报使能/失能指令
if (_alarmState)
{
- await _portUtil.FridgeAlarmOff();
+ await _portUtil.FridgeAlarmOff(1);
Thread.Sleep(100);
CommonClass.SaveAppSetting("AlarmState", "0");
}
else
{
- await _portUtil.FridgeAlarmOn();
+ await _portUtil.FridgeAlarmOn(1);
Thread.Sleep(100);
CommonClass.SaveAppSetting("AlarmState", "1");
}
@@ -184,13 +184,13 @@ namespace DM_Weight.ViewModels
//冰箱2 发送警报使能/失能指令
if (_alarmState2)
{
- await _portUtil.FridgeAlarmOff();
+ await _portUtil.FridgeAlarmOff(2);
Thread.Sleep(100);
CommonClass.SaveAppSetting("AlarmState2", "0");
}
else
{
- await _portUtil.FridgeAlarmOn();
+ await _portUtil.FridgeAlarmOn(2);
Thread.Sleep(100);
CommonClass.SaveAppSetting("AlarmState2", "1");
}
@@ -216,14 +216,14 @@ namespace DM_Weight.ViewModels
if (Min != Convert.ToSingle(newRange[0]))
{
//设定冰箱温度最小值
- await _portUtil.FridgeMinSetting(Convert.ToSingle(newRange[0]));
+ await _portUtil.FridgeMinSetting(Convert.ToSingle(newRange[0]),1);
Thread.Sleep(100);
}
if (Max != Convert.ToSingle(newRange[1]))
{
Thread.Sleep(100);
//设定冰箱温度最大值
- await _portUtil.FridgeMaxSetting(Convert.ToSingle(newRange[1]));
+ await _portUtil.FridgeMaxSetting(Convert.ToSingle(newRange[1]), 1);
Thread.Sleep(100);
}
}
@@ -242,14 +242,14 @@ namespace DM_Weight.ViewModels
if (Min != Convert.ToSingle(newRange2[0]))
{
//设定冰箱温度最小值
- await _portUtil.FridgeMinSetting(Convert.ToSingle(newRange2[0]));
+ await _portUtil.FridgeMinSetting(Convert.ToSingle(newRange2[0]), 2);
Thread.Sleep(100);
}
if (Max != Convert.ToSingle(newRange2[1]))
{
Thread.Sleep(100);
//设定冰箱温度最大值
- await _portUtil.FridgeMaxSetting(Convert.ToSingle(newRange2[1]));
+ await _portUtil.FridgeMaxSetting(Convert.ToSingle(newRange2[1]), 2);
Thread.Sleep(100);
}
}