Ejemplo n.º 1
0
int main(int argc, char *argv[]) 
{
	TPCANMsg message;
	TPCANStatus status;
	unsigned long n = 0;

	status = CAN_Initialize(PCAN_CHANNEL, PCAN_BAUDRATE, 0, 0, 0);
	printf("Initialize CAN: 0x%lx\n", status);
	if(status != PCAN_ERROR_OK) goto leave;

	message.ID = 0x100;
	message.LEN = 8;
	message.MSGTYPE = PCAN_MESSAGE_STANDARD;
	memset(message.DATA, 0x00, message.LEN);

	for(;;) {
	    while((status = CAN_Write(PCAN_CHANNEL, &message)) == PCAN_ERROR_OK) {
			message.DATA[0]++;
	        if((++n % 1000) == 0)
		        printf("  - T Message %lu\n", n);
	    }
	}
leave:
	CAN_Uninitialize(PCAN_NONEBUS);
	return 0;
}
Ejemplo n.º 2
0
TPCANStatus CAN_Uninitialize(TPCANHandle Channel) {

	PCAN_DESCRIPTOR *desc = NULL;
	TPCANStatus Result = PCAN_ERROR_OK;
	int index = 0;

	try {

		// logging
		char szLog[MAX_LOG];
		LOG_EnteringTo("CAN_Uninitialize");
		sprintf(szLog, "Channel: 0x%02X", Channel);
		LOG_Parameters("CAN_Uninitialize", szLog);

		// descriptor
		if (ppDescriptors == NULL) {
			Result = PCAN_ERROR_INITIALIZE;
			goto leave;
		}
		if (ppDescriptors[Channel] == NULL && Channel != PCAN_NONEBUS) {
			Result = PCAN_ERROR_INITIALIZE;
			goto leave;
		}
		desc = ppDescriptors[Channel];


		if (Channel == PCAN_NONEBUS) {
			// uninit all
			for (index = 1; index < 0x100; index++)
				CAN_Uninitialize((TPCANHandle) index);
		} else {
			// close file
			if (desc->nFileNo > -1) {
				__close(desc->nFileNo);
				desc->nFileNo = -1;
			}
			// remove descriptor
			free(desc);
			ppDescriptors[Channel] = NULL;
		}

		leave: LOG_LeavingFrom("CAN_Uninitialize", Result);
		return Result;
	} catch (...) {
		Result = PCAN_ERROR_UNKNOWN;
		LOG_Exception("CAN_Uninitialize");
	}
	return Result;
}