/* */ #pragma once #define TYPECOIL 0x00 #define TYPEDATA 0x80 #define TOTAL_WDFS (16) //Total DF Count #define TOTAL_CurVAL (16) // //extern unsigned short X[256]; //extern unsigned short Y[256]; //extern unsigned short R[256]; #define TOTALTIMERS (64) #define TICK_OF_MS (10) //1ms #define TICK_OF_RS (100) //10mS #define TICK_OF_XS (1000) //100mS #define TICK_OF_YS (10000) //1S enum enKLCoilTypes { KLCoilTypeX = 0 | TYPECOIL, //X Input KLCoilTypeY = 1 | TYPECOIL, //Y Output KLCoilTypeR = 2 | TYPECOIL, //R register KLCoilTypeLX = 3 | TYPECOIL, //Link register KLCoilTypeLY = 4 | TYPECOIL, //Link register KLCoilTypeT = 5 | TYPECOIL, //Timer KLCoilTypeC = 6 | TYPECOIL, //Counter KLCoilTypeLR = 7 | TYPECOIL, //Link register KLCoilTypeSR = 8 | TYPECOIL, //Link register KLCoilTypeP = 9 | TYPECOIL, //P register KLCoilTypeE = 10 | TYPECOIL, //E register }; enum enKLDataTypes { KLDataTypeDEC = 0 | TYPEDATA, KLDataTypeHEX = 1 | TYPEDATA, KLDataTypeFloat = 2 | TYPEDATA, KLDataTypeWX = 3 | TYPEDATA, KLDataTypeWY = 4 | TYPEDATA, KLDataTypeWR = 5 | TYPEDATA, KLDataTypeWLX = 6 | TYPEDATA, KLDataTypeWLY = 7 | TYPEDATA, KLDataTypeDT = 8 | TYPEDATA, KLDataTypeSDT = 9 | TYPEDATA, KLDataTypeWSR = 10 | TYPEDATA, KLDataTypeSV = 11 | TYPEDATA, KLDataTypeEV = 12 | TYPEDATA, KLDataTypeLD = 13 | TYPEDATA, KLDataSysCfg = 25 | TYPEDATA, KLDataTypeFlash = 33 | TYPEDATA, KLDataTypeWDT = 41 | TYPEDATA, KLDataTypeKBD = 51 | TYPEDATA, KLDataTypeTest = 254 | TYPEDATA, }; enum enKLDataCounts { KLDataDTCount = 256, KLDataSDTCount = 256, KLDataWXCount = 16, KLDataWYCount = 16, KLDataWRCount = 16, KLDataLDCount = 64, KLDataWLCount = 8, KLCoilXCount = KLDataWXCount * 16, KLCoilYCount = KLDataWYCount * 16, KLCoilRCount = KLDataWRCount * 16, KLCoilTCount = 64, KLCoilCCount = KLCoilTCount, KLDataSVCount = KLCoilTCount, KLDataEVCount = KLCoilTCount, KLCoilLXCount = 128, KLCoilLYCount = 128, KLCoilLRCount = 128, KLCoilSRCount = 128, }; enum enInputFilter { InputFilter_None = 0, InputFilter_1mS = 1, InputFilter_2mS = 2, InputFilter_4mS = 3, InputFilter_8mS = 4, InputFilter_16mS = 5, InputFilter_32mS = 6, InputFilter_64mS = 7, InputFilter_128mS = 8, InputFilter_256mS = 9, }; enum enOutputHold { Output_Hold = 0, Output_Set_0 = 1, Output_Set_1 = 2, }; enum enPortHardType { PortHardType_None = 0, // 空接口,无类型 PortHardType_SOFT = 1, // 软件虚拟接口,可能是隧道等. PortHardType_UART = 2, // 串行接口 PortHardType_RS232 = 3, // 232接口 PortHardType_RS485 = 4, // 485接口 PortHardType_SLP = 5, // 单总线接口 PortHardType_RF = 6, // 无线接口 PortHardType_LORA = 7, // LoRa无线接口 PortHardType_OPTI = 8, // 光纤接口 PortHardType_ETH = 9, // 以太网接口 PortHardType_WIFI = 10, // WiFi接口 PortHardType_BT = 11, // 以太网接口 }; static CString PortHardTypeToStr(int nPortHardType) { static CString s1; switch (nPortHardType) { case PortHardType_None: return _T("NULL"); case PortHardType_SOFT: // = 1, // 软件虚拟接口,可能是隧道等. return _T("Soft"); case PortHardType_UART: // = 2, // 串行接口 return _T("UART"); case PortHardType_RS232: //= 3, // 232接口 return _T("RS232"); case PortHardType_RS485: //= 4, // 485接口 return _T("RS485"); case PortHardType_SLP: //= 5, // 单总线接口 return _T("SLP"); case PortHardType_RF: //= 6, // 无线接口 return _T("RF"); case PortHardType_LORA: //= 7, // LoRa无线接口 return _T("LoRa"); case PortHardType_OPTI: //= 8, // 光纤接口 return _T("Opti"); case PortHardType_ETH: //= 9, // 以太网接口 return _T("ETH"); case PortHardType_WIFI: //= 10, // WiFi接口 return _T("WiFi"); case PortHardType_BT: //= 11, // 以太网接口 return _T("BT"); default: return _T("UNKNOWN"); break; } } enum enPortUseType { PortUse_Default = 0, //默认 PortUse_Console = 1, //控制台接口 PortUse_KLink = 2, //KLink通讯 PortUse_KBus = 3, //KBus通讯 PortUse_KNet = 4, // KNet通讯 PortUse_SLP = 5, // SLP单总线 PortUse_KRF = 6, // 无线通讯 PortUse_ModbusRTU = 7, //Modbus RTU 通讯 PortUse_ModbusTCP = 8, //Modbus TCP 通讯 PortUse_Com = 9, // 计算机通讯 PortUse_Gen = 10, //通用通讯,自由口 }; static CString PortUseTypeToStr(int nPortHardType) { static CString s1; switch (nPortHardType) { case PortUse_Default: // = 0 默认 return _T("NULL"); case PortUse_Console: // = 1, //控制台接口 return _T("终端"); case PortUse_KLink: // = 2, //KLink通讯 return _T("KLink"); case PortUse_KBus: //= 3, // KNet通讯 return _T("KBus"); case PortUse_KNet: //= 4, // 串行接口 return _T("KNet"); case PortHardType_SLP: //= 5, // SLP单总线 return _T("KSLP"); case PortUse_KRF: //= 6, // 无线通讯 return _T("KwRF"); case PortUse_ModbusRTU: //= 7, // Modbus RTU 通讯 return _T("ModbusRTU"); case PortUse_ModbusTCP: //= 8, // Modbus TCP 通讯 return _T("ModbusTCP"); case PortUse_Com: //= 9, // 计算机通讯 return _T(""); case PortUse_Gen: //= 10, // 通用通讯,自由口 return _T("WiFi"); default: return _T("UNKNOWN"); break; } } enum enServiceReqs { ReqNone, ReqInit, ReqReset, ReqStop, ReqRun, ReqBlinkLED, ReqStartDiag, ReqStopDiag, ReqPortChildInfo, ReqPortChnInfo, ReqUpdateFirm, ReqUpdateFirmInfo, ReqTransFirmware, ReqTransCfg, ReqTransProg, ReqTransData, ReqTransBlink, ReqTransChild, ReqTransInfo, ReqTransOutBandData, ReqRead1Bit, ReqWrite1Bit, ReqReadBits, ReqWriteBits, ReqReadData, ReqWriteData, ReqRemoteTran, }; typedef struct tagPortAbility { USHORT ChildList : 1; USHORT AccessChild : 1; USHORT TranProg : 1; USHORT TranCfg : 1; USHORT Diag : 1; USHORT TranOutBandData : 1; USHORT Tunnel : 1; USHORT TranFirmware : 1; USHORT TranBlink : 1; }stPortAbility; // 各端口 互联 通信 typedef int (*CommFuncDef)(int ReqId, int nParam, void* pData, int len1); typedef struct tagPortDef { union { USHORT nPortType; struct { UCHAR nPortHardType; UCHAR nPortUseType; }; }; USHORT ability; //能力, 获取子机信息等。 UCHAR bEnable; UCHAR bRunning; UCHAR StationId; UCHAR bMaster; UCHAR nMaxStations; UCHAR nCurStations; UCHAR nHealth; short PortConfigType; short PortConfigSize; short PortRunStatType; short PortRunStatSize; // CommFuncDef ReqCommFunc; // func2 CommReq; }stPortDef, * pstPortDef; enum enKeventType { EventTypeNone = 0, EventTypePowerUp = 1, EventTypePowerDown = 2, EventTypePowerRecover = 3, EventTypeConnected = 4, EventTypeLostCon = 5, EventTypeSetTime = 6, EventTypeSysCfg = 7, EventTypeProg = 8, EventTypeForce = 9, EventTypeClearEvent = 10, EventType }; typedef struct tagDevPortDef { union { USHORT nPortType; struct { UCHAR nPortHardType; UCHAR nPortUseType; }; }; UCHAR bEnabled; UCHAR bRunning; UCHAR StationID; UCHAR bMaster; UCHAR MaxStations; UCHAR CurStations; UCHAR Health; }stDevPortDef; typedef struct tagDeviceDef { USHORT nDeviceTypeVer; USHORT nProgVer; UCHAR InBitCount; UCHAR OutBitCount; unsigned short nPortCount; stDevPortDef Ports[8]; //最多8个通讯端口 }stDeviceDef; typedef struct tagDeviceInfo // KBus 子机基本信息 { unsigned short DeviceType; // 子机类型 union { unsigned short DeviceVer; // 子机版本 struct { unsigned char DeviceVerMinor; unsigned char DeviceVerMajor; }; }; unsigned char InBitCount; // 输入开关量数量 unsigned char OutBitCount; // 输出开关量数量 unsigned char ExInBitCount; // 扩展的输入开关量数量 unsigned char ExOutBitCount; // 扩展的输出开关量数量 unsigned char DWStartAddr; // 输出数据字数 unsigned char OutDWCount; // 输出数据字数 unsigned char AIWCount; // 输入模拟量通道(字)数 // 16位为一个字(通道) unsigned char AQWCount; // 输出模拟量通道(字)数 // 16位为一个字(通道) // unsigned char AIBits; // 每通道位数 // 16位以下 // unsigned char AQbits; // 每通道位数 // 16位以下 }stDeviceInfo; typedef struct tagInfoBlock // 20 bytes { // USHORT nBlockLenth; USHORT nDeviceTypeVer; //device type x.y // UCHAR nDevierVer; union { USHORT nProgVer; //prog version x.y struct { UCHAR nProgVerMinor; UCHAR nProgVerMajor; }; }; USHORT nKLinkVer; //x.y USHORT nKBusVer; //x.y // USHORT nKNetVer; //x.y // USHORT nKWLVer; //x.y UCHAR nCapacity1; // ? K UCHAR nCapacity2; // ? k UCHAR nDInput; UCHAR nDOutput; UCHAR nAInput; UCHAR nAOutput; UCHAR nHInput; UCHAR nHOutput; UCHAR nExt1; UCHAR nExt2; UCHAR nLogSize; UCHAR nPorts; UCHAR nManSize; UCHAR nAbility; UCHAR nSwitchBits; }stKMInfoBlock, *pKMInfoBlock; typedef struct tagFactoryData //¹¤³§Á¿²ú²ÎÊý£¬Êý¾Ý { USHORT Sign1; USHORT Seq1; USHORT nModelNo; USHORT nModelVer; UINT nLotNo; UINT nProductDateTime; UINT SN1; UINT nProtocalVer; UINT nDefaultFunc; UCHAR ModelStr[16]; UCHAR LOT_NO[16]; // UCHAR SNStr[16]; unsigned short CRC1; unsigned short EndSign1; }stFactoryData, *pFactoryData; typedef struct tagNewAppInfoBlock { unsigned short Sign; unsigned short Version; unsigned int Length; unsigned int nCRC; }stNewAppInfoBlock, * pNewAppInfoBlock; typedef struct tagKMFuncParam { USHORT EnablePLC : 1; //使能内部PLC功能 USHORT RunMode; //工作模式 }stKMFuncParam; //输入输出地址映射 typedef struct tagAddrMapping { USHORT InputAddr; USHORT OutputAddr; USHORT WRAddr; USHORT DTAddr; }stAddrMapping; typedef struct tagComPortParam //4 Bytes { USHORT WorkMode; /* 0-5=Default,KLink,KBus,KNet,RTU,Com,Gen */ USHORT Station; /* 0=From jumper */ USHORT BaudRate; /* =*100 Baudrate at which running */ USHORT ByteSize : 2; /* 0-1=Number of bits/byte, 7-8 */ USHORT Parity : 4; /* 0-4=None,Odd,Even,Mark,Space */ USHORT StopBits : 2; /* 0,1,2 = 1, 1.5, 2 */ USHORT EndType : 2; /* 0=ByChar, 1= ByTime */ USHORT EofChar : 4; /* 0,1,2 = None, CR, CR+LF, ETX; End of character */ USHORT SofChar : 2; /* 0,1,2 = None, STX */ USHORT EndTime; /*(*0.01mS) */ USHORT RecvAddr; USHORT RecvSize; }stComPortParam, *pstComPortParam; typedef struct tagInputFilterParam { BYTE Filter0 : 4; BYTE Filter1 : 4; }stInputFilterParam; typedef struct tagOutputHoldParam { BYTE Hold1 : 4; BYTE Hold2 : 4; }stOutputHoldParam; // 硬件描述文件 typedef struct tagOutMapping { USHORT bitPos : 4; USHORT byteAddr : 8; USHORT type : 4; }stOutMapping; typedef struct tagCfgBlockInfo { UCHAR nBlockType; UCHAR nBlockSize; }stCfgBlockInfo; //#pragma pack(2) typedef struct tagKMSysCfg //120 Bytes total { USHORT Version; // SC0 // 2 Bytes USHORT workmode; // SC1 // 2 Bytes 0=From jumper USHORT SwitchFunc; // SC2 // 2 Bytes USHORT nCfgBlockCount; // 2 Bytes stComPortParam PortParams[2]; // 8 Bytes stInputFilterParam InputParams[16]; //16 Bytes stOutputHoldParam OutputParams[16]; //16 Bytes union { USHORT value; //12 Bytes //输出映射 struct { USHORT bitPos : 4; USHORT byteAddr : 8; USHORT type : 4; }; }OutMappings[8]; USHORT nProgBank; USHORT nProgSize; USHORT nAnnoSize; USHORT nCount; stCfgBlockInfo CfgBlockInfos[8]; UINT cfgvar8; // 4 Bytes UINT cfgvar9; // 4 Bytes UINT cfgvar10; // 4 Bytes // UINT cfgvar11; // 4 Bytes // UINT cfgvar12; // 4 Bytes // UINT cfgvar13; // 4 Bytes // UINT cfgvar14; // 4 Bytes // UINT cfgvar15; // 4 Bytes // UINT cfgvar16; // 4 Bytes // UINT Space1[4]; //16 Bytes }stKMSysCfg, * pstKMSysCfg; typedef struct tagStoredKMSysCfg { unsigned short Sign1; unsigned short Seq1; stKMSysCfg theKMSysCfg; unsigned short CRC1; unsigned short EndSign1; }stStoredKMSysCfg, * pStoredKMSysCfg; typedef struct tagTimer { unsigned int LastActTime; union { unsigned short StatByte; struct { unsigned short nScale : 2; //Time Scale, 0:1ms 1:10ms 2:100ms 3:1S unsigned short nType : 1; //0 : timer 1 : counter ; unsigned short nDir : 1; //0 : count down. 1 count up; unsigned short nInited : 1; unsigned short bSet : 1; unsigned short bTon : 1; }; // stTimerStat Stat; }; }stTimer; typedef struct tagKMem { unsigned short WDFs[TOTAL_WDFS]; unsigned char CurVALs[TOTAL_CurVAL]; unsigned char CurVAL; stTimer Timers[TOTALTIMERS]; unsigned short WX[KLDataWXCount]; // unsigned short WY[KLDataWYCount]; // unsigned short WR[KLDataWRCount]; unsigned short WT[16]; unsigned short WC[16]; unsigned short EV[KLDataEVCount]; unsigned short SV[KLDataSVCount]; unsigned short WLX[16]; // unsigned short WLY[16]; unsigned short WLR[16]; unsigned short WSR[16]; unsigned short DT[KLDataDTCount]; union { unsigned int SDD[KLDataSDTCount / 2]; unsigned short SDT[KLDataSDTCount]; unsigned char SDB[KLDataSDTCount * 2]; struct { unsigned int EffJumperSW; unsigned int CurJumperSW; unsigned int haltick; unsigned int nRunCount; unsigned int RunStat; unsigned int ErrStat; unsigned int PwrOnCount; unsigned int ThisRunTime; unsigned int TotalRunTime; unsigned int CurTimeSec; unsigned int PwrFailCount; unsigned int LastPwrFailTime; unsigned int LastScanTime; unsigned int ScanTimeuS; unsigned int MinScanTimeuS; unsigned int MaxScanTimeuS; unsigned int nEventCount; unsigned int nEventMinIndex; unsigned int nEventMaxIndex; unsigned int Rev2[5]; unsigned short ADCValues[20]; }; }; int Reserverd5[1024]; }stKMem; enum enOpType { OP_NONE = 0, OP_NOP = 0, OP_ST = 1, // OP_ST_ = 2, // OP_AN = 3, // OP_AN_ = 4, // OP_OR = 5, // OP_OR_ = 6, // OP_NOT = 7, // OP_ANS = 8, // OP_ORS = 9, // OP_PSHS = 10, // OP_RDS = 11, // OP_POPS = 12, // OP_OUT = 16, // OP_SET = 17, // OP_RESET = 18, // OP_DF = 19, // OP_DF_ = 20, // OP_ST_EQ, // OP_ST_LT, // OP_ST_GT, // OP_ST_LE, // OP_ST_GE, // OP_ST_NE, // OP_AN_EQ, // OP_AN_LT, // OP_AN_GT, OP_AN_LE, OP_AN_GE, OP_AN_NE, OP_OR_EQ, OP_OR_LT, OP_OR_GT, OP_OR_LE, OP_OR_GE, OP_OR_NE, OP_MV = 51, OP_INC = 52, OP_ADD2 = 53, OP_ADD3 = 54, OP_DEC = 55, OP_SUB2 = 56, OP_SUB3 = 57, OP_MUL = 58, OP_DIV = 59, OP_BKMV = 60, OP_COPY = 61, OP_CLR = 62, OP_BRK, OP_PAUSE, OP_JP, OP_CALL, OP_TML = 0xC8, // OP_TMR = 0xDC, // OP_TMX = 0xDD, // OP_TMY = 0xFA, // OP_END = 0xFF, }; typedef struct stBinProg1 { unsigned char nOp; unsigned char nParamType; unsigned short nParamAddr; }stBinProg1; typedef struct stBinProg15 { //定时器 //单参数高级指令 unsigned char nOp; unsigned char nOpNum; unsigned short nParamAddr1; unsigned char nParamType1; unsigned char resvr1; unsigned short resvr2; }stBinProg15; typedef struct stBinProg2 { //比较指令 //双参数高级指令 unsigned char nOp; unsigned char nOpNum; unsigned short nParamAddr1; unsigned char nParamType1; unsigned char nParamType2; unsigned short nParamAddr2; }stBinProg2; typedef struct stBinProg3 { //三参数高级指令 unsigned char nOp; unsigned char nOpNum; unsigned short nParamAddr1; unsigned char nParamType1; unsigned char nParamType2; unsigned short nParamAddr2; unsigned char resvr1; unsigned char nParamType3; unsigned short nParamAddr3; }stBinProg3;