Commit 1dfb305f authored by leon.huang's avatar leon.huang

add modbus poll all modual

parent 0b293b14
......@@ -233,7 +233,6 @@ namespace ModbusDemo.windows
public String GetVersion(Byte slaveid)
{
int ret;
String version = "0.0";
String ip = "127.0.0.1";
UInt16[] buf = new ushort[2];
......@@ -247,6 +246,5 @@ namespace ModbusDemo.windows
}
return version;
}
}
}
This diff is collapsed.
......@@ -98,6 +98,8 @@
<Compile Include="Modular\478C.cs" />
<Compile Include="Modular\418X.cs" />
<Compile Include="Common\Modbuslib.cs" />
<Compile Include="Modular\ModualPoll.cs" />
<Compile Include="Modular\modual.cs" />
<Compile Include="windows\Form1.cs">
<SubType>Form</SubType>
</Compile>
......
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using ModbusDemo.MessageFormat;
namespace ModbusDemo.Modular
{
class ModualPoll
{
const byte byX14pNumber = 3;
const byte byX14pReadDataStartAddress = 0;
const byte byX14pReadDataNumber = 4;
const byte byX14pReadTypeStartAddress = 10;
const byte byX14pReadTypeNumber = 4;
static byte[] byX14pIdlist = {17,28,29};
modual.pcx14P cx14P = new modual.pcx14P(byX14pIdlist);
_414P c14formulasormual = new _414P();
const byte byX18xNumber = 6;
const byte byX18xReadDataStartAddress = 0;
const byte byX18xReadDataNumber = 8;
const byte byX18xReadTypeStartAddress = 10;
const byte byX18xReadTypeNumber = 8;
static byte[] byX18xIdlist = {12,13,21,25,45,53};
static modual.eX18xSensorChannelType[,] sX18xChannelType = new modual.eX18xSensorChannelType[byX18xNumber,byX18xReadDataNumber]{{modual.eX18xSensorChannelType.Normal,modual.eX18xSensorChannelType.Normal,modual.eX18xSensorChannelType.Normal,modual.eX18xSensorChannelType.Normal,modual.eX18xSensorChannelType.Normal,modual.eX18xSensorChannelType.Normal,modual.eX18xSensorChannelType.Normal,modual.eX18xSensorChannelType.Normal},
{modual.eX18xSensorChannelType.Normal,modual.eX18xSensorChannelType.Normal,modual.eX18xSensorChannelType.Normal,modual.eX18xSensorChannelType.Normal,modual.eX18xSensorChannelType.Normal,modual.eX18xSensorChannelType.Normal,modual.eX18xSensorChannelType.Normal,modual.eX18xSensorChannelType.Normal},
{modual.eX18xSensorChannelType.Normal,modual.eX18xSensorChannelType.Normal,modual.eX18xSensorChannelType.Normal,modual.eX18xSensorChannelType.Normal,modual.eX18xSensorChannelType.Normal,modual.eX18xSensorChannelType.Normal,modual.eX18xSensorChannelType.Normal,modual.eX18xSensorChannelType.Normal},
{modual.eX18xSensorChannelType.Normal,modual.eX18xSensorChannelType.Normal,modual.eX18xSensorChannelType.Normal,modual.eX18xSensorChannelType.Normal,modual.eX18xSensorChannelType.Normal,modual.eX18xSensorChannelType.Normal,modual.eX18xSensorChannelType.Normal,modual.eX18xSensorChannelType.Normal},
{modual.eX18xSensorChannelType.Normal,modual.eX18xSensorChannelType.Normal,modual.eX18xSensorChannelType.Normal,modual.eX18xSensorChannelType.Normal,modual.eX18xSensorChannelType.Normal,modual.eX18xSensorChannelType.Normal,modual.eX18xSensorChannelType.Normal,modual.eX18xSensorChannelType.Normal},
{modual.eX18xSensorChannelType.Normal,modual.eX18xSensorChannelType.Normal,modual.eX18xSensorChannelType.Normal,modual.eX18xSensorChannelType.Normal,modual.eX18xSensorChannelType.Normal,modual.eX18xSensorChannelType.Normal,modual.eX18xSensorChannelType.Normal,modual.eX18xSensorChannelType.Normal}};
modual.pcx18X cx18x = new modual.pcx18X(byX18xIdlist, sX18xChannelType);
_418X c18xformulasormual= new _418X();
const byte byX78cNumber = 6;
const byte byX78cInputRegStartAddress = 0;
const byte byX78cInputRegNumber = 8;
const byte byX78cOutputRegStartAddress = 16;
const byte byX78cOutputRegNumber = 8;
static byte[] byX78cIdlist = {11,20,33,34,55,56};
modual.pcx78C cx78c = new modual.pcx78C(byX78cIdlist);
const byte byX66cNumber = 32;
const byte byX66cRelayRegStartAddress = 16;
const byte byX66cRelayRegNumber = 6;
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};
modual.pcx66C cx66c = new modual.pcx66C(byX66cIdlist);
void vAllNodePoll()
{
for (byte i = 0; i < byX14pNumber; i++)
{
string[][] sTempString = new string[byX14pNumber][];
ModbusComm.Modbus_ReadHoldingRegistersTask(out cx14P.sX14pDataStruct[i].usX14pRegData, cx14P.byModbusID[i], byX14pReadDataStartAddress, byX14pReadDataNumber, out cx14P.ModbusErrorCode[i]);
ModbusComm.Modbus_ReadHoldingRegistersTask(out cx14P.sX14pDataStruct[i].usX14pRegType, cx14P.byModbusID[i], byX14pReadTypeStartAddress, byX14pReadTypeNumber, out cx14P.ModbusErrorCode[i]);
sTempString[i] = c14formulasormual.RtdValue(cx14P.sX14pDataStruct[i].usX14pRegData, cx14P.sX14pDataStruct[i].usX14pRegType);
for (byte j = 0; j < byX14pReadTypeNumber; j++)
{
cx14P.sX14pDataStruct[i].dX14pConvertData[j] = double.Parse(sTempString[i][j]);
}
}
for (byte i = 0; i < byX18xNumber; i++)
{
string[][] sTempString = new string[byX18xNumber][];
ModbusComm.Modbus_ReadHoldingRegistersTask(out cx18x.sX18xDataStruct[i].usRegData, cx18x.byModbusID[i], byX18xReadDataStartAddress, byX18xReadDataNumber, out cx18x.ModbusErrorCode[i]);
ModbusComm.Modbus_ReadHoldingRegistersTask(out cx18x.sX18xDataStruct[i].usTypeData,cx18x.byModbusID[i], byX18xReadTypeStartAddress, byX18xReadTypeNumber, out cx18x.ModbusErrorCode[i]);
sTempString[i] = c18xformulasormual.Value(cx14P.sX14pDataStruct[i].usX14pRegData, cx14P.sX14pDataStruct[i].usX14pRegType);
for (byte j = 0; j < byX18xReadTypeNumber; j++)
{
if(cx18x.sX18xDataStruct[i].eChannelType[j] == modual.eX18xSensorChannelType.Normal)
cx18x.sX18xDataStruct[i].dConvertData[j] = (double.Parse(sTempString[i][j])- 4)/ 16 * 6;
}
}
for (byte i = 0; i < byX78cNumber; i++)
{
ModbusComm.Modbus_ReadCoilsTask(out cx78c.sx78CRegDataStructStatus[i].bInputRegStatus, cx78c.byModbusID[i], byX78cInputRegStartAddress, byX78cInputRegNumber, out cx78c.ModbusErrorCode[i]);
ModbusComm.Modbus_ReadCoilsTask(out cx78c.sx78CRegDataStructStatus[i].bOutPutRegStatus, cx78c.byModbusID[i], byX78cOutputRegStartAddress, byX78cOutputRegNumber, out cx78c.ModbusErrorCode[i]);
}
for (byte i = 0; i < byX66cNumber; i++)
{
ModbusComm.Modbus_ReadCoilsTask(out cx66c.sx78CDatastructStatus[i].bOutPutRegStatus, cx66c.byModbusID[i], byX66cRelayRegStartAddress, byX66cRelayRegNumber, out cx66c.ModbusErrorCode[i]);
}
}
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using ModbusDemo.MessageFormat;
namespace ModbusDemo.Modular
{
class modual
{
public struct psx14p
{
public ushort[] usX14pRegData;
public ushort[] usX14pRegType;
public double[] dX14pConvertData;
}
public class pcx14P
{
public byte[] byModbusID;
public psx14p[] sX14pDataStruct;
public ModbusComm.eModbusErrorCode[] ModbusErrorCode;
public pcx14P(byte[] InitIDlist)
{
this.byModbusID = InitIDlist;
}
}
public enum eX18xSensorChannelType : byte
{
Normal = 0,
Level,
}
public struct psX18x
{
public ushort[] usRegData;
public ushort[] usTypeData;
public eX18xSensorChannelType[] eChannelType;
public double[] dConvertData;
}
public class pcx18X
{
public byte[] byModbusID;
public psX18x[] sX18xDataStruct;
public ModbusComm.eModbusErrorCode[] ModbusErrorCode;
public pcx18X(byte[] InitIDlist, eX18xSensorChannelType[,] eChannnelType)
{
this.byModbusID = InitIDlist;
for (ushort i = 0; i < eChannnelType.GetLength(0); i++)
{
for (ushort j = 0; j < eChannnelType.GetLength(1); j++)
{
this.sX18xDataStruct[i].eChannelType[j] = eChannnelType[i,j];
}
}
}
}
public struct psx78C
{
public bool[] bInputRegStatus;
public bool[] bOutPutRegStatus;
}
public class pcx78C
{
public byte[] byModbusID;
public psx78C[] sx78CRegDataStructStatus;
public ModbusComm.eModbusErrorCode[] ModbusErrorCode;
public pcx78C(byte[] InitIDlist)
{
this.byModbusID = InitIDlist;
}
}
public struct psx66C
{
public bool[] bRegRelayStatus;
}
public class pcx66C
{
public byte[] byModbusID;
public psx78C[] sx78CDatastructStatus;
public ModbusComm.eModbusErrorCode[] ModbusErrorCode;
public pcx66C(byte[] InitIDlist)
{
this.byModbusID = InitIDlist;
}
}
}
}
......@@ -77,26 +77,26 @@ namespace ModbusDemo.application
// }
//}
public class pcPump
{
public double dPumpCurrent;
public double dPumpVoltage;
public bool bPumpStatus;
public bool bPumpHasOpen;
public void vOpen_Pump()
{
//public class pcPump
//{
// public double dPumpCurrent;
// public double dPumpVoltage;
// public bool bPumpStatus;
// public bool bPumpHasOpen;
// public void vOpen_Pump()
// {
}
public void vClose_Pump()
{
// }
// public void vClose_Pump()
// {
}
public void vGet_Pump_Status()
{
// }
// public void vGet_Pump_Status()
// {
}
// }
}
//}
public class pcTemperatureData
......
......@@ -18,7 +18,6 @@ namespace ModbusDemo.application
this.usTypeRegAddress = usSetRegAddress;
}
}
public struct psLevelData
{
public byte byModbusID;
......@@ -31,7 +30,6 @@ namespace ModbusDemo.application
this.usTypeAddressList = usDataTypeRegAddress;
}
}
public struct psBumpOperation
{
public byte byModbusID;
......@@ -44,7 +42,6 @@ namespace ModbusDemo.application
this.bOpenStatus = bInitOPen;
}
}
public struct psPumbData
{
public byte byModbusID;
......@@ -55,7 +52,6 @@ namespace ModbusDemo.application
this.usRegAddList = usInitRegAddressInit;
}
}
public struct psAgitatorOperation
{
public byte byModbusID;
......@@ -68,7 +64,6 @@ namespace ModbusDemo.application
this.bOpenStatus = bInitOPen;
}
}
public struct psAgitatorData
{
public byte byModbusID;
......@@ -147,10 +142,10 @@ namespace ModbusDemo.application
}
public class pcBump
{
private double[] dBumpCurrent = new double[pcPoolInit.PoolBumpCurrentNumber] { pcPoolInit.cPumbCurrent[0].vRead_Pumb_Data()};
public double[] dBumpVoltage = new double[pcPoolInit.PoolBumpVoltageNumber] { pcPoolInit.cPumbVoltage[0].vRead_Pumb_Data()} ;
public bool[] bBumpStatus = new bool[pcPoolInit.PoolBumpOperatNumber];
public bool[] bpcBumpHasOpen = new bool[pcPoolInit.PoolBumpOperatNumber];
private double[] dBumpCurrent = new double[pcPoolInit.PoolBumpCurrentNumber] { pcPoolInit.cPumbCurrent[0].vRead_Pumb_Data()};
public double[] dBumpVoltage = new double[pcPoolInit.PoolBumpVoltageNumber] { pcPoolInit.cPumbVoltage[0].vRead_Pumb_Data()} ;
public bool[] bBumpStatus = new bool[pcPoolInit.PoolBumpOperatNumber];
public bool[] bpcBumpHasOpen = new bool[pcPoolInit.PoolBumpOperatNumber];
public void vOpen_Bump(ushort usPumbNumber)
......@@ -164,7 +159,7 @@ namespace ModbusDemo.application
}
catch (Exception exception)
{
Form1.totxt.Log("Bump Open Operation Error");
Form1.totxt.Log(exception + "Bump Open Operation Error");
throw;
}
}
......@@ -182,7 +177,7 @@ namespace ModbusDemo.application
}
catch (Exception exception)
{
Form1.totxt.Log("Bump Close Operation Error");
Form1.totxt.Log(exception + "Bump Close Operation Error");
throw;
}
}
......@@ -195,21 +190,19 @@ namespace ModbusDemo.application
}
catch (Exception exception)
{
Form1.totxt.Log("Bump Read Status Error");
Form1.totxt.Log(exception + "Bump Read Status Error");
throw;
}
}
}
public class pcAgitator
{
private double[] dAgitatorCurrent = new double[pcPoolInit.PoolAgitatorCurrentNumber] { pcPoolInit.cAgitatorCurrent[0].vRead_Agitator_Data() };
public double[] dAgitatorVoltage = new double[pcPoolInit.PoolAgitatorVoltageNumber] { pcPoolInit.cAgitatorVoltage[0].vRead_Agitator_Data() };
public bool[] bAgitatorStatus = new bool[pcPoolInit.PoolBumpOperatNumber];
public bool[] bAgitatorHasOpen = new bool[pcPoolInit.PoolBumpOperatNumber];
private double[] dAgitatorCurrent = new double[pcPoolInit.PoolAgitatorCurrentNumber] { pcPoolInit.cAgitatorCurrent[0].vRead_Agitator_Data() };
public double[] dAgitatorVoltage = new double[pcPoolInit.PoolAgitatorVoltageNumber] { pcPoolInit.cAgitatorVoltage[0].vRead_Agitator_Data() };
public bool[] bAgitatorStatus = new bool[pcPoolInit.PoolBumpOperatNumber];
public bool[] bAgitatorHasOpen = new bool[pcPoolInit.PoolBumpOperatNumber];
public void vOpen_Bump(ushort usAgitatorNumber)
public void vOpen_Agitator(ushort usAgitatorNumber)
{
try
{
......@@ -220,11 +213,11 @@ namespace ModbusDemo.application
}
catch (Exception exception)
{
Form1.totxt.Log("Agitator Open Operation Error");
Form1.totxt.Log(exception + "Agitator Open Operation Error");
throw;
}
}
public void vClose_Bump(ushort usAgitatorNumber)
public void vClose_Agitator(ushort usAgitatorNumber)
{
try
{
......@@ -238,12 +231,12 @@ namespace ModbusDemo.application
}
catch(Exception exception)
{
Form1.totxt.Log("Agitator Close Operation Error");
Form1.totxt.Log(exception + "Agitator Close Operation Error");
throw;
}
}
public bool[] vGet_Pumb_Status(ushort usAgitatorNumber)
public bool[] vGet_Agitator_Status(ushort usAgitatorNumber)
{
try
{
......@@ -251,13 +244,11 @@ namespace ModbusDemo.application
}
catch (Exception exception)
{
Form1.totxt.Log("Agitator Read Status Error");
Form1.totxt.Log(exception + "Agitator Read Status Error");
throw;
}
}
}
public class pcPool
{
public string ePondName;
......@@ -268,14 +259,13 @@ namespace ModbusDemo.application
public double dMaxTemper;
public double dMinTemper;
public pcPump cPump;
public pcBump cBump;
public pcAgitator cAgitator;
public double dPondCurrentLevel { get => pcPoolInit.Get_Current_Level(); }
public double dPondCurentTemper { get => pcPoolInit.Get_Current_temper(); }
public pcPool(string eInitPondName)
{
this.ePondName = eInitPondName;
}
}
}
......@@ -59,6 +59,8 @@
this.label4 = new System.Windows.Forms.Label();
this.button2 = new System.Windows.Forms.Button();
this.SubscribeBut = new System.Windows.Forms.Button();
this.label5 = new System.Windows.Forms.Label();
this.label6 = new System.Windows.Forms.Label();
this.updateops.SuspendLayout();
this.SuspendLayout();
//
......@@ -327,7 +329,7 @@
//
this.label2.AutoSize = true;
this.label2.Font = new System.Drawing.Font("宋体", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
this.label2.Location = new System.Drawing.Point(44, 492);
this.label2.Location = new System.Drawing.Point(44, 487);
this.label2.Margin = new System.Windows.Forms.Padding(4, 0, 4, 0);
this.label2.Name = "label2";
this.label2.Size = new System.Drawing.Size(69, 20);
......@@ -347,7 +349,7 @@
// label4
//
this.label4.AutoSize = true;
this.label4.Location = new System.Drawing.Point(108, 498);
this.label4.Location = new System.Drawing.Point(108, 492);
this.label4.Margin = new System.Windows.Forms.Padding(4, 0, 4, 0);
this.label4.Name = "label4";
this.label4.Size = new System.Drawing.Size(55, 15);
......@@ -376,11 +378,31 @@
this.SubscribeBut.UseVisualStyleBackColor = true;
this.SubscribeBut.Click += new System.EventHandler(this.SubscribeBut_Click);
//
// label5
//
this.label5.AutoSize = true;
this.label5.Location = new System.Drawing.Point(111, 528);
this.label5.Name = "label5";
this.label5.Size = new System.Drawing.Size(55, 15);
this.label5.TabIndex = 99;
this.label5.Text = "label5";
//
// label6
//
this.label6.AutoSize = true;
this.label6.Location = new System.Drawing.Point(23, 528);
this.label6.Name = "label6";
this.label6.Size = new System.Drawing.Size(82, 15);
this.label6.TabIndex = 100;
this.label6.Text = "超时次数:";
//
// Form1
//
this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 15F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(1184, 672);
this.Controls.Add(this.label6);
this.Controls.Add(this.label5);
this.Controls.Add(this.SubscribeBut);
this.Controls.Add(this.button2);
this.Controls.Add(this.label4);
......@@ -445,5 +467,7 @@
private System.Windows.Forms.Label label4;
private System.Windows.Forms.Button button2;
private System.Windows.Forms.Button SubscribeBut;
private System.Windows.Forms.Label label5;
private System.Windows.Forms.Label label6;
}
}
\ No newline at end of file
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