773 lines
22 KiB
C#
773 lines
22 KiB
C#
using System;
|
||
using System.Collections.Generic;
|
||
using System.Linq;
|
||
using System.Text;
|
||
using System.Runtime.InteropServices;
|
||
using System.Windows.Forms;
|
||
using static DevExpress.Utils.MVVM.Internal.ILReader;
|
||
|
||
namespace LFP_Manager.DataStructure
|
||
{
|
||
public class CommConfig
|
||
{
|
||
public int CommType;
|
||
|
||
public string SnmpIP;
|
||
public int SnmpModelIndex;
|
||
public int ModuleQty;
|
||
public int RecvWaitTime;
|
||
|
||
public int CanDevice;
|
||
public int CanIndex;
|
||
public int CanNo;
|
||
public int CanBaudrate;
|
||
public int CanModelIndex;
|
||
|
||
public string UartPort;
|
||
public int UartBaudrate;
|
||
public int UartModelIndex;
|
||
public int UartProtocol;
|
||
|
||
public int DbLogPeriod;
|
||
|
||
public int RealTimeChartMaxCount;
|
||
|
||
public int GyroSensitive;
|
||
|
||
public string EnablePassword;
|
||
public string DisablePassword;
|
||
}
|
||
|
||
public class TMinMax
|
||
{
|
||
public short value;
|
||
public short num;
|
||
}
|
||
|
||
public class DeviceSystemTotalData
|
||
{
|
||
public bool CommFail;
|
||
|
||
public DeviceSystemIdent IdentData;
|
||
public DeviceValueTotalData ValueData;
|
||
public DeviceStatusTotalData StatusData;
|
||
|
||
public DeviceSystemTotalData()
|
||
{
|
||
IdentData = new DeviceSystemIdent();
|
||
ValueData = new DeviceValueTotalData();
|
||
StatusData = new DeviceStatusTotalData();
|
||
}
|
||
}
|
||
|
||
public class DeviceSystemIdent
|
||
{
|
||
public string Manufacturer;
|
||
public string DeviceModel;
|
||
//public int ModuleQuantity;
|
||
|
||
public byte[] fw_ver;
|
||
public string FwVerStr;
|
||
|
||
public int AlarmOutputMode;
|
||
|
||
public UInt32 ManufactureDate;
|
||
public string SerialNumber;
|
||
|
||
public DeviceSystemIdent()
|
||
{
|
||
Manufacturer = "";
|
||
DeviceModel = "";
|
||
//ModuleQuantity = 1;
|
||
|
||
fw_ver = new byte[4];
|
||
FwVerStr = "";
|
||
|
||
AlarmOutputMode = 0;
|
||
ManufactureDate = 0;
|
||
SerialNumber = "";
|
||
}
|
||
}
|
||
|
||
public class DeviceSystemData
|
||
{
|
||
public int mNo;
|
||
public int cellQty;
|
||
public int tempQty;
|
||
public int ChargeVoltage;
|
||
public int DOD;
|
||
public int MaxChaCurrent;
|
||
public int MaxDchCurrent;
|
||
|
||
public UInt32 heatbeat;
|
||
public bool CommFail;
|
||
public bool ShelfCommFail;
|
||
public DateTime LastRxTime;
|
||
public Int32 BmsDateTimeInt;
|
||
public ushort BmsDateTimeShort1;
|
||
public ushort BmsDateTimeShort2;
|
||
public DateTime BmsDateTime;
|
||
|
||
public DeviceValueData ValueData;
|
||
public DeviceAvgData AvgData;
|
||
public DeviceStatusData StatusData;
|
||
public DeviceParamData ParamData;
|
||
public DeviceCalibration CalibriationData;
|
||
public DeviceInforation Information;
|
||
public DeviceEtcStatus EtcStatus;
|
||
|
||
public DeviceSystemData()
|
||
{
|
||
mNo = 0;
|
||
cellQty = 15;
|
||
tempQty = 4;
|
||
ChargeVoltage = 0;
|
||
DOD = 0;
|
||
MaxChaCurrent = 0;
|
||
MaxDchCurrent = 0;
|
||
|
||
heatbeat = 0;
|
||
CommFail = false;
|
||
ShelfCommFail = false;
|
||
LastRxTime = DateTime.MinValue;
|
||
BmsDateTimeInt = 0;
|
||
BmsDateTime = DateTime.MinValue;
|
||
|
||
ValueData = new DeviceValueData();
|
||
AvgData = new DeviceAvgData();
|
||
StatusData = new DeviceStatusData();
|
||
ParamData = new DeviceParamData();
|
||
CalibriationData = new DeviceCalibration();
|
||
Information = new DeviceInforation();
|
||
EtcStatus = new DeviceEtcStatus();
|
||
}
|
||
}
|
||
|
||
public class DeviceValueTotalData
|
||
{
|
||
public short TotalVoltage;
|
||
public short TotalCurrent;
|
||
public short TotalSOC;
|
||
public short TotalSOH;
|
||
public short TotalTemp;
|
||
|
||
public DeviceValueTotalData()
|
||
{
|
||
TotalVoltage = 0;
|
||
TotalCurrent = 0;
|
||
TotalSOC = 0;
|
||
TotalSOH = 0;
|
||
TotalTemp = 0;
|
||
}
|
||
}
|
||
|
||
public class DeviceValueData
|
||
{
|
||
public byte[] fw_ver;
|
||
|
||
public short voltageOfPack;
|
||
public short current;
|
||
public short cha_current;
|
||
public short dch_current;
|
||
public short averageCurrent;
|
||
public short rSOC;
|
||
|
||
public ushort[] CellVoltage;
|
||
public short[] CellTemperature;
|
||
|
||
public short Ext1Temperature;
|
||
public short Ext2Temperature;
|
||
|
||
public short remainingCapacity;
|
||
public short stateOfHealth;
|
||
public int cycleCount;
|
||
public int fullChargeCapacity;
|
||
public int designedCapacity;
|
||
|
||
public int TimeLeft;
|
||
|
||
public int Ah_Charged;
|
||
public int Ah_Discharged;
|
||
public int NoOfDischargeCycles;
|
||
public int NoOfChargeCycles;
|
||
|
||
public int ModuleAlarms;
|
||
public int ModuleWarnings;
|
||
public int ModuleStatus;
|
||
public int ModuleVoltage_int;
|
||
public int ModBusDocVersion;
|
||
|
||
public int ParametersChanged;
|
||
public int MaxBattChargeCurr;
|
||
public int MaxBattDischargeCurr;
|
||
|
||
public int BatteryProdDateYear;
|
||
public int BatteryProdDateMonth;
|
||
public int BatteryProdDateDay;
|
||
|
||
public int BatteryModelDescription;
|
||
public int BatteryType;
|
||
|
||
public DeviceValueData()
|
||
{
|
||
fw_ver = new byte[6];
|
||
|
||
CellVoltage = new ushort[csConstData.SystemInfo.MAX_MODULE_CELL_SIZE];
|
||
CellTemperature = new short[csConstData.SystemInfo.MAX_MODULE_TEMP_SIZE];
|
||
}
|
||
}
|
||
|
||
public class DeviceAvgData
|
||
{
|
||
public short maxCellVoltage;
|
||
public short minCellVoltage;
|
||
public short avgCellVoltage;
|
||
public short diffCellVoltage;
|
||
public short maxCellNum;
|
||
public short minCellNum;
|
||
public short maxTemp;
|
||
public short minTemp;
|
||
public short avgTemp;
|
||
public short diffTemp;
|
||
public short maxTempNum;
|
||
public short minTempNum;
|
||
|
||
public DeviceAvgData()
|
||
{
|
||
|
||
}
|
||
}
|
||
|
||
public class DeviceStatusTotalData
|
||
{
|
||
public short batteryStatus;
|
||
public short warning;
|
||
public short protection;
|
||
public short errorCode;
|
||
public short status;
|
||
}
|
||
|
||
public class DeviceStatusData
|
||
{
|
||
public short batteryStatus;
|
||
public short batteryStatus1;
|
||
public short warning;
|
||
public short protection;
|
||
public short protection1;
|
||
public short errorCode;
|
||
public short status;
|
||
public short relayStatus;
|
||
public short cellBallanceStatus;
|
||
public short cellBalanceValue;
|
||
public short cellBalanceFlag;
|
||
}
|
||
|
||
public class DeviceCommStatus
|
||
{
|
||
public DateTime LastRxTime;
|
||
public bool CommFail;
|
||
}
|
||
|
||
public class DeviceParamData
|
||
{
|
||
public short CellOverVoltageTrip;
|
||
public short CellOverVoltageWarning;
|
||
public short CellOverVoltageRelease;
|
||
public short CellUnderVoltageTrip;
|
||
public short CellUnderVoltageWarning;
|
||
public short CellUnderVoltageRelease;
|
||
|
||
public short SysOverVoltageTrip;
|
||
public short SysOverVoltageWarning;
|
||
public short SysOverVoltageRelease;
|
||
public short SysUnderVoltageTrip;
|
||
public short SysUnderVoltageWarning;
|
||
public short SysUnderVoltageRelease;
|
||
|
||
public short ChaHighTempTrip;
|
||
public short ChaHighTempWarning;
|
||
public short ChaHighTempRelease;
|
||
public short ChaLowTempTrip;
|
||
public short ChaLowTempWarning;
|
||
public short ChaLowTempRelease;
|
||
public short DchHighTempTrip;
|
||
public short DchHighTempWarning;
|
||
public short DchHighTempRelease;
|
||
public short DchLowTempTrip;
|
||
public short DchLowTempWarning;
|
||
public short DchLowTempRelease;
|
||
|
||
public short ChaOverCurrentTrip1;
|
||
public short ChaOverCurrentTrip2;
|
||
public short ChaOverCurrentWarning;
|
||
public short ChaOverCurrentReleaseTime;
|
||
public short ChaOverCurrentTimes;
|
||
public short ChaOverCurrentDelay1;
|
||
public short ChaOverCurrentDelay2;
|
||
|
||
public short DchOverCurrentTrip1;
|
||
public short DchOverCurrentTrip2;
|
||
public short DchOverCurrentWarning;
|
||
public short DchOverCurrentReleaseTime;
|
||
public short DchOverCurrentTimes;
|
||
public short DchOverCurrentDelay1;
|
||
public short DchOverCurrentDelay2;
|
||
|
||
public short PcbHighTempTrip;
|
||
public short PcbHighTempWarning;
|
||
public short PcbHighTempRelease;
|
||
|
||
public short ShortCircuit;
|
||
|
||
public short LowSocTrip;
|
||
public short LowSocWarning;
|
||
public short LowSocRelease;
|
||
|
||
public short CellVoltageDifferenceTrip;
|
||
public short CellVoltageDifferenceWarning;
|
||
public short CellVoltageDifferenceRelease;
|
||
public short CellVoltageDifferenceTime;
|
||
|
||
public short DefalutParamOption;
|
||
public short DefalutParamAll;
|
||
public ushort ReadParamAll;
|
||
|
||
public DeviceParamData DeepCopy()
|
||
{
|
||
DeviceParamData newCopy = new DeviceParamData
|
||
{
|
||
CellOverVoltageTrip = CellOverVoltageTrip,
|
||
CellOverVoltageWarning = CellOverVoltageWarning,
|
||
CellOverVoltageRelease = CellOverVoltageRelease,
|
||
CellUnderVoltageTrip = CellUnderVoltageTrip,
|
||
CellUnderVoltageWarning = CellUnderVoltageWarning,
|
||
CellUnderVoltageRelease = CellUnderVoltageRelease,
|
||
|
||
SysOverVoltageTrip = SysOverVoltageTrip,
|
||
SysOverVoltageWarning = SysOverVoltageWarning,
|
||
SysOverVoltageRelease = SysOverVoltageRelease,
|
||
SysUnderVoltageTrip = SysUnderVoltageTrip,
|
||
SysUnderVoltageWarning = SysUnderVoltageWarning,
|
||
SysUnderVoltageRelease = SysUnderVoltageRelease,
|
||
|
||
ChaHighTempTrip = ChaHighTempTrip,
|
||
ChaHighTempWarning = ChaHighTempWarning,
|
||
ChaHighTempRelease = ChaHighTempRelease,
|
||
ChaLowTempTrip = ChaLowTempTrip,
|
||
ChaLowTempWarning = ChaLowTempWarning,
|
||
ChaLowTempRelease = ChaLowTempRelease,
|
||
DchHighTempTrip = DchHighTempTrip,
|
||
DchHighTempWarning = DchHighTempWarning,
|
||
DchHighTempRelease = DchHighTempRelease,
|
||
DchLowTempTrip = DchLowTempTrip,
|
||
DchLowTempWarning = DchLowTempWarning,
|
||
DchLowTempRelease = DchLowTempRelease,
|
||
|
||
ChaOverCurrentTrip1 = ChaOverCurrentTrip1,
|
||
ChaOverCurrentTrip2 = ChaOverCurrentTrip2,
|
||
ChaOverCurrentWarning = ChaOverCurrentWarning,
|
||
ChaOverCurrentReleaseTime = ChaOverCurrentReleaseTime,
|
||
ChaOverCurrentTimes = ChaOverCurrentTimes,
|
||
ChaOverCurrentDelay1 = ChaOverCurrentDelay1,
|
||
ChaOverCurrentDelay2 = ChaOverCurrentDelay2,
|
||
|
||
DchOverCurrentTrip1 = DchOverCurrentTrip1,
|
||
DchOverCurrentTrip2 = DchOverCurrentTrip2,
|
||
DchOverCurrentWarning = DchOverCurrentWarning,
|
||
DchOverCurrentReleaseTime = DchOverCurrentReleaseTime,
|
||
DchOverCurrentTimes = DchOverCurrentTimes,
|
||
DchOverCurrentDelay1 = DchOverCurrentDelay1,
|
||
DchOverCurrentDelay2 = DchOverCurrentDelay2,
|
||
|
||
PcbHighTempTrip = PcbHighTempTrip,
|
||
PcbHighTempWarning = PcbHighTempWarning,
|
||
PcbHighTempRelease = PcbHighTempRelease,
|
||
|
||
ShortCircuit = ShortCircuit,
|
||
|
||
LowSocTrip = LowSocTrip,
|
||
LowSocWarning = LowSocWarning,
|
||
LowSocRelease = LowSocRelease,
|
||
|
||
CellVoltageDifferenceTrip = CellVoltageDifferenceTrip,
|
||
CellVoltageDifferenceWarning = CellVoltageDifferenceWarning,
|
||
CellVoltageDifferenceRelease = CellVoltageDifferenceRelease,
|
||
CellVoltageDifferenceTime = CellVoltageDifferenceTime,
|
||
|
||
DefalutParamOption = DefalutParamOption,
|
||
DefalutParamAll = DefalutParamAll,
|
||
ReadParamAll = ReadParamAll,
|
||
};
|
||
return newCopy;
|
||
}
|
||
}
|
||
|
||
public class DeviceCalibration
|
||
{
|
||
public CellVoltageCalib CellVoltge;
|
||
public SystemVoltageCalib SystemVoltage;
|
||
public ForcedBalControl ForcedBalancing;
|
||
public BatteryParameter Battery;
|
||
public CurrentCalib Current;
|
||
public SystemInfor SystemInfo;
|
||
public CapCalibration CapCalib;
|
||
public FetCalibration FetCalib;
|
||
public ChargeMode ChaMode;
|
||
public TAntiTheft AntiTheft;
|
||
public TBmsDateTime BmsDateTime;
|
||
|
||
public DeviceInforation InvData;
|
||
|
||
public DeviceCalibration()
|
||
{
|
||
CellVoltge = new CellVoltageCalib();
|
||
SystemVoltage = new SystemVoltageCalib();
|
||
ForcedBalancing = new ForcedBalControl();
|
||
Battery = new BatteryParameter();
|
||
Current = new CurrentCalib();
|
||
SystemInfo = new SystemInfor();
|
||
CapCalib = new CapCalibration();
|
||
FetCalib = new FetCalibration();
|
||
ChaMode = new ChargeMode();
|
||
AntiTheft = new TAntiTheft();
|
||
BmsDateTime = new TBmsDateTime();
|
||
|
||
InvData = new DeviceInforation();
|
||
}
|
||
public DeviceCalibration DeepCopy()
|
||
{
|
||
DeviceCalibration newCopy = new DeviceCalibration
|
||
{
|
||
CellVoltge = CellVoltge,
|
||
SystemVoltage = SystemVoltage,
|
||
ForcedBalancing = ForcedBalancing,
|
||
Battery = Battery,
|
||
Current = Current,
|
||
SystemInfo = SystemInfo,
|
||
|
||
CapCalib = CapCalib.DeepCopy(),
|
||
AntiTheft = AntiTheft.DeepCopy(),
|
||
FetCalib = FetCalib,
|
||
ChaMode = ChaMode.DeepCopy(),
|
||
};
|
||
return newCopy;
|
||
}
|
||
}
|
||
|
||
public class CellVoltageCalib
|
||
{
|
||
public short CurrentCellNo; // 0: ODD, 1: EVEN
|
||
public short OddCellVoltageCalibration_K;
|
||
public short OddCellVoltageCalibration_B;
|
||
public short EvenCellVoltageCalibration_K;
|
||
public short EvenCellVoltageCalibration_B;
|
||
}
|
||
|
||
public class SystemVoltageCalib
|
||
{
|
||
[MarshalAs(UnmanagedType.I2, SizeConst = 2)]
|
||
public short Calibration_K;
|
||
public short Calibration_B;
|
||
}
|
||
|
||
public class ForcedBalControl
|
||
{
|
||
public short Control;
|
||
public short CellNo;
|
||
public bool AutoB;
|
||
}
|
||
|
||
public class BatteryParameter
|
||
{
|
||
public short CellQty;
|
||
public short TempQty;
|
||
public UInt32 Capacity;
|
||
}
|
||
|
||
public class CurrentCalib
|
||
{
|
||
public short SelectSubItem;
|
||
public short ShuntRange;
|
||
public short CurrentZero;
|
||
public short VoltageZero;
|
||
public Int32 ChgCalibration_K;
|
||
public Int32 DchCalibration_K;
|
||
public short ChaAndDchSelect;
|
||
public short ChargeOption;
|
||
}
|
||
|
||
public class SystemInfor
|
||
{
|
||
//public short Id;
|
||
public DateTime devTime;
|
||
public ushort LastRebootCause;
|
||
}
|
||
|
||
public class CapCalibration
|
||
{
|
||
public int DesignCapacity;
|
||
public int SocValue;
|
||
public int CycleCount;
|
||
|
||
public CapCalibration()
|
||
{
|
||
DesignCapacity = 0;
|
||
SocValue = 0;
|
||
CycleCount = 0;
|
||
}
|
||
public CapCalibration DeepCopy()
|
||
{
|
||
CapCalibration newCopy = new CapCalibration
|
||
{
|
||
DesignCapacity = DesignCapacity,
|
||
SocValue = SocValue,
|
||
CycleCount = CycleCount,
|
||
};
|
||
return newCopy;
|
||
}
|
||
}
|
||
|
||
public class ChargeMode
|
||
{
|
||
public int Mode;
|
||
public int Value;
|
||
|
||
public ChargeMode()
|
||
{
|
||
Mode = 0;
|
||
Value = 0;
|
||
}
|
||
public ChargeMode DeepCopy()
|
||
{
|
||
ChargeMode newCopy = new ChargeMode
|
||
{
|
||
Mode = Mode,
|
||
Value = Value,
|
||
};
|
||
return newCopy;
|
||
}
|
||
}
|
||
public class TAntiTheft
|
||
{
|
||
public int Comm;
|
||
public int GyroScope;
|
||
public int Status;
|
||
|
||
public TAntiTheft()
|
||
{
|
||
Comm = 0;
|
||
GyroScope = 0;
|
||
Status = 0;
|
||
}
|
||
public TAntiTheft DeepCopy()
|
||
{
|
||
TAntiTheft newCopy = new TAntiTheft
|
||
{
|
||
Comm = Comm,
|
||
GyroScope = GyroScope,
|
||
Status = Status,
|
||
};
|
||
return newCopy;
|
||
}
|
||
}
|
||
public class TBmsDateTime
|
||
{
|
||
public string Str;
|
||
public int lValue;
|
||
public short[] sValue;
|
||
|
||
public TBmsDateTime()
|
||
{
|
||
Str = "";
|
||
lValue = 0;
|
||
sValue = new short[2];
|
||
}
|
||
public TBmsDateTime DeepCopy()
|
||
{
|
||
TBmsDateTime newCopy = new TBmsDateTime
|
||
{
|
||
Str = Str,
|
||
lValue = lValue,
|
||
};
|
||
for (int i = 0; i < 2; i++)
|
||
{
|
||
newCopy.sValue[i] = sValue[i];
|
||
}
|
||
return newCopy;
|
||
}
|
||
}
|
||
|
||
public class FetCalibration
|
||
{
|
||
public short FetStatus;
|
||
public short DchFetOff; // 6010
|
||
public short ChaFetOff; // 6011
|
||
public short LmtChaFetOff; // 6012
|
||
public short PreChaFetOn; // 6013
|
||
public short HeaterFetOn; // 6014
|
||
public short ChaFetOn; // 6015
|
||
}
|
||
|
||
public class DeviceInforation
|
||
{
|
||
public UInt32 ManufactureDate;
|
||
public byte[] Model_Byte;
|
||
public byte[] FwVer_Byte;
|
||
public string Model_Str;
|
||
public string FwVer_Str;
|
||
public byte[] BMS_SN;
|
||
public string BMS_SN_Str;
|
||
public byte[] Module_SN;
|
||
|
||
public DeviceInforation()
|
||
{
|
||
Model_Byte = new byte[24];
|
||
FwVer_Byte = new byte[6];
|
||
Model_Str = " ";
|
||
FwVer_Str = " ";
|
||
BMS_SN = new byte[32];
|
||
BMS_SN_Str = " ";
|
||
Module_SN = new byte[32];
|
||
}
|
||
}
|
||
|
||
public class DeviceEtcStatus
|
||
{
|
||
public short SwitchHW;
|
||
public short SwitchWarning;
|
||
public short SwitchProtect;
|
||
public ushort LogDurationIdle; // min
|
||
public ushort LogDurationActive; // min
|
||
public UInt32 DataAndTime;
|
||
public ushort ChgOCPModel; /* 充电限流
|
||
0:不限流保护
|
||
1:始终限流充电
|
||
2:预充保护
|
||
4:充电过流后限流
|
||
8:预充+充电过流后限流 */
|
||
public short ChgLmtVoltage; // mv
|
||
public short SOC_StopFloat; // % 暂停浮充Soc
|
||
public short SOC_RecvFloat; // % 恢复浮充电压
|
||
public short DurationFloat; // sec
|
||
public short DurationIdle; // sec
|
||
public short VoltageStopFloat; // 0.1V
|
||
public short VoltageRecvFloat; // 0.1V
|
||
public short FloatMode; /* 0000: 持续浮充
|
||
0001:检测电压
|
||
0002:定时浮充
|
||
0003:检测SOC */
|
||
public short BalanceVoltage; // mV 均衡启动电压
|
||
public short BalanceDeltaV; // mV 均衡启动压差
|
||
public short WarnLowCapacity; // 低容量告警
|
||
public short HistroyDelete; // 删除数据记录
|
||
}
|
||
|
||
public class TUartTRxData
|
||
{
|
||
public int type;
|
||
public int length;
|
||
public byte[] data;
|
||
|
||
public TUartTRxData()
|
||
{
|
||
type = 0;
|
||
length = 0;
|
||
data = new byte[256];
|
||
}
|
||
public TUartTRxData DeepCopy()
|
||
{
|
||
TUartTRxData newCopy = new TUartTRxData
|
||
{
|
||
type = type,
|
||
length = length,
|
||
data = data
|
||
};
|
||
for (int i = 0; i < data.Length; i++)
|
||
{
|
||
newCopy.data[i] = data[i];
|
||
}
|
||
|
||
return newCopy;
|
||
}
|
||
}
|
||
|
||
public enum UartTxType
|
||
{
|
||
Polling, // 주기적 상태 조회
|
||
WriteParam, // 파라미터 쓰기 (Holding Register)
|
||
WriteReg, // 레지스터 쓰기
|
||
WriteCoil, // 코일 쓰기
|
||
ReadReg, // 레지스터 읽기
|
||
FwUpdate, // 펌웨어 업데이트
|
||
Raw // 기타 원시 패킷
|
||
}
|
||
|
||
public class TUartTxItem
|
||
{
|
||
public UartTxType TxType { get; set; } = UartTxType.Raw;
|
||
public int SystemId { get; set; } = 0;
|
||
public ushort RegAddr { get; set; } = 0;
|
||
public ushort RegLen { get; set; } = 0;
|
||
public byte[] Data { get; set; } = null;
|
||
public bool ExpectReply { get; set; } = true;
|
||
public int TimeoutMs { get; set; } = 500;
|
||
|
||
public TUartTxItem() { }
|
||
|
||
public TUartTxItem(UartTxType type, int sysId, ushort regAddr, ushort regLen, byte[] data, bool expectReply = true, int timeoutMs = 500)
|
||
{
|
||
TxType = type;
|
||
SystemId = sysId;
|
||
RegAddr = regAddr;
|
||
RegLen = regLen;
|
||
Data = data;
|
||
ExpectReply = expectReply;
|
||
TimeoutMs = timeoutMs;
|
||
}
|
||
}
|
||
|
||
public class TUartTxBuff
|
||
{
|
||
public int InPos;
|
||
public int OutPos;
|
||
public TUartTRxData[] Buf;
|
||
public TUartTxBuff()
|
||
{
|
||
InPos = 0;
|
||
OutPos = 0;
|
||
Buf = new TUartTRxData[50];
|
||
for (int i = 0; i < 50; i++)
|
||
{
|
||
Buf[i] = new TUartTRxData();
|
||
}
|
||
}
|
||
|
||
public bool CheckBuff()
|
||
{
|
||
if (InPos != OutPos) { return true; }
|
||
else { return false; }
|
||
}
|
||
public void PutBuff(TUartTRxData UartTxData)
|
||
{
|
||
if (UartTxData != null)
|
||
{
|
||
Buf[InPos++] = UartTxData.DeepCopy();
|
||
InPos %= 50;
|
||
}
|
||
}
|
||
public TUartTRxData GetBuff()
|
||
{
|
||
TUartTRxData result = null;
|
||
|
||
if (InPos != OutPos)
|
||
{
|
||
result = Buf[OutPos++].DeepCopy();
|
||
OutPos %= 50;
|
||
}
|
||
return result;
|
||
}
|
||
}
|
||
|
||
}
|
||
|