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

modify x18x Convert data

parent 99e950f7
...@@ -18,7 +18,7 @@ namespace ModbusDemo.Common ...@@ -18,7 +18,7 @@ namespace ModbusDemo.Common
private string sAlarmJson; private string sAlarmJson;
private string sAlarmJsonPackage; private string sAlarmJsonPackage;
//private IMqttClient mqttClient = null; //private IMqttClient mqttClient = null;
public enum eAlarmCode : sbyte public enum eAlarmCode : ushort
{ {
ChannelNoError = 0, ChannelNoError = 0,
ChannelCommunError = 1, ChannelCommunError = 1,
...@@ -26,7 +26,7 @@ namespace ModbusDemo.Common ...@@ -26,7 +26,7 @@ namespace ModbusDemo.Common
ChannelDataRespError = 4, ChannelDataRespError = 4,
ChannelDataChangeError = 8 ChannelDataChangeError = 8
} }
public void vSetAlarmList(ushort usAddress, ushort[] usChannel, ushort[] usChannelAlarmcode) public void vSetAlarmList(ushort usAddress, ushort[] usChannel, ushort[] usChannelAlarmcode,bool bStringIncrease)
{ {
ushort i = 0; ushort i = 0;
hMqtttAlarmMap.Add("addr", usAddress.ToString()); hMqtttAlarmMap.Add("addr", usAddress.ToString());
...@@ -37,11 +37,15 @@ namespace ModbusDemo.Common ...@@ -37,11 +37,15 @@ namespace ModbusDemo.Common
i++; i++;
} }
hMqtttAlarmMap.Add("ts", Form1.GetTimeStamp()); hMqtttAlarmMap.Add("ts", Form1.GetTimeStamp());
sAlarmJson = JsonConvert.SerializeObject(hMqtttAlarmMap); sAlarmJson += JsonConvert.SerializeObject(hMqtttAlarmMap);
if (bStringIncrease == true)
{
sAlarmJson += ",";
}
} }
public async Task vPublishAlarmPackageJson(IMqttClient mqttClient) public async Task vPublishAlarmPackageJson(IMqttClient mqttClient)
{ {
sAlarmJson = "[" + sAlarmJson + "]"; sAlarmJson = "[" + sAlarmJson + "]";
var message = new MqttApplicationMessageBuilder() var message = new MqttApplicationMessageBuilder()
.WithTopic(sAlarmTopic) .WithTopic(sAlarmTopic)
.WithPayload(sAlarmJson) .WithPayload(sAlarmJson)
......
...@@ -21,15 +21,15 @@ namespace ModbusDemo ...@@ -21,15 +21,15 @@ namespace ModbusDemo
{ {
public string addr { get; set; } public string addr { get; set; }
public double d0 { get; set; } public double d0 { get; set; }
public int d1 { get; set; } public double d1 { get; set; }
public int d2 { get; set; } public double d2 { get; set; }
public int d3 { get; set; } public double d3 { get; set; }
public int d4 { get; set; } public double d4 { get; set; }
public int d5 { get; set; } public double d5 { get; set; }
public int d6 { get; set; } public double d6 { get; set; }
public int d7 { get; set; } public double d7 { get; set; }
public UInt64 ts { get; set; } public UInt64 ts { get; set; }
public WTDR18X(string addr, double d0, int d1, int d2, int d3, int d4, int d5, int d6, int d7, UInt64 ts) public WTDR18X(string addr, double d0, double d1, double d2, double d3, double d4, double d5, double d6, double d7, UInt64 ts)
{ {
this.addr = addr; this.addr = addr;
this.d0 = d0; this.d0 = d0;
...@@ -47,11 +47,11 @@ namespace ModbusDemo ...@@ -47,11 +47,11 @@ namespace ModbusDemo
{ {
public string addr { get; set; } public string addr { get; set; }
public double d0 { get; set; } public double d0 { get; set; }
public int d1 { get; set; } public double d1 { get; set; }
public int d2 { get; set; } public double d2 { get; set; }
public int d3 { get; set; } public double d3 { get; set; }
public UInt64 ts { get; set; } public UInt64 ts { get; set; }
public WTDR14P(string addr, double d0, int d1, int d2, int d3, UInt64 ts) public WTDR14P(string addr, double d0, double d1, double d2, double d3, UInt64 ts)
{ {
this.addr = addr; this.addr = addr;
this.d0 = d0; this.d0 = d0;
...@@ -85,6 +85,51 @@ namespace ModbusDemo ...@@ -85,6 +85,51 @@ namespace ModbusDemo
} }
} }
class WTDR78C
{
public string addr { get; set; }
public int d0 { get; set; }
public int d1 { get; set; }
public int d2 { get; set; }
public int d3 { get; set; }
public int d4 { get; set; }
public int d5 { get; set; }
public int d6 { get; set; }
public int d7 { get; set; }
public int d8 { get; set; }
public int d9 { get; set; }
public int d10{ get; set; }
public int d11 { get; set; }
public int d12 { get; set; }
public int d13 { get; set; }
public int d14 { get; set; }
public int d15 { get; set; }
public UInt64 ts { get; set; }
public WTDR78C(string addr, int d0, int d1, int d2, int d3, int d4, int d5,int d6,int d7,int d8,int d9,int d10,int d11,int d12,int d13,int d14,int d15, UInt64 ts)
{
this.addr = addr;
this.d0 = d0;
this.d1 = d1;
this.d2 = d2;
this.d3 = d3;
this.d4 = d4;
this.d5 = d5;
this.d6 = d6;
this.d7 = d7;
this.d8 = d8;
this.d9 = d9;
this.d10 = d10;
this.d11 = d11;
this.d12 = d12;
this.d13 = d13;
this.d14 = d14;
this.d15 = d15;
this.ts = ts;
}
}
public class Ctrl public class Ctrl
{ {
......
...@@ -60,7 +60,7 @@ namespace ModbusDemo ...@@ -60,7 +60,7 @@ namespace ModbusDemo
users.UserCompany = Strcom[Inputtype[0]];//通道类型 users.UserCompany = Strcom[Inputtype[0]];//通道类型
users.UserModel = Inputtype[0];//确定计算公式 users.UserModel = Inputtype[0];//确定计算公式
/********************/ /********************/
users1.UserId = 1;//通道 users1.UserId = 1;//通道;
users1.Data = typeData[1];//数据 users1.Data = typeData[1];//数据
users1.UserCompany = Strcom[Inputtype[1]];//通道类型 users1.UserCompany = Strcom[Inputtype[1]];//通道类型
users1.UserModel = Inputtype[1];//确定计算公式 users1.UserModel = Inputtype[1];//确定计算公式
......
This diff is collapsed.
...@@ -7,36 +7,48 @@ using ModbusDemo.MessageFormat; ...@@ -7,36 +7,48 @@ using ModbusDemo.MessageFormat;
using ModbusDemo.Common; using ModbusDemo.Common;
namespace ModbusDemo.Modular namespace ModbusDemo.Modular
{ {
class modual public class modual
{ {
public struct psx14pData public struct psx14pData
{ {
public ushort[] usX14pRegData; public ushort[] usX14pRegData;
public ushort[] usX14pRegType; public ushort[] usX14pRegType;
public double[] dX14pNowConvertData; public double[] dNowConvertData;
public double[] dX14pBeforeConvertData; public double[] dBeforeConvertData;
} }
public struct psxModualAlarm public struct psxModualAlarm
{ {
public bool bDataNotFirstIncreaseOrDecrease; public bool bDataNotFirstIncreaseOrDecrease;
public ModualAlarm.eAlarmCode[] eNowAlarmCode; public ushort[] usNowAlarmCode;
public ModualAlarm.eAlarmCode[] eBeforeAlarmCode; public ushort[] usBeforeAlarmCode;
} }
public class pcx14P public class pcx14P
{ {
public byte[] byModbusID; public byte[] byModbusID;
public psx14pData[] sX14pDataStruct; public psx14pData[] sX14pDataStruct = new psx14pData[ModualPoll.byX14pNumber];
public psxModualAlarm[] sX14PAlarmStruct; public psxModualAlarm[] sX14PAlarmStruct = new psxModualAlarm[ModualPoll.byX14pNumber];
public ModbusComm.eModbusErrorCode[] ModbusErrorCode;
public pcx14P(byte[] InitIDlist) public pcx14P(byte[] InitIDlist)
{ {
this.byModbusID = InitIDlist; this.byModbusID = InitIDlist;
for (byte i = 0; i < ModualPoll.byX14pNumber; i++)
{
this.sX14pDataStruct[i].dBeforeConvertData = new double[ModualPoll.byX14pReadDataNumber];
this.sX14pDataStruct[i].dNowConvertData = new double[ModualPoll.byX14pReadDataNumber];
//this.sX14pDataStruct[i].usX14pRegType = new ushort[ModualPoll.byX14pReadDataNumber];
//this.sX14pDataStruct[i].usX14pRegData = new ushort[ModualPoll.byX14pReadDataNumber];
this.sX14PAlarmStruct[i].usBeforeAlarmCode = new ushort[ModualPoll.byX14pReadDataNumber];
this.sX14PAlarmStruct[i].usNowAlarmCode = new ushort[ModualPoll.byX14pReadDataNumber];
}
} }
} }
public enum eX18xSensorChannelType : byte public enum eX18xSensorChannelType : byte
{ {
Normal = 0, Null = 0,
Weiertai,
Mike_5,
Mike_6,
Mike_7,
Level, Level,
} }
...@@ -44,25 +56,27 @@ namespace ModbusDemo.Modular ...@@ -44,25 +56,27 @@ namespace ModbusDemo.Modular
{ {
public ushort[] usRegData; public ushort[] usRegData;
public ushort[] usTypeData; public ushort[] usTypeData;
public eX18xSensorChannelType[] eChannelType;
public double[] dNowConvertData; public double[] dNowConvertData;
public double[] dBeforeConvertData; public double[] dBeforeConvertData;
} }
public class pcx18X public class pcx18X
{ {
public byte[] byModbusID; public byte[] byModbusID;
public psX18xData[] sX18xDataStruct; public psX18xData[] sX18xDataStruct = new psX18xData[ModualPoll.byX18xNumber];
public psxModualAlarm[] sX18xAlarmstruct; public psxModualAlarm[] sX18xAlarmstruct = new psxModualAlarm[ModualPoll.byX18xNumber];
public ModbusComm.eModbusErrorCode[] ModbusErrorCode; public eX18xSensorChannelType[,] beChannelType;
public pcx18X(byte[] InitIDlist, eX18xSensorChannelType[,] eChannnelType) public pcx18X(byte[] InitIDlist, eX18xSensorChannelType[,] eChannnelType)
{ {
this.byModbusID = InitIDlist; this.byModbusID = InitIDlist;
for (ushort i = 0; i < eChannnelType.GetLength(0); i++) this.beChannelType = eChannnelType;
for (byte i = 0; i < ModualPoll.byX18xNumber; i++)
{ {
for (ushort j = 0; j < eChannnelType.GetLength(1); j++) this.sX18xDataStruct[i].dBeforeConvertData = new double[ModualPoll.byX18xReadDataNumber];
{ this.sX18xDataStruct[i].dNowConvertData = new double[ModualPoll.byX18xReadDataNumber];
this.sX18xDataStruct[i].eChannelType[j] = eChannnelType[i,j]; //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];
} }
} }
} }
...@@ -70,33 +84,42 @@ namespace ModbusDemo.Modular ...@@ -70,33 +84,42 @@ namespace ModbusDemo.Modular
{ {
public bool[] bInputRegStatus; public bool[] bInputRegStatus;
public bool[] bOutPutRegStatus; public bool[] bOutPutRegStatus;
public bool bX78cAllChannelAlarm;
} }
public class pcx78C public class pcx78C
{ {
public byte[] byModbusID; public byte[] byModbusID;
public psx78C[] sX78cRegStatusStruct; public psx78C[] sX78cRegStatusStruct = new psx78C[ModualPoll.byX78cNumber];
public psxModualAlarm[] sX78cAlarmStruct; public psxModualAlarm[] sX78cAlarmStruct = new psxModualAlarm[ModualPoll.byX78cNumber];
public ModbusComm.eModbusErrorCode[] ModbusErrorCode;
public pcx78C(byte[] InitIDlist) public pcx78C(byte[] InitIDlist)
{ {
this.byModbusID = InitIDlist; this.byModbusID = InitIDlist;
for (byte i = 0; i < ModualPoll.byX78cNumber; i++)
{
this.sX78cRegStatusStruct[i].bInputRegStatus = new bool[ModualPoll.byX78cInputRegNumber];
this.sX78cRegStatusStruct[i].bOutPutRegStatus = new bool[ModualPoll.byX78cOutputRegNumber];
this.sX78cAlarmStruct[i].usBeforeAlarmCode = new ushort[ModualPoll.byX78cInputRegNumber + ModualPoll.byX78cOutputRegNumber];
this.sX78cAlarmStruct[i].usNowAlarmCode = new ushort[ModualPoll.byX78cInputRegNumber + ModualPoll.byX78cOutputRegNumber];
}
} }
} }
public struct psx66C public struct psx66C
{ {
public bool[] bRegRelayStatus; public bool[] bRegRelayStatus;
public bool[] bX66CAllChannelAlarm;
} }
public class pcx66C public class pcx66C
{ {
public byte[] byModbusID; public byte[] byModbusID;
public psx78C[] sX66cRegStatusStruct; public psx66C[] sX66cRegStatusStruct = new psx66C[ModualPoll.byX66cNumber];
public psxModualAlarm[] sX66cAlarmStruct; public psxModualAlarm[] sX66cAlarmStruct = new psxModualAlarm[ModualPoll.byX66cNumber];
public ModbusComm.eModbusErrorCode[] ModbusErrorCode;
public pcx66C(byte[] InitIDlist) public pcx66C(byte[] InitIDlist)
{ {
this.byModbusID = InitIDlist; this.byModbusID = InitIDlist;
for (byte i = 0; i < ModualPoll.byX66cNumber; i++)
{
this.sX66cRegStatusStruct[i].bRegRelayStatus = new bool[ModualPoll.byX66cRelayRegNumber];
this.sX66cAlarmStruct[i].usBeforeAlarmCode = new ushort[ModualPoll.byX66cRelayRegNumber];
this.sX66cAlarmStruct[i].usNowAlarmCode = new ushort[ModualPoll.byX66cRelayRegNumber];
}
} }
} }
} }
......
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
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