Automotive and Embedded Networks

cancel
Showing results for 
Search instead for 
Did you mean: 

callback for transmit and receive

NCTYPE_STATE _NCFUNC_ MyCallback (
                                    NCTYPE_OBJH       ObjHandle,
                                    NCTYPE_STATE      State,
                                    NCTYPE_STATUS     status,
                                    NCTYPE_ANY_P      RefData)
{
     if ( (State & NC_ST_WRITE_MULT  ) || (status == CanErrFunctionTimeout) )
          status = ncWrite(ObjHandle, sizeof(Transmit), &Transmit);


     else if  (State & NC_ST_READ_MULT)
      status = ncReadMult(ObjHandle,  sizeof(ReceiveBuf), (void *)ReceiveBuf, &ActualDataSize);

     ..... some other codes....

}

my calls to callback:

Transmit :      Status = ncCreateNotification (TxRx, NC_ST_WRITE_MULT, 100, NULL, MyCallback);
Receive:        Status = ncCreateNotification (TxRx, NC_ST_READ_MULT, NC_DURATION_INFINITE, NULL, MyCallback);

I provide two buttons to call either transmit or receive and when I run my program and call either one of these functions ONCE, the ncCreateNotification run continuously till my whole debugger hangs. I am using borland Cand USB-CAN. Can someone help me on this?



 

0 Kudos
Message 1 of 4
(5,194 Views)

Well guys. My ncCreateNotification works for Transmit and Receive if I dont call them together. However, when I perform the followings, my ncWrite cannot work at all.

1) calling ncCreateNotification to do ncWrite.

2) Switch to ncCreateNotification to do ncReadMult.

3) calling ncCreateNotification to do ncWrite to transmit another frame.

my program runs smoothly if i only perform step 1 and step 2 (in either way).

0 Kudos
Message 2 of 4
(5,188 Views)
Unfortunately you can only have one notification at a time on the same object.  Thus if both Transmit and receive are happening on the same object handle, then only one notification can be handled a time. But both is running sequentially anyway, thus you should handle both notifications sequentially as well.
 
DirkW
0 Kudos
Message 3 of 4
(5,174 Views)
Seems like I cannot create two objects at the same time. I am trying to create objects: TxObj and RxObj.
Both values are the same. 0xA601A0.
 
The flow of my program goes like this:
- configure object through ncConfig and ncOpenObject
 
- transmit by calling ncCreateNotification and I will call this from time to time if I wish to transmit any data. This function returns a 0.
 
- receive by calling ncCreateNotification and this will return NC_ST_READ_AVAIL. I will only call this function once and it will return me data if there's any message sent.
 
0 Kudos
Message 4 of 4
(5,164 Views)