⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 stm32+i

📁 STM32烧写
💻
📖 第 1 页 / 共 2 页
字号:
	Handle = uc_OpenInterface (dataTreeentitydesc->value->value, ifcConfig); 
    if(Handle < 0)
	{
		print_debug(STAUSToChar(STATUS_INFO), "Could not open the interface", STATUS_FAIL);
		return FALSE;
	}
	//The function tests provided ifcHandle for validity. 
	//UCT_RETVAL uc_ValidateInterfaceHandle  ( UCT_IFCHANDLE  ifcHandle   ) 
	print_debug(STAUSToChar(STATUS_INFO), "uc_ValidateInterfaceHandle - validating the interface handle", STATUS_UNDEFINED);
	Result = uc_ValidateInterfaceHandle (Handle); 
	if(Result != UCRET_SUCCESS)
	{
		print_debug(STAUSToChar(STATUS_INFO), "The created interface handle is not valid", STATUS_FAIL);
		return FALSE;
	}

	isConnected = TRUE;
	return TRUE;
}

void CCAN::closeCAN()
{
	WORD Result = UCRET_SUCCESS ;

	//Closes the interface immediately. 
    //UCT_RETVAL uc_CloseInterface  ( UCT_IFCHANDLE  ifcHandle   ) 
	print_debug(STAUSToChar(STATUS_INFO), "uc_CloseInterface - close interface handle", STATUS_UNDEFINED);
    Result = uc_CloseInterface (this->Handle); 
	if(Result != UCRET_SUCCESS)
	{
		print_debug(STAUSToChar(STATUS_INFO), "could not close interface", STATUS_FAIL);
    
	}


	//Device de-initialization UCT_RETVAL uc_ShutdownDevice  ( pZTSTRING  devPath   )  
	print_debug(STAUSToChar(STATUS_INFO), "uc_ShutdownDevice - de-initialization the device", STATUS_UNDEFINED);
    Result = uc_ShutdownDevice  (dataTreeentitydesc->value->value);
	if(Result != UCRET_SUCCESS)
	{
		print_debug(STAUSToChar(STATUS_INFO), "could not de-initialize the device", STATUS_FAIL);
	} 
	
	this->Handle = NULL;
	isConnected = FALSE;
}

bool CCAN::setTimeOut(DWORD ms)
{
	this->timeout = ms;
	return true;
}

bool CCAN::setSpeed(DWORD baudrate)
{
	DWORD Result = true;
	//Closes the interface immediately. 
    //UCT_RETVAL uc_CloseInterface  ( UCT_IFCHANDLE  ifcHandle   )  
	printf("uc_CloseInterface - close interface handle\n");
    Result = uc_CloseInterface (this->Handle); 
	/*if(Result != UCRET_SUCCESS)
	{
		printf("\n(!!!)could not close interface %s\n\n", dataTreeentitydesc->value->value);
	}*/
	//---------------------------------------------------------
	// Scan for baudrate value
	//---------------------------------------------------------
    char _baudrate[6];
	print_debug(STAUSToChar(STATUS_INPUT), "Please type the baudrate: ", STATUS_UNDEFINED);
	itoa(baudrate, _baudrate, 10);
	TDataTreePosition Baudrate = Tdt_ItemName2Position (ifcConfig, "/DrvParams/Baudrate");
	while(strcmp(Baudrate->name, "Baudrate") != 0)
	{
		Baudrate = Tdt_GetNextItem (Baudrate, "/DrvParams/Baudrate");
	}
	strcpy(Baudrate->value->value, _baudrate);
	//---------------------------------------------------------
	print_debug(STAUSToChar(STATUS_INFO), "uc_OpenInterface - Opening the interface handle", STATUS_UNDEFINED);
	Handle = uc_OpenInterface (dataTreeentitydesc->value->value, ifcConfig); 
    if(Handle < 0)
	{
		print_debug(STAUSToChar(STATUS_INFO), "Could not open the interface", STATUS_FAIL);
		return FALSE;
	}
	return true;
}

bool CCAN::setDefaultID(int did)
{
	DWORD Result = true;
	//Closes the interface immediately. 
    //UCT_RETVAL uc_CloseInterface  ( UCT_IFCHANDLE  ifcHandle   )  
	printf("uc_CloseInterface - close interface handle\n");
    Result = uc_CloseInterface (this->Handle); 
	if(Result != UCRET_SUCCESS)
	{
		printf("\n(!!!)could not close interface %s\n\n", dataTreeentitydesc->value->value);
	}

	//---------------------------------------------------------
	// Scan for baudrate default ID
	//---------------------------------------------------------
	char _defaultid[6];
	print_debug(STAUSToChar(STATUS_INPUT), "Please type the default id: ", STATUS_UNDEFINED);

	_defaultid[0] = '0';
	_defaultid[1] = 'x';

	itoa(did, &_defaultid[2], 16);
	TDataTreePosition DefaultID = Tdt_ItemName2Position (ifcConfig, "/DrvParams/DefaultID");
	while(strcmp(DefaultID->name, "DefaultID") != 0)
	{
		DefaultID = Tdt_GetNextItem (DefaultID, "/DrvParams/DefaultID");
	}
	strcpy(DefaultID->value->value, _defaultid);
    //---------------------------------------------------------
	print_debug(STAUSToChar(STATUS_INFO), "uc_OpenInterface - Opening the interface handle", STATUS_UNDEFINED);
	Handle = uc_OpenInterface (dataTreeentitydesc->value->value, ifcConfig); 
    if(Handle < 0)
	{
		print_debug(STAUSToChar(STATUS_INFO), "Could not open the interface", STATUS_FAIL);
		return FALSE;
	}

	return true;
}

bool CCAN::setFilterID(int fid)
{
	DWORD Result = true;
	//Closes the interface immediately. 
    //UCT_RETVAL uc_CloseInterface  ( UCT_IFCHANDLE  ifcHandle   )  
	printf("uc_CloseInterface - close interface handle\n");
    Result = uc_CloseInterface (this->Handle); 
	if(Result != UCRET_SUCCESS)
	{
		printf("\n(!!!)could not close interface %s\n\n", dataTreeentitydesc->value->value);
	}

	//---------------------------------------------------------
	// Scan for FilterID
	//---------------------------------------------------------
	char _filterid[6];
	print_debug(STAUSToChar(STATUS_INPUT), "Please type the filter id: ", STATUS_UNDEFINED);

	_filterid[0] = '0';
	_filterid[1] = 'x';

	itoa(fid, &_filterid[2], 16);
	TDataTreePosition FilterID = Tdt_ItemName2Position (ifcConfig, "/DrvParams/FilterID");
	while(strcmp(FilterID->name, "FilterID") != 0)
	{
		FilterID = Tdt_GetNextItem (FilterID, "/DrvParams/FilterID");
	}
	strcpy(FilterID->value->value, _filterid);
    //---------------------------------------------------------
	print_debug(STAUSToChar(STATUS_INFO), "uc_OpenInterface - Opening the interface handle", STATUS_UNDEFINED);
	Handle = uc_OpenInterface (dataTreeentitydesc->value->value, ifcConfig); 
    if(Handle < 0)
	{
		print_debug(STAUSToChar(STATUS_INFO), "Could not open the interface", STATUS_FAIL);
		return FALSE;
	}

	return true;
}

int CCAN::sendData(DWORD lg, LPBYTE data)
{
	DWORD Result=0;

	if( lg<0 || data==NULL)
		return Result;

	//Result = uc_Write(Handle, (pU8ARRAY)data, lg, 2000);
	
	Result = uc_InjectPacket  (Handle,(pU8ARRAY)data); 

	if(Result < UCRET_SUCCESS)
	{
		print_debug(STAUSToChar(STATUS_INFO), "could not write to the to the interface", STATUS_FAIL);
		return -1;
	}

	fprintf(log, "\nSEND >> ID: 0x%02X, DLC: 0x%02X DATA: 0x", data[2],  data[6]);
	for(int i = 7; i<(int)data[6]+7; i++)
        fprintf(log, "%02X ", data[i]);

	/*fprintf(log, "\n<SEND><ID >0x%02X</ID><DLC>0x%02X</DLC><DATA>0x", data[2],  data[6]) ;   

	for(int i = 7; i<(int)data[6]+7; i++)
        fprintf(log, "%02X ", data[i]);

	fprintf(log,"</DATA></SEND>");*/

	return lg;
}

int CCAN::receiveData(DWORD lg, LPBYTE data)
{
	DWORD Result = 0;

	if( lg<0 || data==NULL)
		return Result;

	//while (uc_GetQueueStatus( this->Handle, UC_QUEUE_RX) <= 0) ;

    Result = uc_Read(this->Handle, (pU8ARRAY)data, lg, this->timeout);

	if(Result == lg)
	{
		fprintf(log, "\nRECI << ID: 0x%02X, DLC: 0x%02X DATA: 0x", data[2],  data[6]);
		for(int i = 7; i<(int)data[6]+7; i++)
			fprintf(log, "%02X ", data[i]);
	}
	else 
		print_debug(STAUSToChar(STATUS_INFO), "receiveData - could not read from the to the interface", STATUS_FAIL);

	return Result;
}
/******************* (C) COPYRIGHT 2009 STMicroelectronics *****END OF FILE******/

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -