Automotive and Embedded Networks

cancel
Showing results for 
Search instead for 
Did you mean: 

Display all data

I use NI-CAN card(PCI-Series2) and Vc++6.0. Main work is transmission CAN ID Data DataLength.
Now, I only display ID and DataLength.
Q1:Use oscilloscope(expert  in CAN ) to see it's Data only ID and DataLength(no Data).Why?
Q2:Use ncWrite(CAN Network Interface Object) to transmission CAN ID Data DataLength ? Or When Use ncWrite(CAN  Object)to transmission CAN Data , Open CAN Network Interface Object to transmission Data?(syntax:CAN0::STD5 example:transmission ID=0x05)
 
 
0 Kudos
Message 1 of 2
(3,844 Views)
Hi,
 
There are two ways to transmit a Frame with NI-CAN. The first is using the Network Interface Object (Port ex: CAN0) directly as follows:
 
/* Configure and open the CAN Network Interface Object */ 
 AttrIdList[0] =         NC_ATTR_BAUD_RATE;  
 AttrValueList[0] =      Baudrate;
 AttrIdList[1] =         NC_ATTR_START_ON_OPEN;
 AttrValueList[1] =      NC_TRUE;
 AttrIdList[2] =         NC_ATTR_READ_Q_LEN;
 AttrValueList[2] =      0;
 AttrIdList[3] =         NC_ATTR_WRITE_Q_LEN;
 AttrValueList[3] =      1;
 AttrIdList[4] =         NC_ATTR_CAN_COMP_STD;
 AttrValueList[4] =      0;
 AttrIdList[5] =         NC_ATTR_CAN_MASK_STD;
 AttrValueList[5] =      NC_CAN_MASK_STD_DONTCARE;
 AttrIdList[6] =         NC_ATTR_CAN_COMP_XTD;
 AttrValueList[6] =      0;
 AttrIdList[7] =         NC_ATTR_CAN_MASK_XTD;
 AttrValueList[7] =      NC_CAN_MASK_XTD_DONTCARE;
    
ncConfig(Interface, 8, AttrIdList, AttrValueList); 
    
ncOpenObject(Interface, &TxHandle);
 
/* Populate data array */
 for (i=0; i<8; i++)
 {
  data[i] = i*2;
 }
 
memcpy (Transmit.Data, data, data_length);
Transmit.DataLength = data_length;
Transmit.IsRemote = 0;
 
ncWrite(TxHandle, sizeof(Transmit), &Transmit);
 
The second way is using a CAN Object for a particular ID (ex: CAN0::STD5), in this case 11 bit ID 5 on Port CAN0 as follows:
 
/* Configure the CAN Network Interface Object */  no open
 AttrIdList[0] =         NC_ATTR_BAUD_RATE;  
 AttrValueList[0] =      Baudrate;
 AttrIdList[1] =         NC_ATTR_START_ON_OPEN;
 AttrValueList[1] =      NC_TRUE;
 AttrIdList[2] =         NC_ATTR_READ_Q_LEN;
 AttrValueList[2] =      0;
 AttrIdList[3] =         NC_ATTR_WRITE_Q_LEN;
 AttrValueList[3] =      0;
 AttrIdList[4] =         NC_ATTR_CAN_COMP_STD;
 AttrValueList[4] =      0;
 AttrIdList[5] =         NC_ATTR_CAN_MASK_STD;
 AttrValueList[5] =      NC_CAN_MASK_STD_DONTCARE;
 AttrIdList[6] =         NC_ATTR_CAN_COMP_XTD;
 AttrValueList[6] =      0;
 AttrIdList[7] =         NC_ATTR_CAN_MASK_XTD;
 AttrValueList[7] =      NC_CAN_MASK_XTD_DONTCARE;
 
ncConfig(Interface, 8, AttrIdList, AttrValueList); 
     
//Configure and open CAN Object for periodic transmission;    
 AttrIdList[0] =         NC_ATTR_COMM_TYPE;
 AttrValueList[0] =      NC_CAN_COMM_TX_PERIODIC;
 AttrIdList[1] =         NC_ATTR_BKD_PERIOD;
 AttrValueList[1] =      period;
 AttrIdList[2] =         NC_ATTR_CAN_DATA_LENGTH;
 AttrValueList[2] =      data_length;
 AttrIdList[3] =         NC_ATTR_CAN_TX_RESPONSE;  
 AttrValueList[3] =      NC_FALSE;
 AttrIdList[4] =         NC_ATTR_RX_CHANGES_ONLY;
 AttrValueList[4] =      NC_FALSE;
 AttrIdList[5] =         NC_ATTR_READ_Q_LEN;
 AttrValueList[5] =      0;
 AttrIdList[6] =         NC_ATTR_WRITE_Q_LEN;
 AttrValueList[6] =      1;
 
//Format the Interface and ID to a String (ObjectID) like CAN0::STD5
 strcat(Interface,id_string);
 strcpy(ObjectID,Interface);
 
 ncConfig (ObjectID, 7, AttrIdList, AttrValueList);
 ncOpenObject (ObjectID, &TxHandle);
 
/* Populate data array */ 
 for (i=0; i<8; i++)
 {
   data[i] = 'D';
 }
 
/* Copy the CAN Data Array with the specific length (data_length) to the DATA inside Transmit */
 memcpy (Transmit.Data, data, data_length);
 
ncWrite(TxHandle, sizeof(Transmit), &Transmit); 
 
In both cases you need to specify the data bytes and the data length.
The ID configures with the write on the Network Interface and with the configure on the Object.
For both ways there are examples shipping with NI-CAN. You can find them with the //National Instruments/NI-CAN folder.
 
Hope that helps.
 
DirkW
 

 
0 Kudos
Message 2 of 2
(3,831 Views)