Commit 6e241f93 authored by leon.huang's avatar leon.huang

add inturrupt close

parent f07825d9
......@@ -26,6 +26,7 @@ namespace ModbusDemo.Common
ChannelDataChangeError = 8,
ChannelLevelError = 16,
ChannelControlError = 32,
ChannelRunOverTimeError = 64,
}
public static void vSetAlarmList(ushort usAddress, ushort[] usChannel, ushort[] usChannelAlarmcode)
{
......@@ -56,7 +57,6 @@ 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++)
......
......@@ -28,20 +28,11 @@ namespace ModbusDemo.MessageFormat
MB_EMASTERSENT,
MB_RTUERNOERR
}
<<<<<<< HEAD
public static ModbusMaster Modbus;
public static ushort usCommunFailTimes = 0;
private static object oLock = new object();
public static eModbusErrorCode Modbus_ReadHoldingRegistersTask(out ushort[] OutputValue, byte slaveAddress, ushort startAddress, ushort numberOfPoints)
{
=======
public static ModbusMaster Modbus;
public static ushort usCommunFailTimes = 0;
static object oLock = new object();
public static eModbusErrorCode Modbus_ReadHoldingRegistersTask(out ushort[] OutputValue, byte slaveAddress, ushort startAddress, ushort numberOfPoints)
{
>>>>>>> 5635bdf708c90bb2146f99466d1145dda5dabb37
lock (oLock)
{
eModbusErrorCode ModbusErrorCode;
......@@ -126,10 +117,6 @@ namespace ModbusDemo.MessageFormat
}
public static eModbusErrorCode Modbus_ReadCoilsTask(out bool[] OutputValue, byte slaveAddress, ushort startAddress, ushort numberOfPoints)
{
<<<<<<< HEAD
=======
//object oLock = new object();
>>>>>>> 5635bdf708c90bb2146f99466d1145dda5dabb37
lock (oLock)
{
eModbusErrorCode ModbusErrorCode;
......@@ -214,10 +201,6 @@ namespace ModbusDemo.MessageFormat
}
public static eModbusErrorCode Modbus_WriteSingleCoil(byte slaveAddress, ushort startAddress, bool value)
{
<<<<<<< HEAD
=======
//object oLock = new object();
>>>>>>> 5635bdf708c90bb2146f99466d1145dda5dabb37
lock (oLock)
{
eModbusErrorCode ModbusErrorCode;
......@@ -300,10 +283,6 @@ namespace ModbusDemo.MessageFormat
}
public static eModbusErrorCode Modbus_WriteMultipleCoils(byte slaveAddress, ushort startAddress, bool[] data)
{
<<<<<<< HEAD
=======
//object oLock = new object();
>>>>>>> 5635bdf708c90bb2146f99466d1145dda5dabb37
lock (oLock)
{
eModbusErrorCode ModbusErrorCode;
......
This diff is collapsed.
......@@ -91,10 +91,8 @@
<Compile Include="application\AutoControl.cs" />
<Compile Include="application\ControlMap.cs" />
<Compile Include="application\InIHelper.cs" />
<Compile Include="application\PoolModbusSet.cs" />
<Compile Include="application\ModualPool.cs" />
<Compile Include="application\AllPond.cs" />
<Compile Include="application\UsThread.cs" />
<Compile Include="Common\ModualAlarm.cs" />
<Compile Include="Common\OperIni.cs" />
<Compile Include="MessageFormat\ModualControl.cs" />
......@@ -180,15 +178,15 @@
</PropertyGroup>
<Import Project="$(SQLDBExtensionsRefPath)\Microsoft.Data.Tools.Schema.Sql.UnitTesting.targets" Condition="$(VisualStudioVersion) != '15.0' And '$(SQLDBExtensionsRefPath)' != ''" />
<Import Project="$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)\SSDT\Microsoft.Data.Tools.Schema.Sql.UnitTesting.targets" Condition="$(VisualStudioVersion) != '15.0' And '$(SQLDBExtensionsRefPath)' == ''" />
<<<<<<< HEAD
<<<<<<< HEAD
=======
=======
>>>>>>> 5635bdf708c90bb2146f99466d1145dda5dabb37
<!-- <<<<<<< HEAD -->
<!-- <<<<<<< HEAD -->
<!-- ======= -->
<!-- ======= -->
<!-- >>>>>>> 5635bdf708c90bb2146f99466d1145dda5dabb37 -->
<PropertyGroup>
<SsdtUnitTestVersion>3.1</SsdtUnitTestVersion>
</PropertyGroup>
>>>>>>> origin/master
<!-- >>>>>>> origin/master -->
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
<Target Name="BeforeBuild">
......
......@@ -36,7 +36,7 @@ namespace ModbusDemo.Modular
#if DEBUG_TEST
public const byte byX18xNumber = 1;
public static byte[] byX18xIdlist = { 13 };
private static modual.eX18xSensorChannelType[,] sX18xChannelType = new modual.eX18xSensorChannelType[byX18xNumber, byX18xReadDataNumber] { { modual.eX18xSensorChannelType.Mike_6, modual.eX18xSensorChannelType.Null, modual.eX18xSensorChannelType.NormalCurrent, modual.eX18xSensorChannelType.Null, modual.eX18xSensorChannelType.Null, modual.eX18xSensorChannelType.Null, modual.eX18xSensorChannelType.Null, modual.eX18xSensorChannelType.Null } };
private static modual.eX18xSensorChannelType[,] sX18xChannelType = new modual.eX18xSensorChannelType[byX18xNumber, byX18xReadDataNumber] { { modual.eX18xSensorChannelType.NormalCurrent, modual.eX18xSensorChannelType.Null, modual.eX18xSensorChannelType.NormalCurrent, modual.eX18xSensorChannelType.Null, modual.eX18xSensorChannelType.Null, modual.eX18xSensorChannelType.Null, modual.eX18xSensorChannelType.Null, modual.eX18xSensorChannelType.Null } };
#else
public const byte byX18xNumber = 6;
public static byte[] byX18xIdlist = {3,53,6,12,21,25};
......
......@@ -89,8 +89,6 @@ namespace ModbusDemo.Modular
{
this.sX18xDataStruct[i].dBeforeConvertData = new double[ModualPoll.byX18xReadDataNumber];
this.sX18xDataStruct[i].dNowConvertData = new double[ModualPoll.byX18xReadDataNumber];
//this.sX18xDataStruct[i].usRegData = new ushort[ModualPoll.byX18xReadDataNumber];
//this.sX18xDataStruct[i].usTypeData = new ushort[ModualPoll.byX18xReadDataNumber];
this.sX18xAlarmstruct[i].usBeforeAlarmCode = new ushort[ModualPoll.byX18xReadDataNumber];
this.sX18xAlarmstruct[i].usNowAlarmCode = new ushort[ModualPoll.byX18xReadDataNumber];
this.sX18xAlarmstruct[i].usCommFailTimes = new ushort[ModualPoll.byX18xReadDataNumber];
......
This diff is collapsed.
......@@ -4,39 +4,113 @@ using System.Linq;
using System.Text;
using System.Threading.Tasks;
using ModbusDemo.application;
using ModbusDemo.MessageFormat;
namespace ModbusDemo.application
{
public class ControlMap
{
public delegate bool bDelege_Handle(bool[] bControlData);
public static bDelege_Handle bDelege_Operation;
public static bool bControl_Map(bool bOpen, byte byControlID, params string[] strOperationChannelName)
public static byte byMapIdleID;
public static bool[] byMapIdleControlData;
public static string[] strMapIdleChannelName;
public static bool bMap_Idle_Operation_Control(bool[] bControldata)
{
bool[] bControlBit = new bool[bControldata.Count()];
bool bStatus;
for (int i = 0; i < bControldata.Count(); i++)
{
string str = "d" + i.ToString();
for (int j = 0; j < strMapIdleChannelName.Count(); j++)
{
if (str == strMapIdleChannelName[j])
{
bControlBit[i] = true;
bControldata[i] = byMapIdleControlData[i];
}
}
}
bStatus = ModualControl.bOperation_Machine(true, byMapIdleID, bControldata, bControlBit, 0, null);
return bStatus;
}
public static bool bControl_Map(bool bOpen, byte byControlID,bool[] bControlData, params string[] strOperationChannelName)
{
bool bMapStatus = true;
if (bOpen == true)
{
if (byControlID == 16 && strOperationChannelName[0] == "d0")
if (byControlID == 31 && strOperationChannelName[0] == "d1")
{
bDelege_Operation = AllPond.cEastTransitPool.cPumb1.bOpen_Machine;
bDelege_Operation = AllPond.cEastTransitPool.cSouthWater.bOpen_Machine;
}
else if (byControlID == 16 && strOperationChannelName[0] == "d0")
{
bDelege_Operation = AllPond.cEastTransitPool.cNorthWater.bOpen_Machine;
}
else if (byControlID == 16 && strOperationChannelName[0] == "d2")
{
bDelege_Operation = AllPond.cEastTransitPool.cPumb1.bOpen_Machine;
}
else if (byControlID == 35 && strOperationChannelName[0] == "d0")
{
bDelege_Operation = AllPond.cEastTransitPool.cPumb2.bOpen_Machine;
}
else if (byControlID == 35 && strOperationChannelName[0] == "d2")
{
bDelege_Operation = AllPond.cEastTransitPool.cStirrer1.bOpen_Machine;
}
else if (byControlID == 39 && strOperationChannelName[0] == "d0")
{
bDelege_Operation = AllPond.cEastTransitPool.cStirrer2.bOpen_Machine;
}
else if (byControlID == 39 && strOperationChannelName[0] == "d2")
{
bDelege_Operation = AllPond.cEastTransitPool.cStirrer3.bOpen_Machine;
}
else
{
byMapIdleID = byControlID;
strMapIdleChannelName = strOperationChannelName;
byMapIdleControlData = bControlData;
bDelege_Operation = bMap_Idle_Operation_Control;
}
}
else
{
if (byControlID == 16 && strOperationChannelName[0] == "d0")
if (byControlID == 31 && strOperationChannelName[0] == "d1")
{
bDelege_Operation = AllPond.cEastTransitPool.cPumb1.bClose_Machine;
bDelege_Operation = AllPond.cEastTransitPool.cSouthWater.bClose_Machine;
}
else if (byControlID == 16 && strOperationChannelName[0] == "d0")
{
bDelege_Operation = AllPond.cEastTransitPool.cNorthWater.bClose_Machine;
}
else if (byControlID == 16 && strOperationChannelName[0] == "d2")
{
bDelege_Operation = AllPond.cEastTransitPool.cPumb1.bClose_Machine;
}
else if (byControlID == 35 && strOperationChannelName[0] == "d0")
{
bDelege_Operation = AllPond.cEastTransitPool.cPumb2.bClose_Machine;
}
else if (byControlID == 35 && strOperationChannelName[0] == "d2")
{
bDelege_Operation = AllPond.cEastTransitPool.cStirrer1.bClose_Machine;
}
else if (byControlID == 39 && strOperationChannelName[0] == "d0")
{
bDelege_Operation = AllPond.cEastTransitPool.cStirrer2.bClose_Machine;
}
else if (byControlID == 39 && strOperationChannelName[0] == "d2")
{
bDelege_Operation = AllPond.cEastTransitPool.cStirrer3.bClose_Machine;
}
else
{
byMapIdleID = byControlID;
strMapIdleChannelName = strOperationChannelName;
byMapIdleControlData = bControlData;
bDelege_Operation = bMap_Idle_Operation_Control;
}
}
return bMapStatus;
}
......
......@@ -48,15 +48,15 @@ namespace ModbusDemo.application
}
public class pcLiquidlevel
{
private string strLevel;
public double dCurrentlevel { get => vGet_ResCurrent();}
private byte byModbusID;
private string strLevel;
public double dCurrentlevel { get => vGet_ResCurrent();}
private byte byModbusID;
private string[] strChannelNumber;
public pcLiquidlevel(string strName, byte byModbusID,params string[] strChannelNumber)
{
this.strLevel = strName;
this.byModbusID = byModbusID;
this.strChannelNumber = strChannelNumber;
this.strLevel = strName;
this.byModbusID = byModbusID;
this.strChannelNumber = strChannelNumber;
}
private double vGet_ResCurrent()
{
......@@ -83,34 +83,22 @@ namespace ModbusDemo.application
}
public class pcOperation
{
public byte byModbusID;
public string[] strChannelNumber;
public string strOperationNumber;
public bool[] bOpenOperation;
public bool[] bCloseOperation;
public bool bHadRefControl;
public byte byResModbusID;
public string strResChannelNumber;
public byte byModbusID;
public string[] strChannelNumber;
public string strOperationNumber;
public bool[] bOpenOperation;
public bool[] bCloseOperation;
//public pcOperation(byte byControlID, string[] strChannelNumber,string strOperationNumber,bool bHadRefControl,byte byResID,string strResChannelName,bool[] bOpenData,bool[] bCloseData)
//{
// this.byModbusID = byControlID;
// this.strChannelNumber = strChannelNumber;
// this.strOperationNumber = strOperationNumber;
// this.bHadRefControl = bHadRefControl;
// this.byResModbusID = byResID;
// this.strResChannelNumber = strResChannelName;
// this.bOpenOperation = bOpenData;
// this.bCloseOperation = bCloseData;
//}
public bool bHadRefControl;
public byte byResModbusID;
public string strResChannelNumber;
}
public class pcMachine:pcOperation
public class pcMachine : pcOperation
{
public string strMachinebName;
public double dChannelCurrent { get => vGet_ResCurrent();}
public bool bHadOpenPumb;
public bool[] bCurrentRelay;
public string strMachinebName;
public double dChannelCurrent { get => vGet_ResCurrent();}
public bool bHadOpenPumb;
public bool[] bCurrentRelay { get => bGet_Current_Relay();}
public pcMachine(string strMachineName,pcOperation pcOperation) // base(pcOperation.byModbusID,pcOperation.strChannelNumber,pcOperation.strOperationNumber,pcOperation.bHadRefControl,pcOperation.byResModbusID,pcOperation.strResChannelNumber,pcOperation.bOpenOperation,pcOperation.bCloseOperation)
{
this.strMachinebName = strMachineName;
......@@ -123,7 +111,6 @@ namespace ModbusDemo.application
this.bOpenOperation = pcOperation.bOpenOperation;
this.bCloseOperation = pcOperation.bCloseOperation;
}
public bool bOpen_Machine(bool[] bControldata)
{
bool[] bControlBit = new bool[bControldata.Count()];
......@@ -146,7 +133,6 @@ namespace ModbusDemo.application
}
return bStatus;
}
public bool bClose_Machine(bool[] bControldata)
{
bool[] bControlBit = new bool[bControldata.Count()];
......@@ -169,16 +155,96 @@ namespace ModbusDemo.application
}
return bStatus;
}
private double vGet_ResCurrent()
{
double[] dConvertData;
if (ModualPoll.bGet_channel_Value<double>(byResModbusID, out dConvertData, strResChannelNumber) == true)
if (bHadRefControl == true && ModualPoll.bGet_channel_Value<double>(byResModbusID, out dConvertData, strResChannelNumber) == true)
{
return dConvertData[0];
}
return 0;
}
private bool[] bGet_Current_Relay()
{
bool[] bRelaydata;
if (ModualPoll.bGet_channel_Value<bool>(byModbusID, out bRelaydata, strChannelNumber) == true)
{
return bRelaydata;
}
else
{
return bRelaydata;
}
}
}
public class pcButtonOperation
{
public byte byModbusID;
public string[] strChannelNumber;
public string strOperationNumber;
public bool[] bOpenOperation;
public bool[] bCloseOperation;
}
public class pcButton :pcButtonOperation
{
public string strButtonName;
public bool[] bCurrentRelay { get => bGet_Current_Relay();}
public pcButton(string strButtonName,pcButtonOperation cButtonOperation)
{
this.strButtonName = strButtonName;
this.byModbusID = cButtonOperation.byModbusID;
this.strOperationNumber = cButtonOperation.strOperationNumber;
this.strChannelNumber = cButtonOperation.strChannelNumber;
this.bOpenOperation = cButtonOperation.bOpenOperation;
this.bCloseOperation = cButtonOperation.bCloseOperation;
}
public bool bOpreation_Button(bool[] bControldata)
{
bool bStatus;
bool[] bControlBit = new bool[bControldata.Count()];
for (int i = 0; i < bControldata.Count(); i++)
{
string str = "d" + i.ToString();
for (int j = 0; j < strChannelNumber.Count(); j++)
{
if (str == strChannelNumber[j])
{
bControlBit[i] = true;
bControldata[i] = bOpenOperation[j];
}
}
}
if ((bStatus = ModualControl.bOperation_Machine(true, byModbusID, bControldata, bControlBit, 0, null)) == true)
{
for (int i = 0; i < bControldata.Count(); i++)
{
string str = "d" + i.ToString();
for (int j = 0; j < strChannelNumber.Count(); j++)
{
if (str == strChannelNumber[j])
{
bControlBit[i] = true;
bControldata[i] = bCloseOperation[j];
}
}
}
bStatus = ModualControl.bOperation_Machine(true, byModbusID, bControldata, bControlBit, 0, null);
}
return bStatus;
}
private bool[] bGet_Current_Relay()
{
bool[] bRelaydata;
if (ModualPoll.bGet_channel_Value<bool>(byModbusID, out bRelaydata, strChannelNumber) == true)
{
return bRelaydata;
}
else
{
return bRelaydata;
}
}
}
}
}
This diff is collapsed.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Threading;
namespace ModbusDemo.application
{
}
......@@ -26,7 +26,7 @@ namespace ModbusDemo
{
public partial class Form1 : Form
{
const bool LOCALDEBUG = true;
const bool LOCALDEBUG = false;
private bool bStart = false;
AutoResetEvent exitEvent;
private int waitTime;
......@@ -1069,48 +1069,6 @@ namespace ModbusDemo
private void button2_Click(object sender, EventArgs e)
{
<<<<<<< HEAD
=======
<<<<<<< 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
>>>>>>> 5635bdf708c90bb2146f99466d1145dda5dabb37
}
......@@ -1174,9 +1132,9 @@ namespace ModbusDemo
ModbusComm.Modbus.Transport.ReadTimeout = 1000;
ModbusComm.Modbus.Transport.WriteTimeout = 1000;
ModbusComm.Modbus.Transport.WaitToRetryMilliseconds = 0;
t_AutoControl = new Thread(T_AutoControl);
t_AutoControl.IsBackground = true;
t_AutoControl.Start();
//t_AutoControl = new Thread(T_AutoControl);
//t_AutoControl.IsBackground = true;
//t_AutoControl.Start();
modbus_Timer.Enabled = true;
btOpenCOM.Enabled = false;
btCloseCOM.Enabled = true;
......
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