我最近在测试PCI-1680CAN卡时再数据接收模块中出现了一个问题:LabVIEW: 调用库函数节点调用的外部节点中出现一个意外。意外可能引起LabVIEW内存损坏。在新位置保存工作并重启LabVIEW。各位大侠,请问这是什么原因啊?下面是底层的VC代码:
LRESULT CANReadFile ( WORDPort, DWORD NumNeeded, PVOID FAR RcvBuf, PDWORD pNumReturned )
Purpose Read the received data from receive buffer. This function allow user receive data by interrupt way. Parameters
Name | Direction | Type | Range | Description | Port | Input | WORD | default | Specify the port number | NumNeeded | Input | DWORD | default | The message number that should be read from buffer | RcvBuf | OutPut | PVOID FAR | default | The receive buffer that the transmit data stored | pNumReturned | Output | PDWORD | default | If pNumReturned = 0, the function is called unsuccessful. Else its value is the received message number. |
Return SUCCESS
if successful CANInvalidPortIndex
ifport index is invalid, must from 1 to 10 CANPortIsNotOpened
ifport is not opened
Example:
#include "canbus2.0.h"
typedef
struct
{ UCHAR rtr; ULONG id; UCHAR dlen; UCHAR data[8]; } CAN_MSG_T;
main( ) { CAN_MSG_T msg; DWORD cbReturned = 0; int nLength; WORD m_wProtocolType; UINT m_Port; string m_RxBuf;
// do some initiate works ......
// read the data from receive buffer if ( m_wProtocolType = = CANBUS_PROTOCOL_20A ) { CANReadFile( m_Port, 1, &msg, &cbReturned ); if ( cbReturned ) { m_RxID = msg.id;
// get receive data length nLength = msg.dlen; if ( msg.dlen!= 0 ) { printf( "%s", (PUCHAR)msg.data ); } } } } |