From 9aed5d7e7b3c7bf09da712e9c272ece401a7acc9 Mon Sep 17 00:00:00 2001 From: QuakeGod <QuakeGod@sina.com> Date: 星期一, 25 十一月 2024 14:51:23 +0800 Subject: [PATCH] add UltraSonic and MultiWireLess --- ComLib/Inc/PLCfunctions.h | 137 ++++++++++++++++++++++++++++++++++----------- 1 files changed, 102 insertions(+), 35 deletions(-) diff --git a/ComLib/Inc/PLCfunctions.h b/ComLib/Inc/PLCfunctions.h index c34a03a..a84c1b4 100644 --- a/ComLib/Inc/PLCfunctions.h +++ b/ComLib/Inc/PLCfunctions.h @@ -10,10 +10,48 @@ #include "GlobalDef.h" #include "KMachine.h" +#if (ENABLE_PLC) + #define TICK_OF_MS (10) //1ms #define TICK_OF_RS (100) //10mS #define TICK_OF_XS (1000) //100mS #define TICK_OF_YS (10000) //1S + +#define TOTAL_WDFS (32) //Total DF Count +#define TOTAL_CurVAL (16) // +#define TOTALTIMERS (64) + +#define PLC_PROGRAM_USE_BANK 1 + +typedef struct tagTimerStat +{ + 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; + +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; #pragma anon_unions @@ -21,14 +59,19 @@ { int bPLCRunning; int nScanCount; + unsigned short WDFs[TOTAL_WDFS]; + unsigned char CurVALs[TOTAL_CurVAL]; + unsigned char CurVAL; + stTimer Timers[TOTALTIMERS]; + unsigned short WT[16]; + + unsigned short WC[16]; + unsigned short EV[KLDataEVCount]; + unsigned short SV[KLDataSVCount]; + unsigned short ProgTrace[256]; }stPLCMem; -extern stPLCMem PLCMem; - -int InitPLC(void); -int StartPLC(void); -int StopPLC(void); enum enPLCOPs { @@ -91,11 +134,14 @@ OP_PAUSE, OP_JP, OP_CALL, + OP_RET, OP_TML = 0xC8, // OP_TMR = 0xDC, // OP_TMX = 0xDD, // OP_TMY = 0xFA, // + + OP_END = 0xFF, }; /* @@ -106,13 +152,13 @@ unsigned short Addr; }stPLCPROG; */ - typedef struct stBinProg1 + typedef struct stBinInstrcn1 { unsigned char nOp; unsigned char nParamType; unsigned short nParamAddr; - }stBinProg1; - typedef struct stBinProg15 + }stBinInstrcn1; + typedef struct stBinInstrcn15 { //??? // unsigned char nOp; @@ -121,8 +167,8 @@ unsigned char nParamType1; unsigned char resvr1; unsigned short resvr2; - }stBinProg15; - typedef struct stBinProg2 + }stBinInstrcn15; + typedef struct stBinInstrcn2 { //???? // unsigned char nOp; @@ -131,8 +177,8 @@ unsigned char nParamType1; unsigned char nParamType2; unsigned short nParamAddr2; - }stBinProg2; - typedef struct stBinProg3 + }stBinInstrcn2; + typedef struct stBinInstrcn3 { //??????? unsigned char nOp; unsigned char nOpNum; @@ -143,28 +189,49 @@ unsigned char resvr1; unsigned char nParamType3; unsigned short nParamAddr3; - }stBinProg3; - - -extern stBinProg1 const prog1[]; -extern int nSizeProg1; - -//extern unsigned char CurVAL; -//extern unsigned char CurVALs[TOTAL_CurVAL]; -//extern unsigned short DFs[TOTAL_WDFS]; - -//extern unsigned short WX[13]; -//extern unsigned short WY[13]; -//extern unsigned short WR[64]; -//extern unsigned short DT[256]; -//extern unsigned short SDT[256]; -//extern const unsigned short bitMasks[16]; -//extern stTimer Timers[TOTALTIMERS]; - -///* + }stBinInstrcn3; -//*/ +typedef struct tagStoredHdr +{ + unsigned short nBlockSign; + unsigned char nBlockType; + unsigned char nSeq; + unsigned short nSize; + unsigned short nCRC2; +}stStoredHdr; + + +/* +typedef struct tagBinProgs +{ + unsigned short nSteps; + unsigned short nOptions; + stBinInstrcn1 BinInstrcns[1]; +}stBinProgs, *pstBinProgs; +*/ +typedef struct tagStoredBinProgs +{ + stStoredHdr StoredHdr; + stBinInstrcn1 BinInstrcns[1]; + +}stStoredBinProgs, *pstStoredBinProgs; + +typedef struct tagStoredAnno +{ + stStoredHdr StoredHdr; + unsigned char Annos[1]; + +}stStoredAnno, *pstStoredAnno; + +//extern stBinInstrcn1 const prog1[]; +//extern int nSizeProg1; +extern stPLCMem PLCMem; + + +int InitPLC(void); +int StartPLC(void); +int StopPLC(void); int InitTimer(int nIndex, int nType); int RunTimer(int nIndex , int SV); @@ -179,9 +246,9 @@ int PushInVal(void); int PopOutVal(void); -int ProcessPLCBinProg(const stBinProg1 * pBinprog, int nSize); -//int ProcessPLCPROG(const stBinProg1 * prog,int nSize); +int ProcessPLCBinProg(const stBinInstrcn1 * pBinProg, int nSize); +//int ProcessPLCPROG(const stBinInstrcn1 * prog,int nSize); - +#endif // (ENABLE_PLC) #endif /* __PLCFUNCTIONS_H__ */ -- Gitblit v1.9.1