冰箱指令根据地址选择发送指令信息

This commit is contained in:
maqiao 2024-07-02 16:29:00 +08:00
parent cb09e98cbd
commit 3a279d73a0
2 changed files with 113 additions and 33 deletions

View File

@ -27,6 +27,7 @@ using DM_Weight.HIKVISION;
using PreviewDemo; using PreviewDemo;
using System.Runtime.InteropServices; using System.Runtime.InteropServices;
using DM_Weight.Common; using DM_Weight.Common;
using System.Net;
namespace DM_Weight.Port namespace DM_Weight.Port
{ {
@ -1317,12 +1318,21 @@ namespace DM_Weight.Port
/// 冰箱使能 /// 冰箱使能
/// </summary> /// </summary>
/// <returns></returns> /// <returns></returns>
public async Task FridegOpen() public async Task FridegOpen(int iIndex)
{ {
try try
{ {
fridgeSerial.DiscardInBuffer(); 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 }; //byte[] buffer = new byte[] { 0x01, 0x06, 0x10, 0xD4, 0x00, 0x01 };
////获取数组CRC校验码 ////获取数组CRC校验码
//byte[] byteDate = CRC16MODBUS.CrcModBus(buffer); //byte[] byteDate = CRC16MODBUS.CrcModBus(buffer);
@ -1347,12 +1357,21 @@ namespace DM_Weight.Port
/// 冰箱失能 /// 冰箱失能
/// </summary> /// </summary>
/// <returns></returns> /// <returns></returns>
public async Task FridgeOff() public async Task FridgeOff(int iIndex)
{ {
try try
{ {
fridgeSerial.DiscardInBuffer(); fridgeSerial.DiscardInBuffer();
byte[] buffer = new byte[] { 0x01, 0x06, 0x10, 0xD4, 0x00, 0x00, 0xCD, 0x32 }; 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 }; //byte[] buffer = new byte[] { 0x01, 0x06, 0x10, 0xD4, 0x00, 0x01 };
////获取数组CRC校验码 ////获取数组CRC校验码
//byte[] byteDate = CRC16MODBUS.CrcModBus(buffer); //byte[] byteDate = CRC16MODBUS.CrcModBus(buffer);
@ -1377,12 +1396,21 @@ namespace DM_Weight.Port
/// 冰箱报警使能 /// 冰箱报警使能
/// </summary> /// </summary>
/// <returns></returns> /// <returns></returns>
public async Task FridgeAlarmOn() public async Task FridgeAlarmOn(int iIndex)
{ {
try try
{ {
fridgeSerial.DiscardInBuffer(); fridgeSerial.DiscardInBuffer();
byte[] buffer = new byte[] { 0x01, 0x06, 0x10, 0xD5, 0x00, 0x01, 0x5D, 0x32 }; 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 }; //byte[] buffer = new byte[] { 0x01, 0x06, 0x10, 0xD5, 0x00, 0x01 };
////获取数组CRC校验码 ////获取数组CRC校验码
//byte[] byteDate = CRC16MODBUS.CrcModBus(buffer); //byte[] byteDate = CRC16MODBUS.CrcModBus(buffer);
@ -1409,12 +1437,21 @@ namespace DM_Weight.Port
/// 冰箱报警失能 /// 冰箱报警失能
/// </summary> /// </summary>
/// <returns></returns> /// <returns></returns>
public async Task FridgeAlarmOff() public async Task FridgeAlarmOff(int iIndex)
{ {
try try
{ {
fridgeSerial.DiscardInBuffer(); 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 }; //byte[] buffer = new byte[] { 0x01, 0x06, 0x10, 0xD5, 0x00, 0x00 };
////获取数组CRC校验码 ////获取数组CRC校验码
//byte[] byteDate = CRC16MODBUS.CrcModBus(buffer); //byte[] byteDate = CRC16MODBUS.CrcModBus(buffer);
@ -1439,7 +1476,7 @@ namespace DM_Weight.Port
/// 冰箱温度设定最小 /// 冰箱温度设定最小
/// </summary> /// </summary>
/// <returns></returns> /// <returns></returns>
public async Task FridgeMinSetting(float min) public async Task FridgeMinSetting(float min,int iIndex)
{ {
try try
{ {
@ -1447,7 +1484,16 @@ namespace DM_Weight.Port
int iMix = Convert.ToInt32(min * 10); int iMix = Convert.ToInt32(min * 10);
fridgeSerial.DiscardInBuffer(); fridgeSerial.DiscardInBuffer();
//byte[] bufferMin = new byte[] { 0x01, 0x06, 0x10, 0xC9, 0x00, 0x15, 0x9C, 0xFB }; //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校验码 //获取数组CRC校验码
byte[] byteDate = CRC16MODBUS.CrcModBus(bufferMin); byte[] byteDate = CRC16MODBUS.CrcModBus(bufferMin);
//Array.Reverse(byteDate); //Array.Reverse(byteDate);
@ -1469,14 +1515,23 @@ namespace DM_Weight.Port
/// 冰箱温度设定最大 /// 冰箱温度设定最大
/// </summary> /// </summary>
/// <returns></returns> /// <returns></returns>
public async Task FridgeMaxSetting(float max) public async Task FridgeMaxSetting(float max,int iIndex)
{ {
try try
{ {
int iMax = Convert.ToInt32(max * 10); int iMax = Convert.ToInt32(max * 10);
fridgeSerial.DiscardInBuffer(); fridgeSerial.DiscardInBuffer();
//byte[] bufferMin = new byte[] { 0x01, 0x06, 0x10, 0xC9, 0x00, 0x15, 0x9C, 0xFB }; //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校验码 //获取数组CRC校验码
byte[] byteDate = CRC16MODBUS.CrcModBus(bufferMax); byte[] byteDate = CRC16MODBUS.CrcModBus(bufferMax);
//Array.Reverse(byteDate); //Array.Reverse(byteDate);
@ -1504,8 +1559,16 @@ namespace DM_Weight.Port
try try
{ {
fridgeSerial.DiscardInBuffer(); fridgeSerial.DiscardInBuffer();
byte bAddress;
byte[] buffer = new byte[] { 0x01, 0x03, 0x10, 0x02, 0x00, 0x01, 0x21, 0x0A }; 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 }; //byte[] buffer = new byte[] { 0x01, 0x03, 0x10, 0x02, 0x00, 0x01 };
////获取数组CRC校验码 ////获取数组CRC校验码
@ -1545,7 +1608,7 @@ namespace DM_Weight.Port
/// 设置冰箱温度 /// 设置冰箱温度
/// </summary> /// </summary>
/// <returns></returns> /// <returns></returns>
public async Task<float> SetFridgeTemperature(float temperature) public async Task<float> SetFridgeTemperature(float temperature,int iIndex)
{ {
int tpt = (int)temperature * 10; int tpt = (int)temperature * 10;
byte Temperature = (byte)(tpt & 0xff); byte Temperature = (byte)(tpt & 0xff);
@ -1554,9 +1617,17 @@ namespace DM_Weight.Port
//if (!FridgeOperate) //if (!FridgeOperate)
{ {
fridgeSerial.DiscardInBuffer(); 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, 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校验码 //获取数组CRC校验码
byte[] byteDate = CRC16MODBUS.CrcModBus(buffer); byte[] byteDate = CRC16MODBUS.CrcModBus(buffer);
@ -1584,14 +1655,23 @@ namespace DM_Weight.Port
/// 冰箱延迟报警 /// 冰箱延迟报警
/// </summary> /// </summary>
/// <returns></returns> /// <returns></returns>
public async Task FridgeDelayWarm() public async Task FridgeDelayWarm(int iIndex)
{ {
try try
{ {
//if (!FridgeOperate) //if (!FridgeOperate)
{ {
fridgeSerial.DiscardInBuffer(); 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 }; //byte[] buffer = new byte[] { 0x01, 0x06, 0x10, 0xCD, 0x00, 0x01 };
////获取数组CRC校验码 ////获取数组CRC校验码
//byte[] byteDate = CRC16MODBUS.CrcModBus(buffer); //byte[] byteDate = CRC16MODBUS.CrcModBus(buffer);

View File

@ -139,13 +139,13 @@ namespace DM_Weight.ViewModels
//发送冰箱使能/失能指令 //发送冰箱使能/失能指令
if (_fridgeState) if (_fridgeState)
{ {
await _portUtil.FridgeOff(); await _portUtil.FridgeOff(1);
Thread.Sleep(100); Thread.Sleep(100);
CommonClass.SaveAppSetting("FridgeState", "0"); CommonClass.SaveAppSetting("FridgeState", "0");
} }
else else
{ {
await _portUtil.FridegOpen(); await _portUtil.FridegOpen(1);
Thread.Sleep(100); Thread.Sleep(100);
CommonClass.SaveAppSetting("FridgeState", "1"); CommonClass.SaveAppSetting("FridgeState", "1");
} }
@ -153,13 +153,13 @@ namespace DM_Weight.ViewModels
//冰箱2 发送冰箱使能/失能指令 //冰箱2 发送冰箱使能/失能指令
if (_fridgeState2) if (_fridgeState2)
{ {
await _portUtil.FridgeOff(); await _portUtil.FridgeOff(2);
Thread.Sleep(100); Thread.Sleep(100);
CommonClass.SaveAppSetting("FridgeState2", "0"); CommonClass.SaveAppSetting("FridgeState2", "0");
} }
else else
{ {
await _portUtil.FridegOpen(); await _portUtil.FridegOpen(2);
Thread.Sleep(100); Thread.Sleep(100);
CommonClass.SaveAppSetting("FridgeState2", "1"); CommonClass.SaveAppSetting("FridgeState2", "1");
} }
@ -170,13 +170,13 @@ namespace DM_Weight.ViewModels
//发送警报使能/失能指令 //发送警报使能/失能指令
if (_alarmState) if (_alarmState)
{ {
await _portUtil.FridgeAlarmOff(); await _portUtil.FridgeAlarmOff(1);
Thread.Sleep(100); Thread.Sleep(100);
CommonClass.SaveAppSetting("AlarmState", "0"); CommonClass.SaveAppSetting("AlarmState", "0");
} }
else else
{ {
await _portUtil.FridgeAlarmOn(); await _portUtil.FridgeAlarmOn(1);
Thread.Sleep(100); Thread.Sleep(100);
CommonClass.SaveAppSetting("AlarmState", "1"); CommonClass.SaveAppSetting("AlarmState", "1");
} }
@ -184,13 +184,13 @@ namespace DM_Weight.ViewModels
//冰箱2 发送警报使能/失能指令 //冰箱2 发送警报使能/失能指令
if (_alarmState2) if (_alarmState2)
{ {
await _portUtil.FridgeAlarmOff(); await _portUtil.FridgeAlarmOff(2);
Thread.Sleep(100); Thread.Sleep(100);
CommonClass.SaveAppSetting("AlarmState2", "0"); CommonClass.SaveAppSetting("AlarmState2", "0");
} }
else else
{ {
await _portUtil.FridgeAlarmOn(); await _portUtil.FridgeAlarmOn(2);
Thread.Sleep(100); Thread.Sleep(100);
CommonClass.SaveAppSetting("AlarmState2", "1"); CommonClass.SaveAppSetting("AlarmState2", "1");
} }
@ -216,14 +216,14 @@ namespace DM_Weight.ViewModels
if (Min != Convert.ToSingle(newRange[0])) if (Min != Convert.ToSingle(newRange[0]))
{ {
//设定冰箱温度最小值 //设定冰箱温度最小值
await _portUtil.FridgeMinSetting(Convert.ToSingle(newRange[0])); await _portUtil.FridgeMinSetting(Convert.ToSingle(newRange[0]),1);
Thread.Sleep(100); Thread.Sleep(100);
} }
if (Max != Convert.ToSingle(newRange[1])) if (Max != Convert.ToSingle(newRange[1]))
{ {
Thread.Sleep(100); Thread.Sleep(100);
//设定冰箱温度最大值 //设定冰箱温度最大值
await _portUtil.FridgeMaxSetting(Convert.ToSingle(newRange[1])); await _portUtil.FridgeMaxSetting(Convert.ToSingle(newRange[1]), 1);
Thread.Sleep(100); Thread.Sleep(100);
} }
} }
@ -242,14 +242,14 @@ namespace DM_Weight.ViewModels
if (Min != Convert.ToSingle(newRange2[0])) if (Min != Convert.ToSingle(newRange2[0]))
{ {
//设定冰箱温度最小值 //设定冰箱温度最小值
await _portUtil.FridgeMinSetting(Convert.ToSingle(newRange2[0])); await _portUtil.FridgeMinSetting(Convert.ToSingle(newRange2[0]), 2);
Thread.Sleep(100); Thread.Sleep(100);
} }
if (Max != Convert.ToSingle(newRange2[1])) if (Max != Convert.ToSingle(newRange2[1]))
{ {
Thread.Sleep(100); Thread.Sleep(100);
//设定冰箱温度最大值 //设定冰箱温度最大值
await _portUtil.FridgeMaxSetting(Convert.ToSingle(newRange2[1])); await _portUtil.FridgeMaxSetting(Convert.ToSingle(newRange2[1]), 2);
Thread.Sleep(100); Thread.Sleep(100);
} }
} }