Automotive and Embedded Networks

cancel
Showing results for 
Search instead for 
Did you mean: 

WaitForState NC_ST_WRITE_SUCCESS times out after ncWrite. But only after a while..

I have a 2-port PCI CAN card, series two. I have configured CAN0 and CAN1 as 'receive everything, no buffers' etc. (pretty much as the obj2obj example).

I need to tranmit on one CAN ID and receive on another, so I have configured CAN objects for this.

All works fine for so long, but then ncWrite just stops working.

Any clues?
Mike Evans
TRW Conekt
N.I. Alliance Member, UK
http://www.Conekt.net
0 Kudos
Message 1 of 5
(4,098 Views)
As an update - this seems only to happen on the second port of the card.

The ncWrite function returns ok, and reading the output queue length gives a value of 1, but the frame never leaves the buffer onto the bus itself.

There are no problems with the bus itself (and swapping the ECUs I'm talking to between the ports still gives CAN1 problems).

Using two single-port CAN cards rather than a dual-port card there are no problems at all. (Figure that out!)

The application is a simple "Transmit one frame using the CAN Transmit Object, and read the ECU's reply with the CAN Receive object"

Hope this gives a little more info. Any help at all would be appreciated.
Mike

PS The original post should have read that CAN0 and CAN1 NIOs are configured to 'rec
eive nothing', not receive everything.
Mike Evans
TRW Conekt
N.I. Alliance Member, UK
http://www.Conekt.net
0 Kudos
Message 2 of 5
(4,097 Views)
Hello Mike,

Have you ever tried to log your application
with NI-Spy ?
Maybe you can see in the log file whats going on.
and check out which State-Flags are set.

Hope this helps
Greetings
from the Lake of Constance,Germany
Juergen
0 Kudos
Message 3 of 5
(4,097 Views)
Hi Juergen,

Thanks for your reply.

I have tried this, the ncWrite function returns zero, so no flags are set.

The two lines where the problem is are:
nResult = ncWrite( CcpTxHandle[nStation], nLength, TxData );
if (nResult == 0) nResult = ncWaitForState(CcpTxHandle[nStation],NC_ST_WRITE_SUCCESS,50,StatePtr);

The ncWaitForState function works fine for a while (i.e. I can call this routine 100 or more times), then for no apparent reason it times out waiting for the write transfer to complete. I have a Vector Canalyser connected to the bus too, which shows no frame errors or bus faults.

If I replace the dual port card with two single-port cards, everything works perfectly!

Any ideas?

Regards,
Mike
Mike Evans
TRW Conekt
N.I. Alliance Member, UK
http://www.Conekt.net
0 Kudos
Message 4 of 5
(4,097 Views)
Hi Mike,

This sounds not good. Maybe there is a memory problem
with the dual port card.
Note: Every card (dual or single) has only 6600 bytes RAM. For more information on this see this links:
http://digital.ni.com/public.nsf/websearch/FB1B03046CE09C53862568FE0052EAFB?OpenDocument
or just search for:
Maximum number of NI-CAN Objects

Maybe you will have to reduce the Queue's size,
but if there is a failure, you will see this by using
Ni-Spy. Just look what happens at ncOpenObject(..)
I am of the opinion this is not the cause. But try it.

There is an alternative for ncWaitForState
-->ncGetAttribute.
You have know NC_ST_WRITE_SUCCESS is a bit mask for states. Take a look at NiCan.h
So if there are any other bits set ncWaitForState
timeouts!

So try this:
NC_TPYE_STATUS Status;
BOOL bExit = FALSE;
int i = 0;
CEvent event;

while(!bExit){
ncGetAttribute(m_NetIntfObjh,NC_ATTR_STATUS,sizeof
(Status),&Status);
TRACE("STATUS = 0x%X\n",Status); // what happens ?
// Filter NC_ST_WRITE_SUCCESS
Status &= NC_ST_WRITE_SUCCESS;
if(Status == NC_ST_WRITE_SUCCESS)
bExit = TRUE;
else{
::WaitForSingleObject(event,5);// wait 5ms
// do not use Sleep() !! this is better
i++;
if (i == 10) // Timeout after 50 ms
bExit = TRUE;
}
}

Hope this helps

Juergen
0 Kudos
Message 5 of 5
(4,098 Views)