 olssoninc
		
			olssoninc
		
		
		
		
		
		
		
		
	
			11-01-2006 06:35 AM
11-01-2006 08:28 AM
Hi,
See the attached example for how to get the number of bytes.
DirkW
11-01-2006 09:30 AM
 YuGen
		
			YuGen
		
		
		
		
		
		
		
		
	
			11-01-2006 12:10 PM - edited 11-01-2006 12:10 PM
Hi Anders,
You can find details in the "NI-CAN Hardware and Software Manual", Chapter 11: "Frame API for C":
1. If you use a CAN Object, "Data always contains Data Length valid bytes, where Data Length was configured using ncConfig."(p.11-81)
2. If you use a CAN Network Interface Object, the field 'DataLength' in the structure NCTYPE_CAN_STRUCT "Returns the number of data bytes received in the frame. This specifies the number of valid data bytes in Data." (p.11-74).
So you seem to have to use a CAN Network Interface Object instead of a CAN Object.
Yuri
Message Edited by YuGen on 11-01-2006 12:11 PM
11-06-2006 06:15 AM
OK. I have trying to convert my receive objekt from a CAN Objekt to a CAN Network Interface Objekt but it still dosent work. I got the struct for Network objekt but the only information in that struct is the same as the CAN objekt (time and data). So wath is wrong when I don´t get the data length information?
//Olssoninc
 YuGen
		
			YuGen
		
		
		
		
		
		
		
		
	
			11-06-2006 08:43 AM
Anders,
> I got the struct for Network objekt but the only information in that struct is the same as ...
With a CAN object you used this structure:
typedef  struct {
   NCTYPE_ABS_TIME        Timestamp;
   NCTYPE_UINT8           Data[8];
} NCTYPE_CAN_DATA_TIMED;
With a CAN Network Interface Object you should use this structure:
typedef  struct {
   NCTYPE_ABS_TIME         Timestamp;
   NCTYPE_CAN_ARBID        ArbitrationId;
   NCTYPE_UINT8            FrameType;
   NCTYPE_UINT8            DataLength;
   NCTYPE_UINT8            Data[8];
} NCTYPE_CAN_STRUCT;
11-07-2006 09:25 AM
Hello!
I have try to use that struct but I don´t ArbitrationId, Frametype and Datalength dosent get any information just some bytes from the data array. It is like the compiler use CAN objekt even when a use the network Interface frame struct.
//Olssoninc
 YuGen
		
			YuGen
		
		
		
		
		
		
		
		
	
			11-07-2006 06:16 PM
11-08-2006 12:27 AM
Here is my CAN read/write function!
void CCaNREADERView::ReadCAN(unsigned char *byte,char *cReadId,char *cWriteId)
{
 char csCANStdWrite[14]="CAN1::STD";
 strcat_s(csCANStdWrite,14,cWriteId);
 char csCANStdRead[14]="CAN1::STD";
 strcat_s(csCANStdRead,14,cReadId);
 NCTYPE_STATUS           Status;
 NCTYPE_STATE            State;
 NCTYPE_CAN_DATA         Transmit;
 NCTYPE_CAN_STRUCT Receive;
 NCTYPE_ATTRID           AttrIdList[8];
 NCTYPE_UINT32           AttrValueList[8];
   AttrIdList[0] =         NC_ATTR_BAUD_RATE;   
   AttrValueList[0] =      50000;
   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] =    NC_CAN_ARBID_NONE;
   AttrIdList[5] =         NC_ATTR_CAN_MASK_STD;
   AttrValueList[5] =      NC_CAN_MASK_STD_DONTCARE;
   AttrIdList[6] =         NC_ATTR_CAN_COMP_XTD;
   AttrValueList[6] =      NC_CAN_ARBID_NONE;
   AttrIdList[7] =         NC_ATTR_CAN_MASK_XTD;
   AttrValueList[7] =      NC_CAN_MASK_XTD_DONTCARE;
 
   Status = ncConfig("CAN0", 8, AttrIdList, AttrValueList);
   PrintStat(Status, "ncConfig CAN0");  
  
   Status = ncConfig("CAN1", 8, AttrIdList, AttrValueList);
   PrintStat(Status, "ncConfig CAN1");  
   AttrIdList[0] =         NC_ATTR_COMM_TYPE;
   AttrValueList[0] =      NC_CAN_COMM_RX_PERIODIC;//NC_CAN_COMM_RX_UNSOL;
   AttrIdList[1] =         NC_ATTR_PERIOD;
   AttrValueList[1] =      NC_DURATION_10SEC;
 AttrIdList[2] =         NC_ATTR_CAN_DATA_LENGTH;
 AttrValueList[2] =      3;
   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] =      0;
   Status = ncConfig(csCANStdRead, 7, AttrIdList, AttrValueList);
   PrintStat(Status, "ncConfig CAN0::1224 (receiving)");  
   AttrIdList[0] =         NC_ATTR_COMM_TYPE;
   AttrValueList[0] =      NC_CAN_COMM_TX_PERIODIC;
   AttrIdList[1] =         NC_ATTR_BKD_PERIOD;
   AttrValueList[1] =      NC_DURATION_1SEC;
   AttrIdList[2] =         NC_ATTR_CAN_DATA_LENGTH;
   AttrValueList[2] =     7;  //Length of Transmitting mes
   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] =      0;
 
 
 Status = ncConfig(csCANStdWrite, 7, AttrIdList, AttrValueList);
 PrintStat(Status, "ncConfig CAN1::1224 (transmitting)");  
 Status = ncOpenObject(csCANStdRead, &RxHandle);
 PrintStat(Status, "ncOpenObject CAN0::1224 (receiving)");
   
  
 Status = ncOpenObject(csCANStdWrite, &TxHandle);
 PrintStat(Status, "ncOpenObject CAN1::STD1224 (transmitting)");
    
 Transmit.Data[0] = 0x00;
 Transmit.Data[1] = 0x00;
 Transmit.Data[2] = 0x00;
 Transmit.Data[3] = 0x00;
 Transmit.Data[4] = 0x00;
 Transmit.Data[5] = 0x00;
 Transmit.Data[6] = 0x00;
 Transmit.Data[7] = 0x00;
 Status= ncWrite(TxHandle, sizeof(Transmit), &Transmit);
 PrintStat(Status, "ncWrite");
 
     Status = ncWaitForState(RxHandle, 
               (NC_ST_READ_AVAIL | NC_ST_ERROR),
               (NC_DURATION_10SEC * 2), &State);
 PrintStat(Status, "ncWaitForState");
 Status= ncRead(RxHandle, sizeof(Receive), &Receive);
 
 for(int i=0;i<8;i++)
  byte[i]=Receive.Data[i];
 Status = ncCloseObject(TxHandle);
 PrintStat(Status, "ncCloseObject CAN1::STD5 (transmitting object)");
 Status = ncCloseObject(RxHandle);
 PrintStat(Status, "ncCloseObject CAN0::STD5 (receiving object)");
}
11-08-2006 12:30 AM
Ok I use CANx::STDy is it wrong? where did they write about that?
//Anders