Commit b5aebba5 authored by leon.huang's avatar leon.huang

temperte mergr

parent c089422c
...@@ -9,14 +9,12 @@ using MQTTnet.Client; ...@@ -9,14 +9,12 @@ using MQTTnet.Client;
using Newtonsoft.Json; using Newtonsoft.Json;
namespace ModbusDemo.Common namespace ModbusDemo.Common
{ {
public class ModualAlarm public static class ModualAlarm
{ {
public const ushort usChannelNumber = 8; public const ushort usChannelNumber = 8;
private const string sAlarmTopic = "Witium/WTDS78X/20193261/Alarm"; private const string sAlarmTopic = "Witium/WTDS78X/20193261/Alarm";
public Hashtable hMqtttAlarmMap = new Hashtable(); public static string sAlarmJson;
public bool bErrorHasSend = false; public static string sAlarmJsonPackage;
private string sAlarmJson;
private string sAlarmJsonPackage;
//private IMqttClient mqttClient = null; //private IMqttClient mqttClient = null;
public enum eAlarmCode : ushort public enum eAlarmCode : ushort
{ {
...@@ -26,9 +24,10 @@ namespace ModbusDemo.Common ...@@ -26,9 +24,10 @@ namespace ModbusDemo.Common
ChannelDataRespError = 4, ChannelDataRespError = 4,
ChannelDataChangeError = 8 ChannelDataChangeError = 8
} }
public void vSetAlarmList(ushort usAddress, ushort[] usChannel, ushort[] usChannelAlarmcode,bool bStringIncrease) public static void vSetAlarmList(ushort usAddress, ushort[] usChannel, ushort[] usChannelAlarmcode,bool bStringIncrease)
{ {
ushort i = 0; ushort i = 0;
Hashtable hMqtttAlarmMap = new Hashtable();
hMqtttAlarmMap.Add("addr", usAddress.ToString()); hMqtttAlarmMap.Add("addr", usAddress.ToString());
string sAlarm = "alm"; string sAlarm = "alm";
foreach (ushort usdata in usChannelAlarmcode) foreach (ushort usdata in usChannelAlarmcode)
...@@ -43,9 +42,8 @@ namespace ModbusDemo.Common ...@@ -43,9 +42,8 @@ namespace ModbusDemo.Common
sAlarmJson += ","; sAlarmJson += ",";
} }
} }
public async Task vPublishAlarmPackageJson(IMqttClient mqttClient) public static async Task vPublishAlarmPackageJson(IMqttClient mqttClient)
{ {
sAlarmJson = "[" + sAlarmJson + "]";
var message = new MqttApplicationMessageBuilder() var message = new MqttApplicationMessageBuilder()
.WithTopic(sAlarmTopic) .WithTopic(sAlarmTopic)
.WithPayload(sAlarmJson) .WithPayload(sAlarmJson)
......
...@@ -13,7 +13,7 @@ namespace ModbusDemo.Modular ...@@ -13,7 +13,7 @@ namespace ModbusDemo.Modular
{ {
class ModualPoll class ModualPoll
{ {
public const byte byX14pNumber = 4; public const byte byX14pNumber = 2;
private const byte byX14pReadDataStartAddress = 0; private const byte byX14pReadDataStartAddress = 0;
public const byte byX14pReadDataNumber = 4; public const byte byX14pReadDataNumber = 4;
private const byte byX14pReadTypeStartAddress = 10; private const byte byX14pReadTypeStartAddress = 10;
...@@ -22,11 +22,14 @@ namespace ModbusDemo.Modular ...@@ -22,11 +22,14 @@ namespace ModbusDemo.Modular
public const double dX14pMinCovertData = 0; public const double dX14pMinCovertData = 0;
public const double dx14pMaxConverData = 60; public const double dx14pMaxConverData = 60;
public const ushort us14pMaxJumTemper = 10; public const ushort us14pMaxJumTemper = 10;
public static byte[] byX14pIdlist = { 1,17, 28, 29 }; public static byte[] byX14pIdlist = { 1,17};
public static modual.pcx14P cx14P = new modual.pcx14P(byX14pIdlist); private static modual.eX14pSensorChannelType[,] sX14pChannelType = new modual.eX14pSensorChannelType[byX14pNumber, byX14pReadTypeNumber] { { modual.eX14pSensorChannelType.Normal, modual.eX14pSensorChannelType.Null, modual.eX14pSensorChannelType.Null, modual.eX14pSensorChannelType.Null },
{ modual.eX14pSensorChannelType.Normal, modual.eX14pSensorChannelType.Null, modual.eX14pSensorChannelType.Null, modual.eX14pSensorChannelType.Null }};
public static modual.pcx14P cx14P = new modual.pcx14P(byX14pIdlist, sX14pChannelType);
public static _414P c14formulasormual = new _414P(); public static _414P c14formulasormual = new _414P();
public const byte byX18xNumber = 8; public const byte byX18xNumber = 6;
private const byte byX18xReadDataStartAddress = 0; private const byte byX18xReadDataStartAddress = 0;
public const byte byX18xReadDataNumber = 8; public const byte byX18xReadDataNumber = 8;
private const byte byX18xReadTypeStartAddress = 10; private const byte byX18xReadTypeStartAddress = 10;
...@@ -34,21 +37,21 @@ namespace ModbusDemo.Modular ...@@ -34,21 +37,21 @@ namespace ModbusDemo.Modular
public const double dX18xMinConvertData = 0; public const double dX18xMinConvertData = 0;
private const ushort dX18xMaxJumpData = 2; private const ushort dX18xMaxJumpData = 2;
public static byte[] byX18xIdlist = {3,6,12,13,21,25,45,53}; public static byte[] byX18xIdlist = {3,53,6,12,21,25};
private static modual.eX18xSensorChannelType[,] sX18xChannelType = new modual.eX18xSensorChannelType[byX18xNumber,byX18xReadDataNumber]{{modual.eX18xSensorChannelType.Weiertai,modual.eX18xSensorChannelType.Null,modual.eX18xSensorChannelType.Mike_7,modual.eX18xSensorChannelType.Null,modual.eX18xSensorChannelType.Null,modual.eX18xSensorChannelType.Null,modual.eX18xSensorChannelType.Null,modual.eX18xSensorChannelType.Null},//东中转池 ID 3 private static modual.eX18xSensorChannelType[,] sX18xChannelType = new modual.eX18xSensorChannelType[byX18xNumber, byX18xReadDataNumber]{{modual.eX18xSensorChannelType.Weiertai,modual.eX18xSensorChannelType.Null,modual.eX18xSensorChannelType.Mike_7,modual.eX18xSensorChannelType.Null,modual.eX18xSensorChannelType.Null,modual.eX18xSensorChannelType.Null,modual.eX18xSensorChannelType.Null,modual.eX18xSensorChannelType.Null}, //东中转池 ID 3
{modual.eX18xSensorChannelType.NormalCurrent,modual.eX18xSensorChannelType.Null,modual.eX18xSensorChannelType.Null,modual.eX18xSensorChannelType.Null,modual.eX18xSensorChannelType.Null,modual.eX18xSensorChannelType.Null,modual.eX18xSensorChannelType.Null,modual.eX18xSensorChannelType.Null}, //东中转池 ID 53
{modual.eX18xSensorChannelType.Mike_7,modual.eX18xSensorChannelType.Weiertai,modual.eX18xSensorChannelType.Null,modual.eX18xSensorChannelType.Null,modual.eX18xSensorChannelType.Null,modual.eX18xSensorChannelType.Null,modual.eX18xSensorChannelType.Null,modual.eX18xSensorChannelType.Null}, //西西中转池 ID 6 {modual.eX18xSensorChannelType.Mike_7,modual.eX18xSensorChannelType.Weiertai,modual.eX18xSensorChannelType.Null,modual.eX18xSensorChannelType.Null,modual.eX18xSensorChannelType.Null,modual.eX18xSensorChannelType.Null,modual.eX18xSensorChannelType.Null,modual.eX18xSensorChannelType.Null}, //西西中转池 ID 6
{modual.eX18xSensorChannelType.Mike_6,modual.eX18xSensorChannelType.Null,modual.eX18xSensorChannelType.Null,modual.eX18xSensorChannelType.Null,modual.eX18xSensorChannelType.Null,modual.eX18xSensorChannelType.Null,modual.eX18xSensorChannelType.Null,modual.eX18xSensorChannelType.Null}, //八角池 ID 21
{modual.eX18xSensorChannelType.Mike_5,modual.eX18xSensorChannelType.Null,modual.eX18xSensorChannelType.Null,modual.eX18xSensorChannelType.Null,modual.eX18xSensorChannelType.Null,modual.eX18xSensorChannelType.Null,modual.eX18xSensorChannelType.Null,modual.eX18xSensorChannelType.Null}, //沉砂池 ID 12 {modual.eX18xSensorChannelType.Mike_5,modual.eX18xSensorChannelType.Null,modual.eX18xSensorChannelType.Null,modual.eX18xSensorChannelType.Null,modual.eX18xSensorChannelType.Null,modual.eX18xSensorChannelType.Null,modual.eX18xSensorChannelType.Null,modual.eX18xSensorChannelType.Null}, //沉砂池 ID 12
{modual.eX18xSensorChannelType.Mike_7,modual.eX18xSensorChannelType.Weiertai,modual.eX18xSensorChannelType.Null,modual.eX18xSensorChannelType.Null,modual.eX18xSensorChannelType.Null,modual.eX18xSensorChannelType.Null,modual.eX18xSensorChannelType.Null,modual.eX18xSensorChannelType.Null}, {modual.eX18xSensorChannelType.Mike_6,modual.eX18xSensorChannelType.Null,modual.eX18xSensorChannelType.Null,modual.eX18xSensorChannelType.Null,modual.eX18xSensorChannelType.Null,modual.eX18xSensorChannelType.Null,modual.eX18xSensorChannelType.Null,modual.eX18xSensorChannelType.Null}}; //匀浆池 ID 25
{modual.eX18xSensorChannelType.Null,modual.eX18xSensorChannelType.Null,modual.eX18xSensorChannelType.Null,modual.eX18xSensorChannelType.Null,modual.eX18xSensorChannelType.Null,modual.eX18xSensorChannelType.Null,modual.eX18xSensorChannelType.Null,modual.eX18xSensorChannelType.Null}, //八角池 ID 21
{modual.eX18xSensorChannelType.Mike_6,modual.eX18xSensorChannelType.Null,modual.eX18xSensorChannelType.Null,modual.eX18xSensorChannelType.Null,modual.eX18xSensorChannelType.Null,modual.eX18xSensorChannelType.Null,modual.eX18xSensorChannelType.Null,modual.eX18xSensorChannelType.Null}, //匀浆池 ID 25
{modual.eX18xSensorChannelType.Mike_5,modual.eX18xSensorChannelType.Null,modual.eX18xSensorChannelType.Null,modual.eX18xSensorChannelType.Null,modual.eX18xSensorChannelType.Null,modual.eX18xSensorChannelType.Null,modual.eX18xSensorChannelType.Null,modual.eX18xSensorChannelType.Null}, //出料池 ID 45
{modual.eX18xSensorChannelType.Null,modual.eX18xSensorChannelType.Null,modual.eX18xSensorChannelType.Null,modual.eX18xSensorChannelType.Null,modual.eX18xSensorChannelType.Null,modual.eX18xSensorChannelType.Null,modual.eX18xSensorChannelType.Null,modual.eX18xSensorChannelType.Null}};
public static modual.pcx18X cx18x = new modual.pcx18X(byX18xIdlist, sX18xChannelType); public static modual.pcx18X cx18x = new modual.pcx18X(byX18xIdlist, sX18xChannelType);
private static _418X c18xformulasormual = new _418X(); private static _418X c18xformulasormual = new _418X();
public const byte byX78cNumber = 6; public const byte byX78cNumber = 0;
private const byte byX78cInputRegStartAddress = 0; private const byte byX78cInputRegStartAddress = 0;
public const byte byX78cInputRegNumber = 8; public const byte byX78cInputRegNumber = 8;
private const byte byX78cOutputRegStartAddress = 16; private const byte byX78cOutputRegStartAddress = 16;
...@@ -60,10 +63,10 @@ namespace ModbusDemo.Modular ...@@ -60,10 +63,10 @@ namespace ModbusDemo.Modular
public const byte byX66cNumber = 32; public const byte byX66cNumber = 32;
private const byte byX66cRelayRegStartAddress = 16; private const byte byX66cRelayRegStartAddress = 16;
public const byte byX66cRelayRegNumber = 6; public const byte byX66cRelayRegNumber = 6;
public static byte[] byX66cIdlist = {9,10,14,15,16,19,22,23,24,26,30,31,32,35,36,37,38,39,40,41,42,43,44,46,47,48,49,50,51,52,54,57}; public static byte[] byX66cIdlist = {4,5,7,8,9,10,14,15,19,22,23,24,26,30,32,36,37,38,40,41,42,43,44,46,47,48,49,50,51,52,54,57};
public static modual.pcx66C cx66c = new modual.pcx66C(byX66cIdlist); public static modual.pcx66C cx66c = new modual.pcx66C(byX66cIdlist);
public static ModualAlarm cModualAlarm = new ModualAlarm(); //public static ModualAlarm cModualAlarm = new ModualAlarm();
public static void vAllNodePoll() public static void vAllNodePoll()
{ {
...@@ -88,14 +91,25 @@ namespace ModbusDemo.Modular ...@@ -88,14 +91,25 @@ namespace ModbusDemo.Modular
cx14P.sX14PAlarmStruct[i].usNowAlarmCode[j] &= (ushort)~ModualAlarm.eAlarmCode.ChannelCommunError; cx14P.sX14PAlarmStruct[i].usNowAlarmCode[j] &= (ushort)~ModualAlarm.eAlarmCode.ChannelCommunError;
} }
} }
for (byte j = 0; j < byX14pReadTypeNumber; j++) for (byte j = 0; j < byX14pReadTypeNumber; j++)
{ {
cx14P.sX14pDataStruct[i].dNowConvertData[j] = double.Parse(sTempString[i][j]); cx14P.sX14pDataStruct[i].dNowConvertData[j] = double.Parse(sTempString[i][j]);
//if (cx14P.sX14pDataStruct[i].dX14pNowConvertData[j] <= dX14pMinCovertData || cx14P.sX14pDataStruct[i].dX14pNowConvertData[j] >= dx14pMaxConverData ) if (ModbusErrorCode == ModbusComm.eModbusErrorCode.MB_EMASTERNOERR)
//{ {
// cx14P.sX14PAlarmStruct[i].eNowAlarmCode[j] |= ModualAlarm.eAlarmCode.ChannelCollectDataError; switch (cx14P.eChannelType[i, j])
//} {
case modual.eX14pSensorChannelType.Normal:
cx14P.sX14pDataStruct[i].dNowConvertData[j] = cx14P.sX14pDataStruct[i].dNowConvertData[j];
break;
case modual.eX14pSensorChannelType.Null:
cx14P.sX14pDataStruct[i].dNowConvertData[j] = 0;
break;
}
}
else
{
cx14P.sX14pDataStruct[i].dNowConvertData[j] = 0;
}
if (cx14P.sX14PAlarmStruct[i].bDataNotFirstIncreaseOrDecrease == true) if (cx14P.sX14PAlarmStruct[i].bDataNotFirstIncreaseOrDecrease == true)
{ {
if (cx14P.sX14pDataStruct[i].dNowConvertData[j] - cx14P.sX14pDataStruct[i].dBeforeConvertData[j] >= us14pMaxJumTemper && cx14P.sX14pDataStruct[i].dBeforeConvertData[j] - cx14P.sX14pDataStruct[i].dNowConvertData[j] >= us14pMaxJumTemper) if (cx14P.sX14pDataStruct[i].dNowConvertData[j] - cx14P.sX14pDataStruct[i].dBeforeConvertData[j] >= us14pMaxJumTemper && cx14P.sX14pDataStruct[i].dBeforeConvertData[j] - cx14P.sX14pDataStruct[i].dNowConvertData[j] >= us14pMaxJumTemper)
...@@ -104,7 +118,7 @@ namespace ModbusDemo.Modular ...@@ -104,7 +118,7 @@ namespace ModbusDemo.Modular
} }
else else
{ {
cx14P.sX14PAlarmStruct[i].usNowAlarmCode[j] &= (ushort)~ModualAlarm.eAlarmCode.ChannelDataChangeError; cx14P.sX14PAlarmStruct[i].usNowAlarmCode[j] |= (ushort)~ModualAlarm.eAlarmCode.ChannelDataChangeError;
} }
} }
cx14P.sX14pDataStruct[i].dBeforeConvertData[j] = cx14P.sX14pDataStruct[i].dNowConvertData[j]; cx14P.sX14pDataStruct[i].dBeforeConvertData[j] = cx14P.sX14pDataStruct[i].dNowConvertData[j];
...@@ -130,10 +144,9 @@ namespace ModbusDemo.Modular ...@@ -130,10 +144,9 @@ namespace ModbusDemo.Modular
{ {
for (sbyte j = 0; j < byX18xReadTypeNumber; j++) for (sbyte j = 0; j < byX18xReadTypeNumber; j++)
{ {
cx18x.sX18xAlarmstruct[i].usNowAlarmCode[j] |= (ushort)~ModualAlarm.eAlarmCode.ChannelCommunError; cx18x.sX18xAlarmstruct[i].usNowAlarmCode[j] &= (ushort)~ModualAlarm.eAlarmCode.ChannelCommunError;
} }
} }
for (byte j = 0; j < byX18xReadTypeNumber ; j++) for (byte j = 0; j < byX18xReadTypeNumber ; j++)
{ {
if (ModbusErrorCode == ModbusComm.eModbusErrorCode.MB_EMASTERNOERR) if (ModbusErrorCode == ModbusComm.eModbusErrorCode.MB_EMASTERNOERR)
...@@ -152,6 +165,9 @@ namespace ModbusDemo.Modular ...@@ -152,6 +165,9 @@ namespace ModbusDemo.Modular
case modual.eX18xSensorChannelType.Mike_7: case modual.eX18xSensorChannelType.Mike_7:
cx18x.sX18xDataStruct[i].dNowConvertData[j] = 7 - ((double.Parse(sTempString[i][j]) - 4) / 16 * 7); cx18x.sX18xDataStruct[i].dNowConvertData[j] = 7 - ((double.Parse(sTempString[i][j]) - 4) / 16 * 7);
break; break;
case modual.eX18xSensorChannelType.NormalCurrent:
cx18x.sX18xDataStruct[i].dNowConvertData[j] = cx18x.sX18xDataStruct[i].dNowConvertData[j];
break;
case modual.eX18xSensorChannelType.Null: case modual.eX18xSensorChannelType.Null:
cx18x.sX18xDataStruct[i].dNowConvertData[j] = 0; cx18x.sX18xDataStruct[i].dNowConvertData[j] = 0;
break; break;
...@@ -266,80 +282,105 @@ namespace ModbusDemo.Modular ...@@ -266,80 +282,105 @@ namespace ModbusDemo.Modular
public static async void vCheckAlarm_And_Send(IMqttClient mqttClient) public static async void vCheckAlarm_And_Send(IMqttClient mqttClient)
{ {
bool bOccurErrorChange = false; bool bOccurErrorChange = false;
ModualAlarm.sAlarmJson = "[";
for (byte i = 0; i < byX14pNumber; i++) for (byte i = 0; i < byX14pNumber; i++)
{ {
ushort[] usChannelErrorlist = { }; bool bX14pError = false;
ushort[] usChannelErrorCodeList = { }; List<ushort> usChannelErrorlist = new List<ushort>();
byte k = 0; List<ushort> usChannelErrorCodeList = new List<ushort>();
for (byte j = 0; j < byX14pReadDataNumber; j++) for (byte j = 0; j < byX14pReadDataNumber; j++)
{ {
if (cx14P.sX14PAlarmStruct[i].usNowAlarmCode[j] != cx14P.sX14PAlarmStruct[i].usBeforeAlarmCode[j]) if (cx14P.sX14PAlarmStruct[i].usNowAlarmCode[j] != cx14P.sX14PAlarmStruct[i].usBeforeAlarmCode[j])
{ {
bOccurErrorChange = true; bOccurErrorChange = true;
usChannelErrorlist[k++] = j; bX14pError = true;
usChannelErrorCodeList[k++] = (ushort)cx14P.sX14PAlarmStruct[i].usNowAlarmCode[j]; usChannelErrorlist.Add(j);
usChannelErrorCodeList.Add((ushort)cx14P.sX14PAlarmStruct[i].usNowAlarmCode[j]);
} }
cx14P.sX14PAlarmStruct[i].usBeforeAlarmCode[j] = cx14P.sX14PAlarmStruct[i].usNowAlarmCode[j]; cx14P.sX14PAlarmStruct[i].usBeforeAlarmCode[j] = cx14P.sX14PAlarmStruct[i].usNowAlarmCode[j];
} }
cModualAlarm.vSetAlarmList(i, usChannelErrorlist, usChannelErrorCodeList,true); if (bX14pError == true)
{
ushort[] usChannelList = usChannelErrorlist.ToArray();
ushort[] usCodeList = usChannelErrorCodeList.ToArray();
ModualAlarm.vSetAlarmList(i, usChannelList, usCodeList, true);
}
} }
for (byte i = 0; i < byX18xNumber; i++) for (byte i = 0; i < byX18xNumber; i++)
{ {
ushort[] usChannelErrorlist = { }; bool bX18xError = false;
ushort[] usChannelErrorCodeList = { }; List<ushort> usChannelErrorlist = new List<ushort>();
byte k = 0; List<ushort> usChannelErrorCodeList = new List<ushort>();
for (byte j = 0; j < byX18xReadTypeNumber; j++) for (byte j = 0; j < byX18xReadTypeNumber; j++)
{ {
if (cx18x.sX18xAlarmstruct[i].usNowAlarmCode[j] != cx18x.sX18xAlarmstruct[i].usBeforeAlarmCode[j]) if (cx18x.sX18xAlarmstruct[i].usNowAlarmCode[j] != cx18x.sX18xAlarmstruct[i].usBeforeAlarmCode[j])
{ {
bX18xError = true;
bOccurErrorChange = true; bOccurErrorChange = true;
usChannelErrorlist[k++] = j; usChannelErrorlist.Add (j);
usChannelErrorCodeList[k++] = (ushort)cx18x.sX18xAlarmstruct[i].usNowAlarmCode[j]; usChannelErrorlist.Add((ushort)cx18x.sX18xAlarmstruct[i].usNowAlarmCode[j]);
} }
cx18x.sX18xAlarmstruct[i].usBeforeAlarmCode[j] = cx18x.sX18xAlarmstruct[i].usNowAlarmCode[j]; cx18x.sX18xAlarmstruct[i].usBeforeAlarmCode[j] = cx18x.sX18xAlarmstruct[i].usNowAlarmCode[j];
} }
cModualAlarm.vSetAlarmList(i, usChannelErrorlist, usChannelErrorCodeList,true); if (bX18xError == true)
{
ushort[] usChannelList = usChannelErrorlist.ToArray();
ushort[] usCodeList = usChannelErrorCodeList.ToArray();
ModualAlarm.vSetAlarmList(i, usChannelList, usCodeList, true);
}
} }
for (byte i = 0; i < byX78cNumber; i++) for (byte i = 0; i < byX78cNumber; i++)
{ {
ushort[] usChannelErrorlist = { }; bool bX78CError = false;
ushort[] usChannelErrorCodeList = { }; List<ushort> usChannelErrorlist = new List<ushort>();
byte k = 0; List<ushort> usChannelErrorCodeList = new List<ushort>();
for (byte j = 0; j < byX78cOutputRegNumber + byX78cInputRegNumber; j++) for (byte j = 0; j < byX78cOutputRegNumber + byX78cInputRegNumber; j++)
{ {
if (cx78c.sX78cAlarmStruct[i].usNowAlarmCode[j] != cx78c.sX78cAlarmStruct[i].usBeforeAlarmCode[j]) if (cx78c.sX78cAlarmStruct[i].usNowAlarmCode[j] != cx78c.sX78cAlarmStruct[i].usBeforeAlarmCode[j])
{ {
bOccurErrorChange = true; bOccurErrorChange = true;
usChannelErrorlist[k++] = j; bX78CError = true;
usChannelErrorCodeList[k++] = (ushort)cx78c.sX78cAlarmStruct[i].usNowAlarmCode[j]; usChannelErrorlist.Add(j);
usChannelErrorlist.Add((ushort)cx78c.sX78cAlarmStruct[i].usNowAlarmCode[j]);
} }
cx78c.sX78cAlarmStruct[i].usBeforeAlarmCode[j] = cx78c.sX78cAlarmStruct[i].usNowAlarmCode[j]; cx78c.sX78cAlarmStruct[i].usBeforeAlarmCode[j] = cx78c.sX78cAlarmStruct[i].usNowAlarmCode[j];
} }
cModualAlarm.vSetAlarmList(i, usChannelErrorlist, usChannelErrorCodeList, true); if (bX78CError == true)
{
ushort[] usChannelList = usChannelErrorlist.ToArray();
ushort[] usCodeList = usChannelErrorCodeList.ToArray();
ModualAlarm.vSetAlarmList(i, usChannelList, usCodeList, true);
}
} }
for (byte i = 0; i < byX66cNumber; i++) for (byte i = 0; i < byX66cNumber; i++)
{ {
ushort[] usChannelErrorlist = { }; bool bX66cError = false;
ushort[] usChannelErrorCodeList = { }; List<ushort> usChannelErrorlist = new List<ushort>();
byte k = 0; List<ushort> usChannelErrorCodeList = new List<ushort>();
for (byte j = 0; j < byX66cRelayRegNumber; j++) for (byte j = 0; j < byX66cRelayRegNumber; j++)
{ {
if (cx66c.sX66cAlarmStruct[i].usNowAlarmCode[j] != cx66c.sX66cAlarmStruct[i].usBeforeAlarmCode[j]) if (cx66c.sX66cAlarmStruct[i].usNowAlarmCode[j] != cx66c.sX66cAlarmStruct[i].usBeforeAlarmCode[j])
{ {
bOccurErrorChange = true; bOccurErrorChange = true;
usChannelErrorlist[k++] = j; bX66cError = true;
usChannelErrorCodeList[k++] = (ushort)cx66c.sX66cAlarmStruct[i].usNowAlarmCode[j]; usChannelErrorlist.Add(j);
usChannelErrorlist.Add((ushort)cx66c.sX66cAlarmStruct[i].usNowAlarmCode[j]);
} }
cx66c.sX66cAlarmStruct[i].usBeforeAlarmCode[j] = cx66c.sX66cAlarmStruct[i].usNowAlarmCode[j]; cx66c.sX66cAlarmStruct[i].usBeforeAlarmCode[j] = cx66c.sX66cAlarmStruct[i].usNowAlarmCode[j];
} }
cModualAlarm.vSetAlarmList(i, usChannelErrorlist, usChannelErrorCodeList,i == byX66cNumber ? true:false); if (bX66cError == true)
{
ushort[] usChannelList = usChannelErrorlist.ToArray();
ushort[] usCodeList = usChannelErrorCodeList.ToArray();
ModualAlarm.vSetAlarmList(i, usChannelList, usCodeList, i == byX66cNumber - 1 ? true : false);
}
} }
if (bOccurErrorChange == true) if (bOccurErrorChange == true)
{ {
await cModualAlarm.vPublishAlarmPackageJson(mqttClient); ModualAlarm.sAlarmJson += "]";
await ModualAlarm.vPublishAlarmPackageJson(mqttClient);
} }
} }
} }
......
...@@ -16,21 +16,27 @@ namespace ModbusDemo.Modular ...@@ -16,21 +16,27 @@ namespace ModbusDemo.Modular
public double[] dNowConvertData; public double[] dNowConvertData;
public double[] dBeforeConvertData; public double[] dBeforeConvertData;
} }
public enum eX14pSensorChannelType : byte
{
Normal = 0,
Null,
}
public struct psxModualAlarm public struct psxModualAlarm
{ {
public bool bDataNotFirstIncreaseOrDecrease; public bool bDataNotFirstIncreaseOrDecrease;
public ushort[] usNowAlarmCode; public ushort[] usNowAlarmCode;
public ushort[] usBeforeAlarmCode; public ushort[] usBeforeAlarmCode;
} }
public class pcx14P public class pcx14P
{ {
public byte[] byModbusID; public byte[] byModbusID;
public psx14pData[] sX14pDataStruct = new psx14pData[ModualPoll.byX14pNumber]; public psx14pData[] sX14pDataStruct = new psx14pData[ModualPoll.byX14pNumber];
public psxModualAlarm[] sX14PAlarmStruct = new psxModualAlarm[ModualPoll.byX14pNumber]; public psxModualAlarm[] sX14PAlarmStruct = new psxModualAlarm[ModualPoll.byX14pNumber];
public pcx14P(byte[] InitIDlist) public eX14pSensorChannelType[,] eChannelType;
public pcx14P(byte[] InitIDlist, eX14pSensorChannelType[,] ChannelType)
{ {
this.byModbusID = InitIDlist; this.byModbusID = InitIDlist;
this.eChannelType = ChannelType;
for (byte i = 0; i < ModualPoll.byX14pNumber; i++) for (byte i = 0; i < ModualPoll.byX14pNumber; i++)
{ {
this.sX14pDataStruct[i].dBeforeConvertData = new double[ModualPoll.byX14pReadDataNumber]; this.sX14pDataStruct[i].dBeforeConvertData = new double[ModualPoll.byX14pReadDataNumber];
...@@ -49,7 +55,7 @@ namespace ModbusDemo.Modular ...@@ -49,7 +55,7 @@ namespace ModbusDemo.Modular
Mike_5, Mike_5,
Mike_6, Mike_6,
Mike_7, Mike_7,
Level, NormalCurrent,
} }
public struct psX18xData public struct psX18xData
......
...@@ -21,6 +21,8 @@ using System.Timers; ...@@ -21,6 +21,8 @@ using System.Timers;
using ModbusDemo.application; using ModbusDemo.application;
using System.Collections; using System.Collections;
using ModbusDemo.Modular; using ModbusDemo.Modular;
using ModbusDemo.MessageFormat;
namespace ModbusDemo namespace ModbusDemo
{ {
public partial class Form1 : Form public partial class Form1 : Form
...@@ -583,7 +585,10 @@ namespace ModbusDemo ...@@ -583,7 +585,10 @@ namespace ModbusDemo
{ {
await Task.Run(() => await Task.Run(() =>
{ {
Modbus_polling(); //Modbus_polling();
ModualPoll.vAllNodePoll();
mqttData = ModualPoll.stAll_Poll_Package();
ModualPoll.vCheckAlarm_And_Send(mqttClient);
}); });
} }
...@@ -858,99 +863,41 @@ namespace ModbusDemo ...@@ -858,99 +863,41 @@ namespace ModbusDemo
} }
private async void Modbus_polling() private async void Modbus_polling()
{ {
float EastTemperature = 0; //float EastTemperature = 0;
float Easternwaterlevel = 0; //float Easternwaterlevel = 0;
float WestWaterLevel = 0; //float WestWaterLevel = 0;
int sign = 0; //int sign = 0;
try //try
{
ushort[] temperature = { };
ushort[] type = { };
string[] vs = { };
string[] s = { };
string[] s6 = { };
ushort[] register = { };
ushort[] Inputtype = { };
ushort[] registerN = { };
ushort[] InputtypeN = { };
bool[] EIO = { };
bool[] SIO = { };
bool[] WIO = { };
int[] EOnOff = { 0 };
int[] SOnOff = { 0 };
int[] WOnOff = { 0 };
Modbus_ReadHoldingRegistersTask(out temperature, 27, 0, 4, out int signT);
Modbus_ReadHoldingRegistersTask(out type, 27, 10, 4, out sign);
UInt64 time_1 = GetTimeStamp();
Modbus_ReadHoldingRegistersTask(out register, 21, 0, 8, out int signr);
Modbus_ReadHoldingRegistersTask(out Inputtype, 21, 10, 8, out int signI);
UInt64 time_2 = GetTimeStamp();
Modbus_ReadHoldingRegistersTask(out registerN, 53, 0, 8, out int signre);
Modbus_ReadHoldingRegistersTask(out InputtypeN, 53, 10, 8, out int signIn);
UInt64 time_3 = GetTimeStamp();
Modbus_ReadCoilsTask(out EIO, 40, 16, 6, out int signE);
Modbus_ReadCoilsTask(out SIO, 19, 16, 6, out int signS);
Modbus_ReadCoilsTask(out WIO, 41, 16, 6, out int signW);
if (sign == -1)
{
}
//else
//{ //{
vs = rtd.RtdValue(temperature, type); // ushort[] temperature = { };
EastTemperature = float.Parse(vs[0]); // ushort[] type = { };
s = Analog.Value(register, Inputtype); // string[] vs = { };
//(实时电流值 - 设定电流最小值) /(20Ma - 设定电流最小值) *设定测量最大值 // string[] s = { };
//(实时电流值 - 4ma) /(20ma - 4ma) *设定测量最大值(也就是设定的满量程) // string[] s6 = { };
// ushort[] register = { };
Easternwaterlevel = (float.Parse(s[0]) - 4) / 16 * 6; // ushort[] Inputtype = { };
s6 = Analog.Value(registerN, InputtypeN); // ushort[] registerN = { };
WestWaterLevel = (float.Parse(s6[0]) - 4) / 16 * 6; // ushort[] InputtypeN = { };
label3.Text = EastTemperature.ToString(); // bool[] EIO = { };
label4.Text = Easternwaterlevel.ToString(); // bool[] SIO = { };
EOnOff = state.IO(EIO);////东中转池 // bool[] WIO = { };
SOnOff = state.IO(SIO);////西中转池 // int[] EOnOff = { 0 };
WOnOff = state.IO(WIO); ////东南北水 // int[] SOnOff = { 0 };
//} // int[] WOnOff = { 0 };
// Modbus_ReadHoldingRegistersTask(out temperature, 27, 0, 4, out int signT);
WTDR14P x = new WTDR14P("27", EastTemperature, 0, 0, 0, time_1); // Modbus_ReadHoldingRegistersTask(out type, 27, 10, 4, out sign);
WTDR18X p = new WTDR18X("21", Easternwaterlevel, 0, 0, 0, 0, 0, 0, 0, time_2);
WTDR18X q = new WTDR18X("53", WestWaterLevel, 0, 0, 0, 0, 0, 0, 0, time_3);
//东搅拌
WTDR66C EastStir = new WTDR66C("40", EOnOff[0], EOnOff[1], EOnOff[2], EOnOff[3], EOnOff[4], EOnOff[5], GetTimeStamp());
//东南北水
WTDR66C WestStir = new WTDR66C("41", WOnOff[0], WOnOff[1], WOnOff[2], WOnOff[3], WOnOff[4], WOnOff[5], GetTimeStamp());
//西搅拌
WTDR66C SouthWater = new WTDR66C("19", SOnOff[0], SOnOff[1], SOnOff[2], SOnOff[3], SOnOff[4], SOnOff[5], GetTimeStamp());
mqttData = "[" +
JsonConvert.SerializeObject(x) + "," +
JsonConvert.SerializeObject(p) + "," +
JsonConvert.SerializeObject(q) + "," +
JsonConvert.SerializeObject(EastStir) + "," +
JsonConvert.SerializeObject(WestStir) + "," +
JsonConvert.SerializeObject(SouthWater)
+ "]";
}
// Modbus_ReadHoldingRegistersTask(out temperature, 1, 0, 4, out int signT);
// Modbus_ReadHoldingRegistersTask(out type, 1, 10, 4, out sign);
// UInt64 time_1 = GetTimeStamp(); // UInt64 time_1 = GetTimeStamp();
// Modbus_ReadHoldingRegistersTask(out register, 3, 0, 8, out int signr); // Modbus_ReadHoldingRegistersTask(out register, 21, 0, 8, out int signr);
// Modbus_ReadHoldingRegistersTask(out Inputtype, 3, 10, 8, out int signI); // Modbus_ReadHoldingRegistersTask(out Inputtype, 21, 10, 8, out int signI);
// UInt64 time_2 = GetTimeStamp(); // UInt64 time_2 = GetTimeStamp();
// Modbus_ReadHoldingRegistersTask(out registerN, 6, 0, 8, out int signre); // Modbus_ReadHoldingRegistersTask(out registerN, 53, 0, 8, out int signre);
// Modbus_ReadHoldingRegistersTask(out InputtypeN, 6, 10, 8, out int signIn); // Modbus_ReadHoldingRegistersTask(out InputtypeN, 53, 10, 8, out int signIn);
// UInt64 time_3 = GetTimeStamp(); // UInt64 time_3 = GetTimeStamp();
// Modbus_ReadCoilsTask(out EIO, 5, 16, 6, out int signE); // Modbus_ReadCoilsTask(out EIO, 40, 16, 6, out int signE);
// Modbus_ReadCoilsTask(out SIO, 8, 16, 6, out int signS); // Modbus_ReadCoilsTask(out SIO, 19, 16, 6, out int signS);
// Modbus_ReadCoilsTask(out WIO, 4, 16, 6, out int signW); // Modbus_ReadCoilsTask(out WIO, 41, 16, 6, out int signW);
// if (sign == -1) // if (sign == -1)
// { // {
...@@ -961,6 +908,9 @@ namespace ModbusDemo ...@@ -961,6 +908,9 @@ namespace ModbusDemo
// vs = rtd.RtdValue(temperature, type); // vs = rtd.RtdValue(temperature, type);
// EastTemperature = float.Parse(vs[0]); // EastTemperature = float.Parse(vs[0]);
// s = Analog.Value(register, Inputtype); // s = Analog.Value(register, Inputtype);
// //(实时电流值 - 设定电流最小值) /(20Ma - 设定电流最小值) *设定测量最大值
// //(实时电流值 - 4ma) /(20ma - 4ma) *设定测量最大值(也就是设定的满量程)
// Easternwaterlevel = (float.Parse(s[0]) - 4) / 16 * 6; // Easternwaterlevel = (float.Parse(s[0]) - 4) / 16 * 6;
// s6 = Analog.Value(registerN, InputtypeN); // s6 = Analog.Value(registerN, InputtypeN);
// WestWaterLevel = (float.Parse(s6[0]) - 4) / 16 * 6; // WestWaterLevel = (float.Parse(s6[0]) - 4) / 16 * 6;
...@@ -971,16 +921,16 @@ namespace ModbusDemo ...@@ -971,16 +921,16 @@ namespace ModbusDemo
// WOnOff = state.IO(WIO); ////东南北水 // WOnOff = state.IO(WIO); ////东南北水
// //} // //}
// WTDR14P x = new WTDR14P("1", EastTemperature, 0, 0, 0, time_1); // WTDR14P x = new WTDR14P("27", EastTemperature, 0, 0, 0, time_1);
// WTDR18X p = new WTDR18X("3", Easternwaterlevel, 0, 0, 0, 0, 0, 0, 0, time_2); // WTDR18X p = new WTDR18X("21", Easternwaterlevel, 0, 0, 0, 0, 0, 0, 0, time_2);
// WTDR18X q = new WTDR18X("6", WestWaterLevel, 0, 0, 0, 0, 0, 0, 0, time_3); // WTDR18X q = new WTDR18X("53", WestWaterLevel, 0, 0, 0, 0, 0, 0, 0, time_3);
// //东搅拌 // //东搅拌
// WTDR66C EastStir = new WTDR66C("5", EOnOff[0], EOnOff[1], EOnOff[2], EOnOff[3], EOnOff[4], EOnOff[5], GetTimeStamp()); // WTDR66C EastStir = new WTDR66C("40", EOnOff[0], EOnOff[1], EOnOff[2], EOnOff[3], EOnOff[4], EOnOff[5], GetTimeStamp());
// //东南北水 // //东南北水
// WTDR66C WestStir = new WTDR66C("4", WOnOff[0], WOnOff[1], WOnOff[2], WOnOff[3], WOnOff[4], WOnOff[5], GetTimeStamp()); // WTDR66C WestStir = new WTDR66C("41", WOnOff[0], WOnOff[1], WOnOff[2], WOnOff[3], WOnOff[4], WOnOff[5], GetTimeStamp());
// //西搅拌 // //西搅拌
// WTDR66C SouthWater = new WTDR66C("8", SOnOff[0], SOnOff[1], SOnOff[2], SOnOff[3], SOnOff[4], SOnOff[5], GetTimeStamp()); // WTDR66C SouthWater = new WTDR66C("19", SOnOff[0], SOnOff[1], SOnOff[2], SOnOff[3], SOnOff[4], SOnOff[5], GetTimeStamp());
// mqttData = "[" + // mqttData = "[" +
// JsonConvert.SerializeObject(x) + "," + // JsonConvert.SerializeObject(x) + "," +
...@@ -991,89 +941,88 @@ namespace ModbusDemo ...@@ -991,89 +941,88 @@ namespace ModbusDemo
// JsonConvert.SerializeObject(SouthWater) // JsonConvert.SerializeObject(SouthWater)
// + "]"; // + "]";
//} //}
//catch (Exception exception)
catch (Exception exception) //{
{ // //Connection exception
//Connection exception // //No response from server.
//No response from server. // //The server maybe close the com port, or response timeout.
//The server maybe close the com port, or response timeout. // if (exception.Source.Equals("System"))
if (exception.Source.Equals("System")) // {
{ // timer.Stop();
timer.Stop(); // Console.WriteLine(DateTime.Now.ToString() + " " + exception.Message);
Console.WriteLine(DateTime.Now.ToString() + " " + exception.Message); // totxt.Log(DateTime.Now.ToString() + " " + exception.Message);
totxt.Log(DateTime.Now.ToString() + " " + exception.Message); // return;
return; // }
} // //The server return error code.
//The server return error code. // //You can get the function code and exception code.
//You can get the function code and exception code. // if (exception.Source.Equals("nModbusPC"))
if (exception.Source.Equals("nModbusPC")) // {
{ // string str = exception.Message;
string str = exception.Message; // int FunctionCode;
int FunctionCode; // string ExceptionCode;
string ExceptionCode;
// str = str.Remove(0, str.IndexOf("\r\n") + 17);
str = str.Remove(0, str.IndexOf("\r\n") + 17); // FunctionCode = Convert.ToInt16(str.Remove(str.IndexOf("\r\n")));
FunctionCode = Convert.ToInt16(str.Remove(str.IndexOf("\r\n"))); // Console.WriteLine("Function Code: " + FunctionCode.ToString("X"));
Console.WriteLine("Function Code: " + FunctionCode.ToString("X")); // totxt.Log("Function Code: " + FunctionCode.ToString("X"));
totxt.Log("Function Code: " + FunctionCode.ToString("X")); // //MessageBox.Show("Function Code: " + FunctionCode.ToString("X"));
//MessageBox.Show("Function Code: " + FunctionCode.ToString("X"));
// str = str.Remove(0, str.IndexOf("\r\n") + 17);
str = str.Remove(0, str.IndexOf("\r\n") + 17); // ExceptionCode = str.Remove(str.IndexOf("-"));
ExceptionCode = str.Remove(str.IndexOf("-")); // switch (ExceptionCode.Trim())
switch (ExceptionCode.Trim()) // {
{ // case "1":
case "1": // Console.WriteLine("Exception Code: " + ExceptionCode.Trim() + "----> Illegal function!");
Console.WriteLine("Exception Code: " + ExceptionCode.Trim() + "----> Illegal function!"); // //MessageBox.Show("Exception Code: " + ExceptionCode.Trim() + "----> Illegal function!");
//MessageBox.Show("Exception Code: " + ExceptionCode.Trim() + "----> Illegal function!"); // totxt.Log("Exception Code: " + ExceptionCode.Trim() + "----> Illegal function!");
totxt.Log("Exception Code: " + ExceptionCode.Trim() + "----> Illegal function!"); // break;
break; // case "2":
case "2": // Console.WriteLine("Exception Code: " + ExceptionCode.Trim() + "----> Illegal data address!");
Console.WriteLine("Exception Code: " + ExceptionCode.Trim() + "----> Illegal data address!"); // totxt.Log("Exception Code: " + ExceptionCode.Trim() + "----> Illegal data address!");
totxt.Log("Exception Code: " + ExceptionCode.Trim() + "----> Illegal data address!"); // //MessageBox.Show("Exception Code: " + ExceptionCode.Trim() + "----> Illegal data address!");
//MessageBox.Show("Exception Code: " + ExceptionCode.Trim() + "----> Illegal data address!"); // break;
break; // case "3":
case "3": // Console.WriteLine("Exception Code: " + ExceptionCode.Trim() + "----> Illegal data value!");
Console.WriteLine("Exception Code: " + ExceptionCode.Trim() + "----> Illegal data value!"); // totxt.Log("Exception Code: " + ExceptionCode.Trim() + "----> Illegal data value!");
totxt.Log("Exception Code: " + ExceptionCode.Trim() + "----> Illegal data value!"); // //MessageBox.Show("Exception Code: " + ExceptionCode.Trim() + "----> Illegal data value!");
//MessageBox.Show("Exception Code: " + ExceptionCode.Trim() + "----> Illegal data value!"); // break;
break; // case "4":
case "4": // Console.WriteLine("Exception Code: " + ExceptionCode.Trim() + "----> Slave device failure!");
Console.WriteLine("Exception Code: " + ExceptionCode.Trim() + "----> Slave device failure!"); // totxt.Log("Exception Code: " + ExceptionCode.Trim() + "----> Slave device failure!");
totxt.Log("Exception Code: " + ExceptionCode.Trim() + "----> Slave device failure!"); // //MessageBox.Show("Exception Code: " + ExceptionCode.Trim() + "----> Slave device failure!");
//MessageBox.Show("Exception Code: " + ExceptionCode.Trim() + "----> Slave device failure!"); // break;
break; // case "5":
case "5": // Console.WriteLine("Exception Code: " + ExceptionCode.Trim() + "----> ACKNOWLEDGE!");
Console.WriteLine("Exception Code: " + ExceptionCode.Trim() + "----> ACKNOWLEDGE!"); // totxt.Log("Exception Code: " + ExceptionCode.Trim() + "----> ACKNOWLEDGE!");
totxt.Log("Exception Code: " + ExceptionCode.Trim() + "----> ACKNOWLEDGE!"); // //MessageBox.Show("Exception Code: " + ExceptionCode.Trim() + "----> ACKNOWLEDGE!");
//MessageBox.Show("Exception Code: " + ExceptionCode.Trim() + "----> ACKNOWLEDGE!"); // break;
break; // case "6":
case "6": // Console.WriteLine("Exception Code: " + ExceptionCode.Trim() + "----> SLAVE DEVICE BUSY !");
Console.WriteLine("Exception Code: " + ExceptionCode.Trim() + "----> SLAVE DEVICE BUSY !"); // totxt.Log("Exception Code: " + ExceptionCode.Trim() + "----> SLAVE DEVICE BUSY !");
totxt.Log("Exception Code: " + ExceptionCode.Trim() + "----> SLAVE DEVICE BUSY !"); // //MessageBox.Show("Exception Code: " + ExceptionCode.Trim() + "----> SLAVE DEVICE BUSY !");
//MessageBox.Show("Exception Code: " + ExceptionCode.Trim() + "----> SLAVE DEVICE BUSY !"); // break;
break; // case "8":
case "8": // Console.WriteLine("Exception Code: " + ExceptionCode.Trim() + "----> MEMORY PARITY ERROR !");
Console.WriteLine("Exception Code: " + ExceptionCode.Trim() + "----> MEMORY PARITY ERROR !"); // totxt.Log("Exception Code: " + ExceptionCode.Trim() + "----> MEMORY PARITY ERROR !");
totxt.Log("Exception Code: " + ExceptionCode.Trim() + "----> MEMORY PARITY ERROR !"); // //MessageBox.Show("Exception Code: " + ExceptionCode.Trim() + "----> MEMORY PARITY ERROR !");
//MessageBox.Show("Exception Code: " + ExceptionCode.Trim() + "----> MEMORY PARITY ERROR !"); // break;
break; // case "A":
case "A": // Console.WriteLine("Exception Code: " + ExceptionCode.Trim() + "----> GATEWAY PATH UNAVAILABLE !");
Console.WriteLine("Exception Code: " + ExceptionCode.Trim() + "----> GATEWAY PATH UNAVAILABLE !"); // totxt.Log("Exception Code: " + ExceptionCode.Trim() + "----> GATEWAY PATH UNAVAILABLE !");
totxt.Log("Exception Code: " + ExceptionCode.Trim() + "----> GATEWAY PATH UNAVAILABLE !"); // //MessageBox.Show("Exception Code: " + ExceptionCode.Trim() + "----> GATEWAY PATH UNAVAILABLE !");
//MessageBox.Show("Exception Code: " + ExceptionCode.Trim() + "----> GATEWAY PATH UNAVAILABLE !"); // break;
break; // case "B":
case "B": // Console.WriteLine("Exception Code: " + ExceptionCode.Trim() + "---->GATEWAY TARGET DEVICE FAILED TO RESPOND!");
Console.WriteLine("Exception Code: " + ExceptionCode.Trim() + "---->GATEWAY TARGET DEVICE FAILED TO RESPOND!"); // totxt.Log("Exception Code: " + ExceptionCode.Trim() + "---->GATEWAY TARGET DEVICE FAILED TO RESPOND!");
totxt.Log("Exception Code: " + ExceptionCode.Trim() + "---->GATEWAY TARGET DEVICE FAILED TO RESPOND!"); // //MessageBox.Show("Exception Code: " + ExceptionCode.Trim() + "----> GATEWAY TARGET DEVICE FAILED TO RESPOND!");
//MessageBox.Show("Exception Code: " + ExceptionCode.Trim() + "----> GATEWAY TARGET DEVICE FAILED TO RESPOND!"); // break;
break; // }
} // return;
return; // }
} //}
} //finally
finally //{
{ //}
}
return; return;
} }
...@@ -1146,7 +1095,6 @@ namespace ModbusDemo ...@@ -1146,7 +1095,6 @@ namespace ModbusDemo
} }
#endregion #endregion
#region 网络检测 #region 网络检测
ManualResetEvent network = new ManualResetEvent(false); ManualResetEvent network = new ManualResetEvent(false);
...@@ -1627,8 +1575,8 @@ namespace ModbusDemo ...@@ -1627,8 +1575,8 @@ namespace ModbusDemo
private void button2_Click(object sender, EventArgs e) private void button2_Click(object sender, EventArgs e)
{ {
//Modbus_polling(); //Modbus_polling();
ModualPoll.vAllNodePoll(); //ModualPoll.vAllNodePoll();
ModualPoll.stAll_Poll_Package(); //mqttData = ModualPoll.stAll_Poll_Package();
} }
private async void SubscribeBut_Click(object sender, EventArgs e) private async void SubscribeBut_Click(object sender, EventArgs e)
...@@ -1696,6 +1644,14 @@ namespace ModbusDemo ...@@ -1696,6 +1644,14 @@ namespace ModbusDemo
master.Transport.ReadTimeout = 1000; //读取串口数据超时时间(ms) master.Transport.ReadTimeout = 1000; //读取串口数据超时时间(ms)
master.Transport.WriteTimeout = 1000;//写入串口数据超时时间(ms) master.Transport.WriteTimeout = 1000;//写入串口数据超时时间(ms)
master.Transport.WaitToRetryMilliseconds = 0;//重试间隔(ms) master.Transport.WaitToRetryMilliseconds = 0;//重试间隔(ms)
ModbusComm.Modbus = ModbusSerialMaster.CreateRtu(comPort);
ModbusComm.Modbus.Transport.Retries = 0;
ModbusComm.Modbus.Transport.ReadTimeout = 1000;
ModbusComm.Modbus.Transport.WriteTimeout = 1000;
ModbusComm.Modbus.Transport.WaitToRetryMilliseconds = 0;
modbus_Timer.Enabled = true; modbus_Timer.Enabled = true;
btOpenCOM.Enabled = false; btOpenCOM.Enabled = false;
btCloseCOM.Enabled = true; btCloseCOM.Enabled = true;
...@@ -1708,7 +1664,6 @@ namespace ModbusDemo ...@@ -1708,7 +1664,6 @@ namespace ModbusDemo
return; return;
} }
} }
private void btCloseCOM_Click(object sender, EventArgs e) private void btCloseCOM_Click(object sender, EventArgs e)
{ {
//Close comport first,then stop and dispose slave. //Close comport first,then stop and dispose slave.
...@@ -1722,6 +1677,4 @@ namespace ModbusDemo ...@@ -1722,6 +1677,4 @@ namespace ModbusDemo
totxt.Log(DateTime.Now.ToString() + " =>Disconnect " + comPort.PortName); totxt.Log(DateTime.Now.ToString() + " =>Disconnect " + comPort.PortName);
} }
} }
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment