電腦COM口數據測試

来源:https://www.cnblogs.com/mycnblogs-lumen/archive/2023/07/08/17537901.html
-Advertisement-
Play Games

電腦COM口數據測試一、基本使用流程 程式需要以管理員身份運行,COM口迴路測試需短接2,3pin,測試時候使用控制台,配置測試相關路徑,併在測試完成後 1.測試配置路徑D:\bigdata\INI\FWCOM.ini 2.測試完成後需要在路徑D:\bigdata\LOG\生成測試FWCOM.lo ...



電腦COM口數據測試
一、基本使用流程

程式需要以管理員身份運行,COM口迴路測試需短接2,3pin,測試時候使用控制台,配置測試相關路徑,併在測試完成後

1.測試配置路徑D:\bigdata\INI\FWCOM.ini

2.測試完成後需要在路徑D:\bigdata\LOG\生成測試FWCOM.log文件

程式運行結果示意圖

運行完成後的日誌文件示意圖

 二、軟體設計
源碼分為三個部分,common.cpp基本基本信息配置,function.cpp完成功能實現,最後通過main.cpp運行整個程式

common.cpp

 

配置函數代碼
#undef UNICODE
#include "common.h"
#include "Config.h"
void TextColor(int color)
{
	HANDLE stdH = GetStdHandle(STD_OUTPUT_HANDLE);
	SetConsoleTextAttribute(stdH, color);
}
void PASS()
{
	printf("The test is: ");

	TextColor(GREEN);
	printf("passed");
	printf("\n");
	printf("\n");
	TextColor(WHITE);

}
void FAIL()
{
	printf("The test is: ");

	TextColor(RED);
	printf("failed");
	printf("\n");
	printf("\n");
	TextColor(WHITE);

}
DWORD SubSystemID(MBTYPE mb[])
{
	DWORD decSubSystemID = 0;
	DWORD aimSubSystemID = 0;
	//	BYTE bus = pciSelect[0], dev = pciSelect[1], func = pciSelect[2], offset = 0x2c;
	BYTE bus = 0;
	BYTE dev = 0;
	BYTE func = 0;
	BYTE offset = 0;
	DWORD address = 0;
	for (int i = 0; i < sizeof(mb); i++)
	{
		//		printf("i = %d\n", i);

		if (mb[i].subSystemId != 0)
		{
			bus = mb[i].bus;
			dev = mb[i].dev;
			func = mb[i].fun;
			offset = mb[i].subSystemIdOffset;
			aimSubSystemID = mb[i].subSystemId;
			address = MAKE_CONFIG_ADDRESS(bus, dev, func, offset);
			FoxLib_SetPortVal(PCI_CONFIG_ADDRESS, address, 4);
			FoxLib_GetPortVal(PCI_CONFIG_DATA, &decSubSystemID, 4);
#ifdef DEBUG
			printf("aimSubSystemID = \"%x\", decSubSystemID = \"%x\"\n", aimSubSystemID, decSubSystemID);
#endif
			if (aimSubSystemID == decSubSystemID)
			{
				return 0;
			}

		}

	}
	printf("Not support MB!\n");
	return 1;
}
void GetGlobalData(char* name)
{
	int i = 0;
	int index = 0;
	int toolSelect = 0;
	if (strstr(name, "hwm") != NULL)
	{
		index = 1;
		for (i = 0; i < cTINumberMax; i++)
		{
			if (cFanName[i][0] != '\0')
			{
				iFanIndex[index] = i;
				index++;
				iAllFanNum++;
			}
		}
		index = 1;
		for (i = 0; i < cTINumberMax; i++)
		{
			if (cTempName[i][0] != '\0')
			{
				iTempIndex[index] = i;

				index++;
				iAllTempNum++;
			}
		}
#ifdef DEBUG
		printf("iAllFanNum = %d, iAllTempNum = %d\n", iAllFanNum, iAllTempNum);
#endif

	}
	else if (strstr(name, "idchk") != NULL)
	{
		index = 1;
		for (i = 0; i < cTINumberMax; i++)
		{
			if (cIdChkName[i][0] != '\0')
			{
				iIdChkIndex[index] = i;
				index++;
				iAllIdChkNum++;
			}
		}
#ifdef DEBUG
		printf("iAllIdChkNum = %d\n", iAllIdChkNum);
#endif

	}
	else if (strstr(name, "pcie") != NULL)
	{
		index = 1;
		for (i = 0; i < cTINumberMax; i++)
		{
			if (cPcieName[i][0] != '\0')
			{
				iPcieIndex[index] = i;
				index++;
				iAllPcieNum++;
			}
		}
#ifdef DEBUG
		printf("iAllPcieNum = %d\n", iAllPcieNum);
#endif

	}
	else if (strstr(name, "sata") != NULL)
	{
		index = 1;
		for (i = 0; i < cTINumberMax; i++)
		{
			if (cSataSpdName[i][0] != '\0')
			{
				iSataSpdIndex[index] = i;
				index++;
				iAllSataSpdNum++;
			}
		}
#ifdef DEBUG
		printf("iAllSataSpdNum = %d\n", iAllSataSpdNum);
#endif

	}
	else if (strstr(name, "fntpnl") != NULL)
	{
		index = 1;
		for (i = 0; i < cTINumberMax; i++)
		{
			if (cFntpnlName[i][0] != '\0')
			{
				iFntpnlIndex[index] = i;
				index++;
				iAllFntpnlNum++;
			}
		}
#ifdef DEBUG
		printf("iAllFntpnlNum = %d\n", iAllFntpnlNum);
#endif

	}
	else if (strstr(name, "jumper") != NULL)
	{
		index = 1;
		for (i = 0; i < cTINumberMax; i++)
		{
			if (cJumperName[i][0] != '\0')
			{
				iJumperIndex[index] = i;
				index++;
				iAllJumperNum++;
			}
		}
#ifdef DEBUG
		printf("iAllJumperNum = %d\n", iAllJumperNum);
#endif

	}

}

int GetDataFromConfig(char* fileName, char* dataConfigAppName, char configItemKey[CONFIGNUM][CONFIGDATALENGTH], char dataArray[CONFIGNUM][CONFIGDATALENGTH])
{
	int ret = 0;
	LPTSTR lpReturnedString = NULL;
	LPCTSTR lpFileName = NULL;

	lpReturnedString = (char*)malloc(MAX_PATH);
	memset(lpReturnedString, 0, MAX_PATH);

	int itemNum = 0;
	int itemOffset = 0;
	while (1)
	{

		GetPrivateProfileString(dataConfigAppName, configItemKey[itemNum], NULL, lpReturnedString, MAX_PATH, fileName);
		if (*lpReturnedString == '\0')
		{
#ifdef DEBUG
			printf("Input data error\n");
			printf("-- dataConfigAppName = %s, itemKey = %s, lpReturnedString = %s, fileName = %s\n", dataConfigAppName, configItemKey[itemNum], lpReturnedString, fileName);
#endif		
			ret = 1;
			break;
		}
		else
		{
			itemOffset = 0;
			while (lpReturnedString)
			{
				if (*lpReturnedString == '\0')
				{
					break;
				}
				dataArray[itemNum][itemOffset] = *lpReturnedString;
				itemOffset++;
				lpReturnedString++;

			}
			lpReturnedString -= itemOffset;
#ifdef DEBUG
			printf("dataConfigAppName = %s, itemKey = %s, lpReturnedString = %s, fileName = %s\n", dataConfigAppName, configItemKey[itemNum], lpReturnedString, fileName);
#endif

			itemNum++;
		}
		memset(lpReturnedString, 0, strlen((char*)lpReturnedString));

	}

	return ret;
}
int LogName(char* logName, char* configName)
{
	int lengthConName = strlen(configName);
	int i = 0;
	for (i = 0; i < (lengthConName - 4); i++)
	{
		*logName = *configName;
		logName++;
		configName++;
	}

	logName -= i;

	sprintf(logName, "%s.TXT", logName);
#ifdef DEBUG
	printf("*logName = \"%s\"\n", logName);
#endif
	FILE* fd = NULL;
	fd = fopen(lpLogFileName, "a+");
	if (fd == NULL)
	{
		printf("Create the log file %s failed\n", lpLogFileName);
		return 1;
	}
	return 0;
}

functonc.cpp

功能函數代碼
#include "function.h"
#include "..\Common\ExConfig.h"

#define BASSADDRONE 0x3F8
HANDLE hCom;
DCB dcb = { sizeof(DCB) };
char com[5];
int Baudrate[3] = { 0 };
DWORD send_data = 'E';
DWORD resv_data = 'A';

/*
函數功能:設置串口(com)基本配置信息
參數:	baudrate	波特率
		cts	(clear to send)清除發送
		dtr	(data set ready)數據終端準備好
		rts	(request to send)請求數據發送
		dsr	(data set ready)數據準備好
		errorcode  錯誤代碼
		支持硬控制項流的UART
*/
int SerialSetting(int baudrate, int cts, int dtr, int rts, char errorCode[])
{
	dcb.fDtrControl = DTR_CONTROL_DISABLE;
	dcb.fRtsControl = RTS_CONTROL_DISABLE;

	if (hCom != INVALID_HANDLE_VALUE)
	{
		CloseHandle(hCom);
	}

	hCom = CreateFile(com, GENERIC_READ | GENERIC_WRITE, 0, NULL, OPEN_EXISTING, 0, NULL);

	if (hCom == INVALID_HANDLE_VALUE) {
		strcpy_s(itemLog[iItemLogNum].TM_STATUS, "FAIL");
		strcpy_s(itemLog[iItemLogNum].TM_FAILINFO, "DEVICE NO FOUND");
		strcpy_s(itemLog[iItemLogNum].TM_ERRORCODE, errorCode);
		TextColor(RED);
		printf("%s NO FOUND\n\n", com);
		TextColor(WHITE);
		iItemLogNum++;
		return 1;
	}
	system("pause");
	GetCommState(hCom, &dcb);
	dcb.BaudRate = baudrate;
	dcb.ByteSize = 8;
	dcb.Parity = NOPARITY;
	dcb.StopBits = ONESTOPBIT;
	dcb.fOutxCtsFlow = cts;
	dcb.fDtrControl = dtr;
	dcb.fRtsControl = rts;

	int fSuccess = SetCommState(hCom, &dcb);
	if (!fSuccess)	return 1;
	int maskstatus = SetCommMask(hCom, EV_RXCHAR);
	if (maskstatus == 0)	return 1;
	int setupstatus = SetupComm(hCom, 4096, 4096);
	if (setupstatus == 0)	return 1;
	int purgestatus = PurgeComm(hCom, PURGE_TXABORT | PURGE_RXABORT | PURGE_TXCLEAR | PURGE_RXCLEAR);
	if (purgestatus == 0)	return 1;

	COMMTIMEOUTS CommTimeouts;
	CommTimeouts.ReadIntervalTimeout = MAXDWORD;
	CommTimeouts.ReadTotalTimeoutConstant = 1000;
	CommTimeouts.ReadTotalTimeoutMultiplier = 0;
	CommTimeouts.WriteTotalTimeoutConstant = 1000;
	CommTimeouts.WriteTotalTimeoutMultiplier = 0;
	BOOL bTimeOutResult = SetCommTimeouts(hCom, &CommTimeouts);
	if (bTimeOutResult == 0)	return 1;
	return 0;
}

//串口初始化
int InitCOMOne()
{
	int Status = 0;	//狀態(成功或失敗)
	DWORD sataStatus = 0x0;	//讀寫地址數據

	Status = FoxLib_SetPortVal(BASSADDRONE + 1, 0, 1);
	if (Status != 0x0)
		return Status;

	Status = FoxLib_SetPortVal(BASSADDRONE + 3, 0x80, 1);
	if (Status != 0x0)
		return Status;

	FoxLib_GetPortVal(BASSADDRONE + 0, &sataStatus, 1);

	Status = FoxLib_SetPortVal(BASSADDRONE + 0, 0x0C, 1);
	if (Status != 0x0)
		return Status;

	Status = FoxLib_SetPortVal(BASSADDRONE + 1, 0x00, 1);
	if (Status != 0x0)
		return Status;

	Status = FoxLib_SetPortVal(BASSADDRONE + 3, 0x03, 1);
	if (Status != 0x0)
		return Status;

	return 0x0;
}

//串口發送數據
int Send_COMOne(DWORD my_date)
{
	int Status = 0;	//狀態(成功或失敗)
	DWORD sataStatus = 0x0;	//讀寫地址數據
	UINT32 count = 10000;

	FoxLib_GetPortVal(BASSADDRONE + 5, &sataStatus, 1);

	while (!(sataStatus & 0x20) && (count > 0))
	{
		count--;
		FoxLib_GetPortVal(BASSADDRONE + 5, &sataStatus, 1);
	}

	if (count > 0)
	{
		printf("Count:%d\n", count);
		Status = FoxLib_SetPortVal(BASSADDRONE + 0, my_date, 1);
		if (Status != 0x0)
		{
			return Status;
		}
		printf("Send_COM data %c ", my_date);  //發送數據列印
		TextColor(GREEN);
		printf("Success!\n");
		TextColor(WHITE);
		return 0x0;
	}
	else
	{
		printf("Send_COM data %c ", my_date);
		TextColor(RED);
		printf("Failed!\n\n");
		TextColor(WHITE);
		return 0x01;
	}

}

//串口接收數據
int Recv_COMOne(DWORD* my_date)
{

	DWORD sataStatus = 0;	//讀寫地址數據
	UINT8 cn = 0;

	while (cn < 100)
	{
		FoxLib_GetPortVal(BASSADDRONE + 5, &sataStatus, 1);
		if (sataStatus & 0x01)
			break;
		else
		{
			Sleep(100);
			cn++;
		}
	}
	FoxLib_GetPortVal(BASSADDRONE + 5, &sataStatus, 1);
	if (sataStatus & 0x01)
	{
		FoxLib_GetPortVal(BASSADDRONE + 0, my_date, 1);
		printf("Recv_COM data  %c ", *my_date);
		TextColor(GREEN);
		printf("Success!\n");
		TextColor(WHITE);
		return 0x0;
	}
	else
	{
		printf("Received data ");
		TextColor(RED);
		printf("Failed!\n\n");
		TextColor(WHITE);
		return 0x01; 
	}
}

int IDCheckMain(char* fileName, char dataConfigAppName[cTINumberMax][cTINameMax], BYTE Num)
{
	int ret = 0;
	WORD venID = 0, devID = 0, revID = 0;
	char dataConfigArray[CONFIGNUM][CONFIGDATALENGTH];
	memset(dataConfigArray, 0, CONFIGNUM * CONFIGDATALENGTH);
	char aimTestLocation[30] = { '\0' };
	char aimTestErrorcode[30] = { '\0' };
	strcpy(headLog.T_DEVICE, "IdCheck");

	int iNum = 0;

#ifdef DEBUG
	printf("Num = %d, iIdChkCurrentNum = %d, iAllIdChkNum + 1 = %d\n", Num, iIdChkCurrentNum, iAllIdChkNum + 1);
#endif
	if (iIdChkCurrentNum == (iAllIdChkNum + 1))
	{
		strcpy(headLog.T_CAPTION, "All");

		for (iNum = 1; iNum < iIdChkCurrentNum; iNum++)
		{

			GetDataFromConfig(fileName, dataConfigAppName[iIdChkIndex[iNum]], configItemKeyIDchk, dataConfigArray);
			venID = AtoX(dataConfigArray[0]);
			memset(dataConfigArray[0], 0, strlen((char*)dataConfigArray[0]));

			devID = AtoX(dataConfigArray[1]);
			memset(dataConfigArray[1], 0, strlen((char*)dataConfigArray[1]));

			revID = AtoX(dataConfigArray[2]);
			memset(dataConfigArray[2], 0, strlen((char*)dataConfigArray[2]));

			strcpy(aimTestLocation, dataConfigArray[3]);
			memset(dataConfigArray[3], 0, strlen((char*)dataConfigArray[3]));

			strcpy(aimTestErrorcode, dataConfigArray[4]);
			memset(dataConfigArray[4], 0, strlen((char*)dataConfigArray[4]));


#ifdef DEBUG
			printf("**iFanNum = %d, venID = %X, devID = %X, revID = %X\n", iNum, venID, devID, revID);
			printf("**aimTestLocation = %s\n", aimTestLocation);
			printf("**aimTestErrorcode = %s\n", aimTestErrorcode);
#endif
			ret += IDCheck(cIdChkName[iIdChkIndex[iNum]], venID, devID, revID, aimTestLocation, aimTestErrorcode);

			memset(aimTestLocation, 0, strlen(aimTestLocation));
			memset(aimTestErrorcode, 0, strlen(aimTestErrorcode));

		}
	}
	else
	{
		GetDataFromConfig(fileName, dataConfigAppName[iIdChkIndex[Num]], configItemKeyIDchk, dataConfigArray);
		venID = AtoX(dataConfigArray[0]);
		memset(dataConfigArray[0], 0, strlen((char*)dataConfigArray[0]));

		devID = AtoX(dataConfigArray[1]);
		memset(dataConfigArray[1], 0, strlen((char*)dataConfigArray[1]));

		revID = AtoX(dataConfigArray[2]);
		memset(dataConfigArray[2], 0, strlen((char*)dataConfigArray[2]));

		strcpy(aimTestLocation, dataConfigArray[3]);
		memset(dataConfigArray[3], 0, strlen((char*)dataConfigArray[3]));

		strcpy(aimTestErrorcode, dataConfigArray[4]);
		memset(dataConfigArray[4], 0, strlen((char*)dataConfigArray[4]));

#ifdef DEBUG
		printf("*venID = %X, devID = %X, revID = %X\n", venID, devID, revID);
		printf("**aimTestLocation = %s\n", aimTestLocation);
		printf("**aimTestErrorcode = %s\n", aimTestErrorcode);
#endif
		strcpy(headLog.T_CAPTION, cIdChkName[Num]);
		strcpy(headLog.T_LOCATION, aimTestLocation);

		ret = IDCheck(cIdChkName[Num], venID, devID, revID, aimTestLocation, aimTestErrorcode);
		memset(aimTestLocation, 0, strlen(aimTestLocation));
		memset(aimTestErrorcode, 0, strlen(aimTestErrorcode));

	}

	tEndTime = getEndTime(endTime);
	time(&tEndTime);
	strcpy(headLog.T_ENDTIME, endTime);
	memset(durTime, 0, LENGTHA);
	sprintf(durTime, "%d", int(difftime(tEndTime, tStartTime)));
	//getDURTime(tEndTime, tStartTime, durTime);
	strcpy(headLog.T_DURATION, durTime);

	if (ret == 0)
	{
		strcpy(headLog.T_STATUS, "PASS");
	}
	else
	{
		strcpy(headLog.T_STATUS, "FAIL");
	}

	HeadLogRecord(headLog);
	for (int i = 0; i < iItemLogNum; i++)
	{
		ItemLogRecord(itemLog[i]);
	}
	WriteLogRecord(lpLogFileName);
	return ret;
}

DWORD getBusDevFun(DWORD code)
{
	int iRet = 0;
	BYTE offset = 0;
	DWORD dwAddr = 0, dwData = 0, ClassCode = 0;
	for (BYTE i = 0; i < 255; i++)
	{
		BYTE bus = i;
		for (BYTE j = 0; j < 32; j++)
		{
			BYTE dev = j;
			for (BYTE k = 0; k < 8; k++)
			{
				BYTE func = k;
				//check the invalid vendor ID
				offset = 0x00;
				dwAddr = MAKE_CONFIG_ADDRESS(bus, dev, func, offset);
				FoxLib_SetPortVal(PCI_CONFIG_ADDRESS, dwAddr, 4);
				FoxLib_GetPortVal(PCI_CONFIG_DATA, &dwData, 4);
				//	dwData = 0xffffffff;
				DWORD IDCode = dwData;

				if (code == IDCode)
				{
					return (bus << 16) + (dev << 8) + func;
				}
			}
		}
	}
	return 0;
}

//保留idcheck內容,但是這裡不使用
int IDCheck(char para[], WORD inVenID, WORD inDevID, WORD inRevID, char subLocation[], char errorCode[])
{
	int result = 1;
	WORD venID = 0, devID = 0, revID = 0;
	WORD devIdTemp1 = 0, devIdTemp2 = 0, devIdTemp3 = 0;
	WORD devIdTemp = 0;
	WORD devIDH = 0, devIDL = 0;
	int bus = 0, dev = 0, func = 0;
	DWORD dwAddr = 0, dwData = 0, classCode = 0;
	BYTE indexPort = 0x2e, dataPort = 0x2f;
	//	BYTE byteData;
	BYTE offset = 0;
	BOOL flag = TRUE;
	BOOL bLanOK = TRUE;

	WORD ecAddr = 0, ecAddrH = 0, ecAddrL = 0;
	WORD ecData = 0;
	//for creat log .txt

	if (strcmpi(para, "sio") == 0)
	{
		//ITE test should add next 4 lines to enter PNP mode
		FoxLib_SetPortVal(indexPort, 0x87, 1);
		FoxLib_SetPortVal(indexPort, 0x01, 1);
		FoxLib_SetPortVal(indexPort, 0x55, 1);
		FoxLib_SetPortVal(indexPort, 0x55, 1);

		//get the vendor (NUVOTON)
		FoxLib_SetPortVal(0x2e, 0x20, 1);
		FoxLib_GetPortVal(0x2f, (PDWORD)&devIdTemp1, 1);
		FoxLib_SetPortVal(0x2e, 0x21, 1);
		FoxLib_GetPortVal(0x2f, (PDWORD)&devIdTemp2, 1);
		FoxLib_SetPortVal(0x2e, 0x22, 1);
		FoxLib_GetPortVal(0x2f, (PDWORD)&devIdTemp3, 1);
		venID = 0;
		devID = (devIdTemp1 << 8) + devIdTemp2;
		revID = devIdTemp3;

		strcpy(itemLog[iItemLogNum].TM_SUBLOCATION, "DeviceID");
		strcpy(itemLog[iItemLogNum].TM_TESTITEM, para);
		sprintf(itemLog[iItemLogNum].TM_EXPVALUE1, "%04X", inDevID);
		sprintf(itemLog[iItemLogNum].TM_ACTVALUE1, "%04X", devID);

		if (inDevID != devID)
		{
			strcat(itemLog[iItemLogNum].TM_FAILINFO, "expValue not equal actValue_");
			strcat(itemLog[iItemLogNum].TM_FAILINFO, "fail");
			strcpy(itemLog[iItemLogNum].TM_ERRORCODE, errorCode);
			strcpy(itemLog[iItemLogNum].TM_STATUS, "FAIL");
		}
		else {
			strcpy(itemLog[iItemLogNum].TM_STATUS, "PASS");
		}

		iItemLogNum++;

		strcpy(itemLog[iItemLogNum].TM_SUBLOCATION, "RevisionID");
		strcpy(itemLog[iItemLogNum].TM_TESTITEM, para);
		sprintf(itemLog[iItemLogNum].TM_EXPVALUE1, "%04X", inRevID);
		sprintf(itemLog[iItemLogNum].TM_ACTVALUE1, "%04X", revID);
		if (inRevID != revID)
		{
			strcat(itemLog[iItemLogNum].TM_FAILINFO, "expValue not equal actValue_");
			strcat(itemLog[iItemLogNum].TM_FAILINFO, "fail");
			strcpy(itemLog[iItemLogNum].TM_ERRORCODE, errorCode);
			strcpy(itemLog[iItemLogNum].TM_STATUS, "FAIL");
		}
		else {
			strcpy(itemLog[iItemLogNum].TM_STATUS, "PASS");
		}
		iItemLogNum++;

	}
	else
	{
		if (strcmpi(para, "pch") == 0)
		{
#ifdef DEBUG
			printf("\n*********\n");
#endif
			// bus 00 dev 1f func 00
			/*int BusDevFun = getBusDevFun(0X06848086);
			bus = (BusDevFun >> 16)&0xff;
			dev = (BusDevFun >> 8)&0xff;
			func = BusDevFun & 0Xff;*/

			bus = 0x00;
			dev = 0x1F;
			func = 0x00;

		}
		else if (strcmpi(para, "audio") == 0)
		{
			// bus 00 dev 1f func 03
			/*int BusDevFun = getBusDevFun(0X06C88086);
			bus = (BusDevFun >> 16) & 0xff;
			dev = (BusDevFun >> 8) & 0xff;
			func = BusDevFun & 0Xff;*/

			bus = 0x00;
			dev = 0x1F;
			func = 0x03;
		}
		else if (strcmpi(para, "lan") == 0)
		{
			int BusDevFun = getBusDevFun(0X816810EC);
			bus = (BusDevFun >> 16) & 0xff;
			dev = (BusDevFun >> 8) & 0xff;
			func = BusDevFun & 0Xff;
		}

		if (bLanOK == TRUE)
		{
			dwAddr = MAKE_CONFIG_ADDRESS(bus, dev, func, 0x00);
			FoxLib_SetPortVal(PCI_CONFIG_ADDRESS, dwAddr, 4);
			FoxLib_GetPortVal(PCI_CONFIG_DATA, &dwData, 4);
			venID = (WORD)dwData;
			devID = (WORD)(dwData >> 16);

			dwAddr = MAKE_CONFIG_ADDRESS(bus, dev, func, 0x08);
			FoxLib_SetPortVal(PCI_CONFIG_ADDRESS, dwAddr, 4);
			FoxLib_GetPortVal(PCI_CONFIG_DATA, &dwData, 4);
			revID = (BYTE)dwData;
		}

		strcpy(itemLog[iItemLogNum].TM_SUBLOCATION, "VendorID");
		strcpy(itemLog[iItemLogNum].TM_TESTITEM, para);
		sprintf(itemLog[iItemLogNum].TM_EXPVALUE1, "%04X", inVenID);
		sprintf(itemLog[iItemLogNum].TM_ACTVALUE1, "%04X", venID);
		if (inVenID != venID)
		{
			strcat(itemLog[iItemLogNum].TM_FAILINFO, "expValue not equal actValue_");
			strcat(itemLog[iItemLogNum].TM_FAILINFO, "fail");
			strcpy(itemLog[iItemLogNum].TM_ERRORCODE, errorCode);
			strcpy(itemLog[iItemLogNum].TM_STATUS, "FAIL");
		}
		else {
			strcpy(itemLog[iItemLogNum].TM_STATUS, "PASS");
		}
		iItemLogNum++;

		strcpy(itemLog[iItemLogNum].TM_SUBLOCATION, "DeviceID");
		strcpy(itemLog[iItemLogNum].TM_TESTITEM, para);
		sprintf(itemLog[iItemLogNum].TM_EXPVALUE1, "%04X", inDevID);
		sprintf(itemLog[iItemLogNum].TM_ACTVALUE1, "%04X", devID);
		if (inDevID != devID)
		{
			strcat(itemLog[iItemLogNum].TM_FAILINFO, "expValue not equal actValue_");
			strcat(itemLog[iItemLogNum].TM_FAILINFO, "fail");
			strcpy(itemLog[iItemLogNum].TM_ERRORCODE, errorCode);
			strcpy(itemLog[iItemLogNum].TM_STATUS, "FAIL");
		}
		else {
			strcpy(itemLog[iItemLogNum].TM_STATUS, "PASS");
		}
		iItemLogNum++;

		strcpy(itemLog[iItemLogNum].TM_SUBLOCATION, "RevisionID");
		strcpy(itemLog[iItemLogNum].TM_TESTITEM, para);
		sprintf(itemLog[iItemLogNum].TM_EXPVALUE1, "%04X", inRevID);
		sprintf(itemLog[iItemLogNum].TM_ACTVALUE1, "%04X", revID);
		if (inRevID != revID)
		{
			strcat(itemLog[iItemLogNum].TM_FAILINFO, "expValue not equal actValue_");
			strcat(itemLog[iItemLogNum].TM_FAILINFO, "fail");
			strcpy(itemLog[iItemLogNum].TM_ERRORCODE, errorCode);
			strcpy(itemLog[iItemLogNum].TM_STATUS, "FAIL");
		}
		else {
			strcpy(itemLog[iItemLogNum].TM_STATUS, "PASS");
		}
		iItemLogNum++;

	}

	if (venID == inVenID && devID == inDevID && revID == inRevID)
	{
		printf("aimvenid: %04X\t aimdevid: %04X\t aimrevid: %04X\n", inVenID, inDevID, inRevID);
		printf("actvenid: %04X\t actdevid: %04X\t actrevid: %04X\n", venID, devID, revID);
		printf("%s ID test is: ", para);
		TextColor(GREEN);
		printf("passed!\n");
		TextColor(WHITE);
		result = 0;
	}
	else
	{
		printf("aimvenid: %04X\t aimdevid: %04X\t aimrevid: %04X\n", inVenID, inDevID, inRevID);
		printf("actvenid: %04X\t actdevid: %04X\t actrevid: %04X\n", venID, devID, revID);
		printf("%s ID test is: ", para);
		TextColor(RED);
		printf("failed!\n");
		TextColor(WHITE);
		result = 1;
	}

	return result;
}

int FwComMain(char* fileName, char dataConfigAppName[cTINumberMax][cTINameMax], BYTE Num)
{
	int nRetCode = 0;
	int iNum = 0;

	char dataConfigArray[CONFIGNUM][CONFIGDATALENGTH];
	memset(dataConfigArray, 0, CONFIGNUM * CONFIGDATALENGTH);
	char aimTestLocation[30] = { '\0' };
	char aimTestErrorcode[30] = { '\0' };
	strcpy(headLog.T_DEVICE, "Serial Port");


#ifdef DEBUG
	printf("Num = %d, iFCOMCurrentNum = %d, iAllFCOMNum + 1 = %d\n", Num, iFCOMCurrentNum, iAllFCOMNum + 1);
#endif
	if (iFCOMCurrentNum == (iAllFCOMNum + 1))
	{

		for (iNum = 1; iNum < iFCOMCurrentNum; iNum++)
		{

			GetDataFromConfig(fileName, cFCOMName[iFCOMIndex[iNum]], configItemKeyFCOM, dataConfigArray);

			strcpy(aimTestLocation, dataConfigArray[1]);
			memset(dataConfigArray[1], 0, strlen((char*)dataConfigArray[1]));

			strcpy(aimTestErrorcode, dataConfigArray[3]);
			memset(dataConfigArray[3], 0, strlen((char*)dataConfigArray[3]));

			Baudrate[0] = atoi(dataConfigArray[4]);
			memset(dataConfigArray[4], 0, strlen((char*)dataConfigArray[4]));

			Baudrate[1] = atoi(dataConfigArray[5]);
			memset(dataConfigArray[5], 0, strlen((char*)dataConfigArray[5]));

			Baudrate[2] = atoi(dataConfigArray[6]);
			memset(dataConfigArray[6], 0, strlen((char*)dataConfigArray[6]));

#ifdef DEBUG
			printf("**iFanNum = %d, Baudrate[0] = %d, Baudrate[1] = %d, Baudrate[2] = %d\n", iNum, Baudrate[0], Baudrate[1], Baudrate[2]);
			printf("**aimTestLocation = %s\n", aimTestLocation);
			printf("**aimTestErrorcode = %s\n", aimTestErrorcode);
#endif

			strcpy(headLog.T_CAPTION, aimTestLocation);
			strcpy(headLog.T_LOCATION, aimTestLocation);

			nRetCode += FwCom(cFCOMName[iFCOMIndex[iNum]], aimTestLocation, aimTestErrorcode, Baudrate);

			memset(aimTestLocation, 0, strlen(aimTestLocation));
			memset(aimTestErrorcode, 0, strlen(aimTestErrorcode));

		}
	}
	else
	{

		GetDataFromConfig(fileName, cFCOMName[Num], configItemKeyFCOM, dataConfigArray);

		strcpy(aimTestLocation, dataConfigArray[1]);
		memset(dataConfigArray[1], 0, strlen((char*)dataConfigArray[1]));

		strcpy(aimTestErrorcode, dataConfigArray[3]);
		memset(dataConfigArray[3], 0, strlen((char*)dataConfigArray[3]));

		Baudrate[0] = atoi(dataConfigArray[4]);
		memset(dataConfigArray[4], 0, strlen((char*)dataConfigArray[4]));

		Baudrate[1] = atoi(dataConfigArray[5]);
		memset(dataConfigArray[5], 0, strlen((char*)dataConfigArray[5]));

		Baudrate[2] = atoi(dataConfigArray[6]);
		memset(dataConfigArray[6], 0, strlen((char*)dataConfigArray[6]));

#ifdef DEBUG
		printf("*Baudrate[0] = %d, Baudrate[1] = %d, Baudrate[2] = %d\n", Baudrate[0], Baudrate[1], Baudrate[2]);
		printf("**aimTestLocation = %s\n", aimTestLocation);
		printf("**aimTestErrorcode = %s\n", aimTestErrorcode);
#endif

		strcpy(headLog.T_CAPTION, aimTestLocation);
		strcpy(headLog.T_LOCATION, aimTestLocation);

		nRetCode = FwCom(cFCOMName[Num], aimTestLocation, aimTestErrorcode, Baudrate);

		memset(aimTestLocation, 0, strlen(aimTestLocation));
		memset(aimTestErrorcode, 0, strlen(aimTestErrorcode));

	}

	tEndTime = getEndTime(endTime);
	time(&tEndTime);
	strcpy(headLog.T_ENDTIME, endTime);
	memset(durTime, 0, LENGTHA);
	sprintf(durTime, "%d", int(difftime(tEndTime, tStartTime)));
	strcpy(headLog.T_DURATION, durTime);

	if (nRetCode == 0)
	{
		strcpy(headLog.T_STATUS, "PASS");
	}
	else
	{
		strcpy(headLog.T_STATUS, "FAIL");
	}

	HeadLogRecord(headLog);
	for (int i = 0; i < iItemLogNum; i++)
	{
		ItemLogRecord(itemLog[i]);
	}
	WriteLogRecord(lpLogFileName);

	return nRetCode;
}

int FwCom(char para[], char subLocation[], char errorCode[], int baudrate[])
{
	int result = 1;
	//for creat log .txt
	strcpy(com, para);
	strcpy(itemLog[iItemLogNum].TM_TESTITEM, para);
	strcpy(itemLog[iItemLogNum].TM_SUBLOCATION, subLocation);

	for (int i = 0; i < 3; i++)
	{
		if (SerialSetting(Baudrate[i], FALSE, DTR_CONTROL_HANDSHAKE, RTS_CONTROL_TOGGLE, errorCode)) return 1;

		printf("%s initing.......\n", para);
		result = InitCOMOne();
		if (result != 0x0)
		{
			printf("COM initing ");
			TextColor(RED);
			printf("Failed!\n\n");
			TextColor(WHITE);
			strcpy(itemLog[iItemLogNum].TM_STATUS, "FAIL");
			strcat(itemLog[iItemLogNum].TM_FAILINFO, "COM initing Fail!!!");
			strcpy(itemLog[iItemLogNum].TM_ERRORCODE, errorCode);
			iItemLogNum++;
			return result;
		}

		result = Send_COMOne(send_data);
		if (result != 0x0)
		{
			strcpy(itemLog[iItemLogNum].TM_STATUS, "FAIL");
			strcat(itemLog[iItemLogNum].TM_FAILINFO, "Send_COM Fail!!!");
			strcpy(itemLog[iItemLogNum].TM_ERRORCODE, errorCode);
			iItemLogNum++;
			return result;
		}

		Sleep(0x100);

		result = Recv_COMOne(&resv_data); //接收Recv_COMOne()函數的返回值

		//接收失敗,提示
		if (result != 0x0)
		{
			strcpy(itemLog[iItemLogNum].TM_STATUS, "FAIL");
			strcat(itemLog[iItemLogNum].TM_FAILINFO, "Recv_COM Fail!!!");
			strcpy(itemLog[iItemLogNum].TM_ERRORCODE, errorCode);
			iItemLogNum++;
			return result;
		}

		if (resv_data == send_data)
		{
			printf("COM Send&Receive Test ");
			TextColor(GREEN);
			printf("Passed!\n\n");
			TextColor(WHITE);
			strcpy(itemLog[iItemLogNum].TM_STATUS, "PASS");
			iItemLogNum++;
			return result;
		}
		else
		{
			printf("COM One Send&Receive Test Fail ");
			TextColor(RED);
			printf("Failed!\n\n");
			TextColor(WHITE);
			strcpy(itemLog[iItemLogNum].TM_STATUS, "FAIL");
			strcat(itemLog[iItemLogNum].TM_FAILINFO, "COM Send&Receive Test Fail!!!");
			strcpy(itemLog[iItemLogNum].TM_ERRORCODE, errorCode);
			iItemLogNum++;
			return 0x01;
		}
	}
	return result;
}

main.cpp

主函數帶代碼
 #include "function.h"
#include "..\Common\ExConfig.h"

#ifndef _DEBUG
#define new DEBUG_NEW
#endif

void PromptInformation(char* name)
{
	int i = 0;
	printf("==========================================================================\n");
	printf("*********Diag COM Tool for %s %s*********\n", projectName, FCOM);
	printf("Usage:\n");
	printf("\t%s [number| all] [ConfigFile]\n", name);
	printf("Note:\n");
	printf("\tnumber :\n");
	for (i = 1; i <= iAllFCOMNum; i++)
	{
		if (i == 1)
		{
			printf("\t\t");
		}

		printf("%d:\"%s\" ", i, cFCOMName[iFCOMIndex[i]]);
		if (i == iAllFCOMNum)
		{
			printf("\n");
			printf("\t\tAll: For all the number test \n");

		}
	}
	printf("==========================================================================\n");

}

int main(int argc, char* argv[])
{
	int result1 = 2;
	int iArgvNum = 0;
	BYTE Num = 0;

	char* lpFileName = (char*)malloc(MAX_PATH);
	memset(lpFileName, 0, MAX_PATH);

	strlwr(argv[0]);
	GetGlobalData(argv[0]);

	memset((char*)lpLogFileName, 0, MAX_PATH);

	strcpy(headLog.T_NAME, argv[0]);
	memset(startTime, 0, LENGTHA);
	tStartTime = getNowTime(startTime);
	time(&tStartTime);
	strcpy(headLog.T_STARTTIME, startTime);

	if (argc == 3)
	{
		strlwr(argv[2]);
		if (strstr(argv[2], ".ini") == NULL)
		{
			PromptInformation(argv[0]);
			return 1;
		}

		iArgvNum = 1;
		if (strcmpi(argv[iArgvNum], "all") == 0)
		{
#ifdef DEBUG
			printf("**argv[iArgvNum] = %s\n", argv[iArgvNum]);
#endif
			iFCOMCurrentNum = iAllFCOMNum + 1;
		}
		else
		{
#ifdef DEBUG
			printf("*argv[iArgvNum] = %s\n", argv[iArgvNum]);
#endif
			iFCOMCurrentNum = atoi(argv[iArgvNum]);
			Num = iFCOMIndex[iFCOMCurrentNum];
			if (iFCOMCurrentNum < 1 || iFCOMCurrentNum > iAllFCOMNum)
			{
				printf("Parameter number is out of range.\n");
				PromptInformation(argv[0]);
				return 1;
			}
		}

		iArgvNum = 2;
		if (LogName(lpLogFileName, argv[iArgvNum]))
		{
			return 1;
		}

		if ((argv[iArgvNum][0] == '.') || (argv[iArgvNum][1] == ':'))
		{
			sprintf((char*)lpFileName, "%s", argv[iArgvNum]);

		}
		else
		{
			sprintf((char*)lpFileName, ".\\%s", argv[iArgvNum]);

		}

		result1 = FwComMain(lpFileName, cFCOMName, Num);

	}
	else
	{
		PromptInformation(argv[0]);
		return 1;
	}

	return result1;
}

 


您的分享是我們最大的動力!

-Advertisement-
Play Games
更多相關文章
  • # 資料庫概論系統—系統篇 ## 一、關係查詢處理和查詢優化 ### 1.1關係資料庫的查詢處理 查詢處理可分為四個階段:查詢分析、檢查檢查、查詢優選和查詢執行(其中查詢優化可分為代數和物理優化) ### 1.2關係資料庫系統的查詢優化 查詢優化的優點不僅在於用戶不必考慮如何最好地表達查詢以獲得較高 ...
  • ## 1. SSL原理 SSL(Secure Sockets Layer)是一種用於安全地傳輸數據的加密協議。在MySQL中,SSL可以用於加密客戶端與伺服器之間的通信,以防止數據被竊取或篡改。SSL通過以下方式實現數據的加密和身份驗證: - **加密通信**:SSL使用非對稱加密和對稱加密相結合的 ...
  • 有一段時間,在B站那裡刷視頻的時候,無意刷到一個德生的收音機視頻。突然讓我想起了我的中學時代,我的中學時代是在收音機的陪伴之下成長的。那個時候,主要的想法是為了收聽短波的英文電臺,美名日學習英語。不過那個時候,能清晰聽到的英文廣播電臺並不多,更多的是外國播放的中文廣播電臺,而這些電臺大多數是說國內的 ...
  • 這裡給大家分享我在網上總結出來的一些知識,希望對大家有所幫助 介紹 今天介紹一個非常簡單的入門級小案例,就是地圖的捲簾效果實現,各大地圖引擎供應商都有相關示例,很奇怪高德居然沒有,我看了下文檔發現其實也是可以簡單實現的,演示代碼放到文末。本文用到了圖層掩模,即圖層遮罩,讓圖層只在指定範圍內顯示。 實 ...
  • 這裡給大家分享我在網上總結出來的一些知識,希望對大家有所幫助 背景 因為我們日常開發項目的時候,需要和同事對接api和文檔還有UI圖,所以有時候要同時打開多個視窗,併在多個視窗中切換,來選擇自己要的信息,如果api和文檔不多的情況還好,但是有時候就是要做大量的頁面,為了提升效率我決定自己做一個截圖工 ...
  • 一. 源碼展示: 1. Object.equals: ①引用類型地址值比較,直接返回結果:true || false public class Object { public boolean equals(Object obj) { return (this == obj); } } 2. Stri ...
  • ## 1.1 概述 > 說白了就是鍵值對的映射關係 > > 不會丟失數據本身關聯的結構,但不關註數據的順序 > > 是一種可變類型 ```py 格式:dic = {鍵:值, 鍵:值} ``` * 鍵的類型:字典的鍵可以是任何不可變的類型,如浮點數,字元串,元組 ## 1.2 函數dict 可以從其他 ...
  • ### 目錄 *1:什麼是AQS?* *2:AQS都有那些用途?* *3:我們如何使用AQS* *4:AQS的實現原理* *5:對AQS的設計與實現的一些思考* ### 1:什麼是AQS ​ 隨著電腦的算力越來越強大,各種各樣的並行編程模型也隨即踴躍而來,但當我們要在並行計算中使用共用資源的時候, ...
一周排行
    -Advertisement-
    Play Games
  • 移動開發(一):使用.NET MAUI開發第一個安卓APP 對於工作多年的C#程式員來說,近來想嘗試開發一款安卓APP,考慮了很久最終選擇使用.NET MAUI這個微軟官方的框架來嘗試體驗開發安卓APP,畢竟是使用Visual Studio開發工具,使用起來也比較的順手,結合微軟官方的教程進行了安卓 ...
  • 前言 QuestPDF 是一個開源 .NET 庫,用於生成 PDF 文檔。使用了C# Fluent API方式可簡化開發、減少錯誤並提高工作效率。利用它可以輕鬆生成 PDF 報告、發票、導出文件等。 項目介紹 QuestPDF 是一個革命性的開源 .NET 庫,它徹底改變了我們生成 PDF 文檔的方 ...
  • 項目地址 項目後端地址: https://github.com/ZyPLJ/ZYTteeHole 項目前端頁面地址: ZyPLJ/TreeHoleVue (github.com) https://github.com/ZyPLJ/TreeHoleVue 目前項目測試訪問地址: http://tree ...
  • 話不多說,直接開乾 一.下載 1.官方鏈接下載: https://www.microsoft.com/zh-cn/sql-server/sql-server-downloads 2.在下載目錄中找到下麵這個小的安裝包 SQL2022-SSEI-Dev.exe,運行開始下載SQL server; 二. ...
  • 前言 隨著物聯網(IoT)技術的迅猛發展,MQTT(消息隊列遙測傳輸)協議憑藉其輕量級和高效性,已成為眾多物聯網應用的首選通信標準。 MQTTnet 作為一個高性能的 .NET 開源庫,為 .NET 平臺上的 MQTT 客戶端與伺服器開發提供了強大的支持。 本文將全面介紹 MQTTnet 的核心功能 ...
  • Serilog支持多種接收器用於日誌存儲,增強器用於添加屬性,LogContext管理動態屬性,支持多種輸出格式包括純文本、JSON及ExpressionTemplate。還提供了自定義格式化選項,適用於不同需求。 ...
  • 目錄簡介獲取 HTML 文檔解析 HTML 文檔測試參考文章 簡介 動態內容網站使用 JavaScript 腳本動態檢索和渲染數據,爬取信息時需要模擬瀏覽器行為,否則獲取到的源碼基本是空的。 本文使用的爬取步驟如下: 使用 Selenium 獲取渲染後的 HTML 文檔 使用 HtmlAgility ...
  • 1.前言 什麼是熱更新 游戲或者軟體更新時,無需重新下載客戶端進行安裝,而是在應用程式啟動的情況下,在內部進行資源或者代碼更新 Unity目前常用熱更新解決方案 HybridCLR,Xlua,ILRuntime等 Unity目前常用資源管理解決方案 AssetBundles,Addressable, ...
  • 本文章主要是在C# ASP.NET Core Web API框架實現向手機發送驗證碼簡訊功能。這裡我選擇是一個互億無線簡訊驗證碼平臺,其實像阿裡雲,騰訊雲上面也可以。 首先我們先去 互億無線 https://www.ihuyi.com/api/sms.html 去註冊一個賬號 註冊完成賬號後,它會送 ...
  • 通過以下方式可以高效,並保證數據同步的可靠性 1.API設計 使用RESTful設計,確保API端點明確,並使用適當的HTTP方法(如POST用於創建,PUT用於更新)。 設計清晰的請求和響應模型,以確保客戶端能夠理解預期格式。 2.數據驗證 在伺服器端進行嚴格的數據驗證,確保接收到的數據符合預期格 ...