13.07.2015 Views

VCI - Virtual CAN Interface - Ixxat

VCI - Virtual CAN Interface - Ixxat

VCI - Virtual CAN Interface - Ixxat

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Accessing the busDWORD WINAPI ReceiveThreadProc( LPVOID lpParameter ){HANDLE hChannel = (HANDLE) lpParameter;<strong>CAN</strong>MSG sCanMsg;while (canChannelWaitRxEvent(hChannel, INFINITE) == <strong>VCI</strong>_OK){while (canChannelPeekMessage(hChannel, &sCanMsg) == <strong>VCI</strong>_OK)}{}// processing of the message}return 0;Note that the thread procedure only ends when the function canChannelWaitRxEventreturns an error code not equal to <strong>VCI</strong>_OK. However, when correctlycalled, all message channel-specific functions only return an error code not equalto <strong>VCI</strong>_OK when a serious problem has occurred.A program-controlled “normal” abort of the thread procedure from the previousexample does not therefore appear to be possible. However, it is possible to closethe handle of the message channel from another thread, where all currently outstandingfunction calls or all new calls end with an error code not equal to<strong>VCI</strong>_OK. However, the disadvantage of this is that any transmit threads runningsimultaneously are also affected.3.1.3.2 Transmission of <strong>CAN</strong> messagesThe easiest way of transmitting <strong>CAN</strong> messages to the bus is to call the functioncanChannelSendMessage. The function waits until sufficient space is available inthe message channel and then writes the message in a free entry in the transmitbuffer. If it was possible to enter the message in the transmit buffer in the timespecified in dwMsTimeout, the function returns the value <strong>VCI</strong>_OK. If the specifiedtime has elapsed without the message being written in the transmit buffer, thefunction returns the value <strong>VCI</strong>_E_TIMEOUT.The function canChannelPostMessage also writes a <strong>CAN</strong> message in the transmitbuffer. Unlike canChannelSendMessage, however, the function does not wait untilsufficient space is available in the transmit buffer but returns to the callingprogram with an error code if no free entry is available.It is possible to wait for the occurrence of transmit events with the function can-ChannelWaitTxEvent. The transmit event is triggered when the transmit bufferhas at least enough space for the number of messages specified in wTxThresholdwhen canChannelInitialize is called.The following code fragment shows a possible use of the functions canChannel-WaitTxEvent and canChannelPostMessage.23Copyright IXXAT Automation GmbH C-API Programming Manual, Version 1.5

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!