Having problem in CAN channel initialization

i am trying to initialize the CAN channel using the code below. Its a code in VC++ .Net 2005 for Vector CAN CardXL

[code]
bool FlashTool::frmMain::setupCANConnection()
{
CloseCAN();

m_objXLDriver = gcnew XLDriver();
m_objXLDriver->XL_OpenDriver();

XLClass::xl_driver_config ^ objDriverConfig = gcnew XLClass::xl_driver_config();
XLClass::XLstatus status;
status = m_objXLDriver->XL_GetDriverConfig(objDriverConfig);
//bool tp = errorMapping(status);

m_nHWChannel = comboCANChannel->SelectedIndex;
if (comboCANIdLength->SelectedIndex == 0)
{
m_bIDLengthStandard = true ;
}
else
{
m_bIDLengthStandard = false ;
}

if (objDriverConfig->channelCount == 0)
{
MessageBox::Show( "No channel found connected to the driver" , "ECU Flash Tool" ,MessageBoxButtons::OK,MessageBoxIcon::Error);
return false ;
}
if (status != XLClass::XLstatus::XL_SUCCESS)
{
MessageBox::Show( "Unable to connect to driver" , "ECU Flash Tool" ,MessageBoxButtons::OK,MessageBoxIcon::Error);
return false ;
}
else
{
bool bAppHWConfigured = false ;

m_sAppName = "ECU_Flash_Tool" ;
m_nBusType = ( unsigned int )XLClass::XLbusTypes::XL_BUS_TYPE_CAN;
for ( unsigned int nLoop=0;nLoop < objDriverConfig->channelCount; nLoop++)
{
m_nAppChannel = nLoop;
status = m_objXLDriver->XL_GetApplConfig(m_sAppName,m_nAppChannel,m_nHWType,m_nHWIndex,m_nHWChannel,m_nBusType);
//MessageBox::Show(" channel : " + i.ToString() + " status : " + Convert::ToString(status));
if (errorMapping(status) != true )
{
MessageBox::Show( " continue " );
continue ;
}
bAppHWConfigured = true ;
break ;
}
if (bAppHWConfigured == false )
{
MessageBox::Show( " Configuring " );
m_nHWType = ( unsigned int )XLClass::XLhwTypes::XL_HWTYPE_CANCARDXL;
m_nHWIndex = 0;
m_nHWChannel = 0;
for ( unsigned int nLoop=0;nLoop < objDriverConfig->channelCount; nLoop++)
{
m_nAppChannel = nLoop;
if (m_nHWChannel == 0)
{
//m_nHWIndex = 1;
m_nHWChannel = 1;
}
else
{
//m_nHWIndex = 0;
m_nHWChannel = 0;
}
status = m_objXLDriver->XL_SetApplConfig(m_sAppName,m_nAppChannel,m_nHWType,m_nHWIndex,m_nHWChannel,m_nBusType);
MessageBox::Show( " channel : " + nLoop.ToString() + " status : " + Convert::ToString(status));
}
m_objXLDriver->XL_PopupHwConfig();
return false ;
}
}

unsigned int nChannelMask;
m_nHWType = ( unsigned int )XLClass::XLhwTypes::XL_HWTYPE_CANCARDXL;
m_nHWIndex = 0;
m_nHWChannel = 0;
m_sAppName = "ECU_Flash_Tool" ;

nChannelMask = m_objXLDriver->XL_GetChannelMask(m_nHWType,m_nHWIndex,m_nHWChannel);//objDriverConfig->channel[m_nHWChannel]->channelMask ;
m_nPermissionMask = nChannelMask;
m_nAccessMask = nChannelMask;

// open port
status = m_objXLDriver->XL_OpenPort(m_nPortHandle, m_sAppName, m_nAccessMask, m_nPermissionMask, 64, m_nBusType);
bool tp = errorMapping(status);
if (status != XLClass::XLstatus::XL_SUCCESS)
{
MessageBox::Show( " Please confirm that the cable is connected to the card" , "ECU Flash Tool" ,MessageBoxButtons::OK,MessageBoxIcon::Error);
return false ;
}

unsigned int nBitRate = Convert::ToUInt32(comboStartBaudrate->Text);
status = m_objXLDriver->XL_CanSetChannelBitrate(m_nPortHandle,m_nAccessMask,nBitRate);

// deactivate channel
status = m_objXLDriver->XL_DeactivateChannel(m_nPortHandle, m_nAccessMask);

//Setting the chip parameters
XLClass::xl_chip_params ^ objChipParams = gcnew XLClass::xl_chip_params();
objChipParams->bitrate = (unsigned int)Convert::ToUInt32(comboStartBaudrate->Text);//Start baudrate
objChipParams->tseq1 = (unsigned char)Convert::ToByte(txtTseg1->Text,16);
objChipParams->tseq2 = (unsigned char)Convert::ToByte(txtTseg2->Text,16);
objChipParams->sjw = (unsigned char)Convert::ToByte(txtSjw->Text,16);
objChipParams->sam = 1;
status = XLClass::XLstatus::XL_ERR_CMD_TIMEOUT;
try
{
//Setting the channel params.
status = m_objXLDriver->XL_CanSetChannelParams(m_nPortHandle,m_nAccessMask,objChipParams);
}
catch(Exception ^exp)
{
MessageBox::Show(exp->ToString());
return false;
}

// activate channel
m_objXLDriver->XL_ActivateChannel(m_nPortHandle, m_nAccessMask, m_nBusType, flags);

// reset time stamp clock
m_objXLDriver->XL_ResetClock(m_nPortHandle);

return true ;
}
[/code]

when the function XL_CanSetChannelParams is executed, the following exception is thrown

System.ArgumentException: Offset and length were out of bounds for the array or count is greater than the number of elements from index to the end of the source collection. at System.Buffer.BlockCopy(Array src, Int32 srcOffset, Array dst, Int32 dstOffset, Int32 count) at vxlapi_NET20.XLMarshalling.Insert(Byte[] byteArray, Int32 offsetInMO, Byte valueToInsert) at vxlapi_NET20.XLMarshalling.Fill_ChipParams(xl_chip_params chipParams) at vxlapi_NET20.XLDriver.XL_CanSetChannelParams(Int32 portHandle, UInt64 accessMask, xl_chip_params chipParams) at FlashTool.frmMain.setupCANConnection() in e:flashtoolfrmmain.cpp:line 1397

Please help in this.
Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories