From 61deef5cdf96cbfdd6ad45be49e80d597c00ca65 Mon Sep 17 00:00:00 2001
From: QuakeGod <QuakeGod@sina.com>
Date: 星期二, 24 十二月 2024 08:37:21 +0800
Subject: [PATCH] 2024-12-24

---
 KLink1/KLink.h |  163 +++++++++++++++++++++++++++++++++++++++++++-----------
 1 files changed, 130 insertions(+), 33 deletions(-)

diff --git a/KLink1/KLink.h b/KLink1/KLink.h
index 22c0fb2..313f860 100644
--- a/KLink1/KLink.h
+++ b/KLink1/KLink.h
@@ -23,6 +23,37 @@
 // 此类是从KLink1.dll 导出的
 class KLINK1_API KLink1 {
 
+	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 unsigned char UCHAR;
 	typedef unsigned short USHORT;
@@ -34,9 +65,14 @@
 
 	HvSerialPort1 MySerPort1;
 	int m_bCommParamSet = 0;
-	int m_nPort;
-	int m_nBaudRate;
-	CString m_Settings;
+	int m_nPort=1;
+	int m_nBaudRate=115200;
+	CString m_Settings=_T("8,N,1");
+/*
+	int m_nDefaultPort=1;
+	int m_nDefaultBaudRate=115200;
+	CString m_DefaultSettings=_T("8,N,1");
+*/
 
 #define TYPECOIL 0x00
 #define TYPEDATA 0x80
@@ -103,7 +139,7 @@
 		KL_NOT_SUPPORT,
 	};
 
-	const char * GetErrDescStr(int nErrNo);
+	static const char * GetErrDescStr(int nErrNo);
 
 	enum
 	{
@@ -157,6 +193,10 @@
 		KLCmdStartProgram,
 		KLCmdWriteProgram,
 		KLCmdFinishProgram,
+		KLCmdReadPLCAnno,
+		KLCmdStartPLCAnno,
+		KLCmdWritePLCAnno,
+		KLCmdFinishPLCAnno,
 
 		KLCmdRead1Bit = 0x21,				//ReadSingleBit
 		KLCmdWrite1Bit = 0x22,				//WriteSingleBit
@@ -208,7 +248,13 @@
 		KLCmdMC = 0x70,
 		KLCmdMD,
 		KLCmdMG,
-
+	
+		KLCmdWriteFirmware,
+		KLCmdWriteFirmInfo,
+		KLCmdGetPortInfo,
+		KLCmdGetPortChnInfo,
+		KLCmdGetPortChildInfo,
+		KLCmdPortRemoteReq,
 		KLCmdThrough,
 
 		KLCmdErrRply = 0xEE,				//ERRORReply
@@ -400,34 +446,36 @@
 
 	typedef struct tagChnStat
 	{
-		unsigned int Stat;
-		unsigned int SendPackets;
-		unsigned int RecvPackets;
-		unsigned int LastSentTimeuS;
-		unsigned int LostPackets;
-		unsigned int CtnLstPkts;
-		unsigned int MaxCtnLstPkts;
-		unsigned int NotPkgErr;
-		unsigned int PkgLenErr;
-		unsigned int BCCErr;
-		unsigned int TimeOutErr;
-		unsigned int Delay;
-		unsigned int MaxDelay;
-		unsigned int SendTimeInterval;
+		unsigned short Stat;
+		unsigned short SendPackets;
+		unsigned short RecvPackets;
+		unsigned short LastSentTimeuS;
+		unsigned short LostPackets;
+		unsigned short CtnLstPkts;
+		unsigned short MaxCtnLstPkts;
+		unsigned short NotPkgErr;
+		unsigned short PkgLenErr;
+		unsigned short BCCErr;
+		unsigned short TimeOutErr;
+		unsigned short Delay;
+		unsigned short MaxDelay;
+		unsigned short SendTimeInterval;
 		union
 		{
-			unsigned int ClientDatas[10];
+			unsigned short ClientDatas[10];
 			struct {
-				unsigned int ClientRecvPkts;	//
-				unsigned int ClientSendPkts;	//
-				unsigned int ClientNotPktErr;	//
-				unsigned int ClientMisIdPkts;	//
-				unsigned int ClientPkgLenErr;	//
-				unsigned int ClientBccErr;		//
-				unsigned int ClientTimeOutErr;	//
+				unsigned short ClientRecvPkts;	//
+				unsigned short ClientSendPkts;	//
+				unsigned short ClientNotPktErr;	//
+				unsigned short ClientMisIdPkts;	//
+		//		unsigned int ClientNoEndErr;	//
+				unsigned short ClientPkgLenErr;	//
+				unsigned short ClientBccErr;		//
+				unsigned short ClientTimeOutErr;	//
 			};
 		};
 	} stChnStat, *pChnStat;
+
 	enum enKLDataCounts
 	{
 		KLDataWXCount = 16,
@@ -467,6 +515,18 @@
 			USHORT WY[64];
 			UCHAR WYB[128];
 			UINT WYD[32];
+		};
+		union //tagWLX
+		{
+			USHORT WLX[64];
+			UCHAR WLXB[128];
+			UINT WLXD[32];
+		};
+		union //tagWLY
+		{
+			USHORT WLY[64];
+			UCHAR WLYB[128];
+			UINT WLYD[32];
 		};
 		union //tagDT
 		{
@@ -508,8 +568,21 @@
 			unsigned short WDT[KLDataWDTCount];
 			unsigned char WDB[KLDataWDTCount * 2];
 		};
+		union
+		{
+			UCHAR KBDB[2048];
+			USHORT KBDT[1024];
+			UINT KBDD[512];
+		};
+		union {
+			UCHAR KWLB[256];
+			USHORT KWLT[128];
+			UINT KWLD[64];
+		};
+
 	}MEM;
 
+	
 	CString m_resultStr;
 
 	static int xtoi(const char * hexstr, int len = 0);
@@ -596,6 +669,9 @@
 	int Connect(int ConnectParam = 0);
 	int DisConnect(int DisConnectParam = 0);
 	
+	int GotoCmdMode(int Param = 0);
+	int ExitCmdMode(int Param = 0);
+
 	int DoHeartBeat(int nParam = 0);
 
 	void OnTimer();
@@ -610,6 +686,7 @@
 	//int MakeReqPacket(void * pBuf, UCHAR nDst, UCHAR Stat, UCHAR nCMD, UCHAR Type, USHORT nAddr = 0, USHORT nCount = 0, void * pData = NULL);
 
 	int MakeReqPacketEx(void * pBuf, UCHAR nDst, UCHAR Stat, UCHAR nCMD, UCHAR Type, USHORT nAddr = 0, USHORT nCount = 0, void * pData = NULL, int ExtFrameLen = 0, void * pExtDataFrame = NULL);
+	int MakeRemoteReqPacketEx(void* pBuf, UCHAR nDst, UCHAR Stat, UCHAR nPort, UCHAR nChildId, UCHAR nCMD, UCHAR Param1, USHORT nAddr = 0, USHORT nCount = 0, void* pData = NULL, int ExtFrameLen = 0, void* pExtDataFrame = NULL);
 
 	int CheckPackage(void * pBuf, int nSize);
 	int ProcessPacket(void *pBuf, int nLen);
@@ -621,8 +698,8 @@
 	int ReadFactoryData(UCHAR nDst, USHORT nStartAddr, UCHAR nByteCount, USHORT * nReadBytes, USHORT * Values);
 	int WriteFactoryData(UCHAR nDst, USHORT nStartAddr, UCHAR nByteCount, USHORT * Values);
 
-	int ReadSysCfgData(UCHAR nDst, USHORT nStartAddr, UCHAR nByteCount, USHORT * nReadBytes, USHORT * Values);
-	int WriteSysCfgData(UCHAR nDst, USHORT nStartAddr, UCHAR nByteCount, USHORT * Values);
+	int ReadSysCfgData(UCHAR nDst, UCHAR nType, USHORT nStartAddr, UCHAR nByteCount, USHORT * nReadBytes, USHORT * Values);
+	int WriteSysCfgData(UCHAR nDst, UCHAR nType, USHORT nStartAddr, UCHAR nByteCount, USHORT * Values);
 
 
 	//int GetTime32(UCHAR nDst, int * nCount);
@@ -656,15 +733,35 @@
 
 	int BlinkLED(UCHAR nDst, UCHAR nSecond);
 
-	int ReadProgram(UCHAR nDst, UCHAR nType, USHORT nWordAddr, UCHAR nWordCount, USHORT * Values);
+	int ReadPLCProgram(UCHAR nDst, UCHAR nType, USHORT nWordAddr, UCHAR nWordCount, USHORT * Values);
+	int StartDownloadPLCProgram(UCHAR nDst, UCHAR nType, USHORT nProgBytes,USHORT nCRC = 0);
+	int DownloadPLCProgram(UCHAR nDst, UCHAR nType, USHORT nByteAddr, UCHAR nByteCount, USHORT * Values);
+	int FinishDownloadPLCProgram(UCHAR nDst, UCHAR nType, USHORT nProgSteps, USHORT nCRC = 0);
 
-	int StartProgram(UCHAR nDst, UCHAR nType);
-	int WriteProgram(UCHAR nDst, UCHAR nType, USHORT nWordAddr, UCHAR nWordCount, USHORT * Values);
-	int FinishProgram(UCHAR nDst, UCHAR nType, USHORT nStepSize);
+	int ReadPLCAnno(UCHAR nDst, UCHAR nType, USHORT nByteAddr, UCHAR nByteCount, UCHAR* Values);
+	int StartDownloadPLCAnno(UCHAR nDst, UCHAR nType, USHORT nBytes, USHORT nCRC = 0);
+	int DownloadPLCAnno(UCHAR nDst, UCHAR nType, USHORT nByteAddr, UCHAR nByteCount, UCHAR* Values);
+	int FinishDownloadPLCAnno(UCHAR nDst, UCHAR nType, USHORT nByteSize, USHORT nCRC = 0);
+
 
 	int ReadRunStat(UCHAR nDst, UCHAR nType, USHORT nWordAddr, UCHAR nWordCount, USHORT * Values);
 
+
 	int ClearStatistics(UCHAR nDst, UCHAR nType);
 
+	int ResetDevice(UCHAR nDst, UCHAR nType);
+
+	int WriteFirmware(UCHAR nDst, UCHAR nType, USHORT nByteAddr, UCHAR nByteCount, UCHAR* Values);
+	int WriteFirmInfo(UCHAR nDst, UCHAR nType, USHORT nByteAddr, UCHAR nByteCount, UCHAR* Values);
+
+	int GetPortInfo(UCHAR nDst, UCHAR nType, UCHAR nByteCount, USHORT* nByteRead, USHORT* Values);
+
+	int GetPortChildInfo(UCHAR nDst, UCHAR nType, UCHAR nChildId, UCHAR nByteCount, USHORT* nByteRead, USHORT* Values);
+	int GetPortChnInfo(UCHAR nDst, UCHAR nType, UCHAR nChnId, UCHAR nByteCount, USHORT* nByteRead, USHORT* Values);
+
+	int RunRemoteReq(UCHAR nDst, UCHAR nPort, UCHAR nChnId, UCHAR nReqId, UCHAR nParam, USHORT nByteAddr = 0, UCHAR nByteCount =0 ,void * pData = 0);
+
+	int RmoteBlinkLED(UCHAR nDst, UCHAR nPort, UCHAR nChnId, UCHAR nSecond);
+
 };
 

--
Gitblit v1.9.1