Commit 5635bdf7 authored by shaxuezheng's avatar shaxuezheng

Updata cotrol logic

parents beb1f654 83d8d9d1
......@@ -7,6 +7,7 @@ using System.Collections;
using MQTTnet;
using MQTTnet.Client;
using Newtonsoft.Json;
using ModbusDemo.Modular;
namespace ModbusDemo.Common
{
public static class ModualAlarm
......@@ -55,5 +56,137 @@ namespace ModbusDemo.Common
.Build();
await mqttClient.PublishAsync(message);
}
public static void vSet_Modual_Alarm(byte byModbusID,ushort usAlarmCodde,bool bSetAlarm,byte byCommFailTimes,params string[] strChannalList)
{
for (int i = 0; i < ModualPoll.byX14pNumber;i++)
{
if (byModbusID == ModualPoll.cx14P.byModbusID[i])
{
for (int j = 0; j < strChannalList.Count(); j++)
{
for (int k = 0; k < 8; k++)
{
string strChannel = "d" + i.ToString();
if (strChannalList[k] == strChannel)
{
if (bSetAlarm == true)
{
if ((usAlarmCodde & (ushort)eAlarmCode.ChannelCommunError) == (ushort)eAlarmCode.ChannelCommunError)
{
ModualPoll.cx14P.sX14PAlarmStruct[i].usCommFailTimes[k] += byCommFailTimes;
}
ModualPoll.cx14P.sX14PAlarmStruct[i].usNowAlarmCode[k] |= usAlarmCodde;
}
else
{
if ((usAlarmCodde & (ushort)eAlarmCode.ChannelCommunError) == (ushort)eAlarmCode.ChannelCommunError)
{
ModualPoll.cx14P.sX14PAlarmStruct[i].usCommFailTimes[k] = 0;
}
ModualPoll.cx14P.sX14PAlarmStruct[i].usNowAlarmCode[k] &= usAlarmCodde;
}
}
}
}
}
}
for (int i = 0; i < ModualPoll.byX18xNumber; i++)
{
if (byModbusID == ModualPoll.cx18x.byModbusID[i])
{
for (int j = 0; j < strChannalList.Count(); j++)
{
for (int k = 0; k < 8; k++)
{
string strChannel = "d" + i.ToString();
if (strChannalList[k] == strChannel)
{
if (bSetAlarm == true)
{
if ((usAlarmCodde & (ushort)eAlarmCode.ChannelCommunError) == (ushort)eAlarmCode.ChannelCommunError)
{
ModualPoll.cx18x.sX18xAlarmstruct[i].usCommFailTimes[k] += byCommFailTimes;
}
ModualPoll.cx18x.sX18xAlarmstruct[i].usNowAlarmCode[k] |= usAlarmCodde;
}
else
{
if ((usAlarmCodde & (ushort)eAlarmCode.ChannelCommunError) == (ushort)eAlarmCode.ChannelCommunError)
{
ModualPoll.cx18x.sX18xAlarmstruct[i].usCommFailTimes[k] = 0;
}
ModualPoll.cx18x.sX18xAlarmstruct[i].usNowAlarmCode[k] &= usAlarmCodde;
}
}
}
}
}
}
for (int i = 0; i < ModualPoll.byX78cNumber; i++)
{
if (byModbusID == ModualPoll.cx78c.byModbusID[i])
{
for (int j = 0; j < strChannalList.Count(); j++)
{
for (int k = 0; k < 16; k++)
{
string strChannel = "d" + i.ToString();
if (strChannalList[k] == strChannel)
{
if (bSetAlarm == true)
{
if ((usAlarmCodde & (ushort)eAlarmCode.ChannelCommunError) == (ushort)eAlarmCode.ChannelCommunError)
{
ModualPoll.cx78c.sX78cAlarmStruct[i].usCommFailTimes[k] += byCommFailTimes;
}
ModualPoll.cx78c.sX78cAlarmStruct[i].usNowAlarmCode[k] |= usAlarmCodde;
}
else
{
if ((usAlarmCodde & (ushort)eAlarmCode.ChannelCommunError) == (ushort)eAlarmCode.ChannelCommunError)
{
ModualPoll.cx78c.sX78cAlarmStruct[i].usCommFailTimes[k] = 0;
}
ModualPoll.cx78c.sX78cAlarmStruct[i].usNowAlarmCode[k] &= usAlarmCodde;
}
}
}
}
}
}
for (int i = 0; i < ModualPoll.byX66cNumber; i++)
{
if (byModbusID == ModualPoll.cx66c.byModbusID[i])
{
for (int j = 0; j < strChannalList.Count(); j++)
{
for (int k = 0; k < ModualPoll.byX66cRelayRegNumber; k++)
{
string strChannel = "d" + i.ToString();
if (strChannalList[k] == strChannel)
{
if (bSetAlarm == true)
{
if ((usAlarmCodde & (ushort)eAlarmCode.ChannelCommunError) == (ushort)eAlarmCode.ChannelCommunError)
{
ModualPoll.cx66c.sX66cAlarmStruct[i].usCommFailTimes[k] += byCommFailTimes;
}
ModualPoll.cx66c.sX66cAlarmStruct[i].usNowAlarmCode[k] |= usAlarmCodde;
}
else
{
if ((usAlarmCodde & (ushort)eAlarmCode.ChannelCommunError) == (ushort)eAlarmCode.ChannelCommunError)
{
ModualPoll.cx66c.sX66cAlarmStruct[i].usCommFailTimes[k] = 0;
}
ModualPoll.cx66c.sX66cAlarmStruct[i].usNowAlarmCode[k] &= usAlarmCodde;
}
}
}
}
}
}
}
}
}
This diff is collapsed.
This diff is collapsed.
......@@ -155,7 +155,7 @@ namespace ModbusDemo
var message = new MqttApplicationMessageBuilder()
.WithTopic(mqttBackTopic)
.WithPayload(mqttData_Back)
.WithAtMostOnceQoS()
.WithAtLeastOnceQoS()
.WithRetainFlag(false)
.Build();
await mqttClient.PublishAsync(message);
......@@ -171,7 +171,6 @@ namespace ModbusDemo
.WithRetainFlag(false)
.Build();
await mqttClient.PublishAsync(message);
totxt.Log("我在247,执行了Back");
}
private async Task Subscribe()
{
......@@ -471,7 +470,7 @@ namespace ModbusDemo
private void Sendout()
{
Control.CheckForIllegalCrossThreadCalls = false;
MQTTTimer.Interval = 60000;//120500
MQTTTimer.Interval = 20000;//120500
MQTTTimer.Enabled = true;
MQTTTimer.AutoReset = true;//设置是执行一次(false)还是一直执行(true);
MQTTTimer.Start();
......@@ -1070,6 +1069,45 @@ namespace ModbusDemo
private void button2_Click(object sender, EventArgs e)
{
<<<<<<< HEAD
=======
//AutoControl.Control usEcontrol = new AutoControl.Control();
//AutoControl.Control usWcontrol = new AutoControl.Control();
//if (ModualControl.cPoolLevelConfig.Count!=0)
//{
// for (int i = 0; i < ModualControl.cPoolLevelConfig.Count; i++)
// {
// if (ModualControl.cPoolLevelConfig[i].byModbusID == 6)
// {
// usWcontrol.maxLevel = ModualControl.cPoolLevelConfig[i].dUpLevel;
// usWcontrol.minLevel = ModualControl.cPoolLevelConfig[i].dDownLevel;
// usWcontrol.Name = "西·中转池";
// usWcontrol.Enablation = true;
// AutoControl.CriticalValueMonitoring(true, ModualControl.cPoolLevelConfig[1].dUpLevel,
// ModualControl.cPoolLevelConfig[0].dDownLevel, ModualPoll.cx18x.sX18xDataStruct[1].dNowConvertData[1],
// "西·中转池",
// out usWcontrol
// );
// }
// if (ModualControl.cPoolLevelConfig[i].byModbusID == 3)
// {
// usEcontrol.maxLevel = ModualControl.cPoolLevelConfig[i].dUpLevel;
// usEcontrol.minLevel = ModualControl.cPoolLevelConfig[i].dDownLevel;
// usEcontrol.Name = "东·中转池";
// usEcontrol.Enablation = true;
// AutoControl.CriticalValueMonitoring(true, ModualControl.cPoolLevelConfig[0].dUpLevel,
// ModualControl.cPoolLevelConfig[0].dDownLevel, ModualPoll.cx18x.sX18xDataStruct[0].dNowConvertData[0],
// "东·中转池",
// out usEcontrol
// );
// }
// }
//}
>>>>>>> 83d8d9d1b2182210455375f355bb9f6860d45dc2
}
......
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