Automotive and Embedded Networks

cancel
Showing results for 
Search instead for 
Did you mean: 

Diag On Lin (with Automotive Diagnostic Command Set toolkit)

Solved!
Go to solution

Hello,

 

I need to develop an application under Labwindows/CVI 2013 that can do basic diagnostics on LIN. I have installed the toolkit "Automotive Diagnostic Command Set" and even tested the 2 NI examples.

 

I have a PXI-8516 baord. I just need to send and recieve frames.

I know that this frame is a good one for example : 3C-92-F2-00-00-00-00-00-00

 

The problem with the example is that the 0x3C and 0x3D is not used. I need to know how can a create and send a frame and how recieve the ansewer (need to wait for few ms before reading ? )

 

here my code ( part on callaback function) :

	unsigned char dataIn[8] = {146, 242, 0, 0, 0, 0, 0, 0}; //HEX : 92, F2, 00, 00, 00, 00, 00, 00
	unsigned int len = 8;
	
	switch (event)
	{
		case EVENT_COMMIT:
			
			Delay(1); 
			
			for(int i=0; i<8;i++)
			{
				status = ndUDSWriteDataByIdentifier(&DiagStruct, 0x3C, dataIn, len, &Success);
				
				Delay(1); 
				status = ndUDSWriteDataByIdentifier(&DiagStruct, 0x3D, dataIn, len, &Success);
				Delay(1); 
}

Thank you in advance ! 

 

0 Kudos
Message 1 of 14
(7,520 Views)

Blue_Strike,

 

Which examples are you using? Are they the ones the ship with CVI? Did you modify them?

Becca B.
Product Marketing
National Instruments
0 Kudos
Message 2 of 14
(7,500 Views)

Hello Becca M.

 

Yes I'm using the example provided when you install CVI 2013.

I didn't modified the source, I just copied few lines to my code.

0 Kudos
Message 3 of 14
(7,487 Views)

I have Mux Trace too connected to my device and my Ni board (PXI 8516). When I send a frame with mux trace like 'HEX : 92, F2, 00, 00, 00, 00, 00, 00'  and then a request resp frame, I get the frame answer. 

I want to do the same thing but with CVI. 

0 Kudos
Message 4 of 14
(7,473 Views)

Blue_Strike,

 

Have you tried just running the examples without taking parts of it and putting it in your code? This is a great way to ensure that everything is connected correctly and that you are getting the desired functionality. Which examples are you looking at? And what exactly is not working with your code? Are you getting an error? 

Becca B.
Product Marketing
National Instruments
0 Kudos
Message 5 of 14
(7,465 Views)

Hello,

 

I'm getting a general message error. 

Firsteble, I call ndOpenDiagnosticOnLin (19200 baud LIN1)  then ndUDSDiagnosticSessionControl (mode 0x81) then ndUDSReadDataByIdentifier function

 

Here is my Callaback function code to read LIN frame :

 

int CVICALLBACK UDSReadDataByIdentifierCallback (int panel, int control, int event,
		void *callbackData, int eventData1, int eventData2)
{
	char *Report_temp = NULL;
	unsigned short ID = 0;
	int ID_temp = 0;
	unsigned char dataIn[8] = {146, 242, 0, 0, 0, 0, 0, 0}; //HEX : 92, F2, 00, 00, 00, 00, 00, 00
	unsigned char dataOut[8];
	long len = 8;
	
	switch (event)
	{
			case EVENT_COMMIT:
			//Get TABPANEL handle and num
			GetPanelHandleFromTabPage (panelHandle, MAIN_PANEL_TABPANEL, 1, &DiagtabHandle);
			
			Report_temp = malloc(128 * sizeof(char));
			ID = (unsigned short) ID_temp;
			
			Delay(1); 
			
				status = ndUDSReadDataByIdentifier(&DiagStruct, DIAG_READ_ID, dataOut, len, &Success); //DIAG_READ_ID = 0x3D // Len = 8
				Delay(0.05); 
			
			CheckError ("ndUDSReadDataByIdentifier", status, Report_temp);

			
			SetCtrlVal(DiagtabHandle, TABDIAG_LED_Diag_RD_Data_Id, ON);
			
			
			if(status == 0)   // first call OK
			{
				SetCtrlAttribute (DiagtabHandle, TABDIAG_LED_Diag_RD_Data_Id, ATTR_ON_COLOR , status == 0? VAL_GREEN : VAL_RED);
				SetCtrlVal(DiagtabHandle, TABDIAG_STATUS_FUNC_6, "PASS");
				SetCtrlVal(DiagtabHandle, TABDIAG_REPORT_FUNC_6, Report_temp);
			}
			else  //Error 
			{
				SetCtrlAttribute (DiagtabHandle, TABDIAG_LED_Diag_RD_Data_Id, ATTR_ON_COLOR , VAL_RED);
				SetCtrlVal(DiagtabHandle, TABDIAG_STATUS_FUNC_6, "FAIL");
				SetCtrlVal(DiagtabHandle, TABDIAG_REPORT_FUNC_6, Report_temp);
			}
			break;
	}
	return 0;
}

I'm getting a general error in the line ndUDSReadDataByIdentifier. (See attached pic)

Capture.PNG

 

0 Kudos
Message 6 of 14
(7,449 Views)

Besides, when I check the Mux Trace to see what the ndUDSReadDataByIdentifier send on the LIN, I see this : 

Capture.PNG

 

but what I want to send is different. I mean, when i call the ndUDSWriteDataByIdentifier function. 

0 Kudos
Message 7 of 14
(7,446 Views)

Should I use the ndDiagFrameSend function to send a LIN diag frame ? 

0 Kudos
Message 8 of 14
(7,439 Views)

To resume all this, how can I do to send this frame on LIN : 

HEX : 92, F2, 00, 00, 00, 00, 00, 00

And how should I do to read ECU answer using the automotive toolkit.  

0 Kudos
Message 9 of 14
(7,418 Views)

Blue_Strike,

 

1. Are you seeing the same error/crash when you are just running the examples? If you haven't done so already, run the examples without changing them. Check to see what you are outputing by using the Bus Monitor. 

2. Use the Bus Monitor so you can check what you are actually sending out on the bus. Do this for both your program as well as the examples. This will give confirmation of what is being sent, not what is actually on the ECU

3. Do you have a database?

4. Can you post your code where you set up your handle?

 

 

Becca B.
Product Marketing
National Instruments
0 Kudos
Message 10 of 14
(7,406 Views)