#include <O22SIOST.h>
Public Member Functions | |
int | OpenStreaming (long nType, long nLength, long nPort) |
int | CloseStreaming () |
int | SetCallbackFunctions (STREAM_CALLBACK_PROC pStartThreadCallbackFunc, void *pStartThreadParam, STREAM_EVENT_CALLBACK_PROC pStreamEventCallbackFunc, void *pStreamEventParam, STREAM_CALLBACK_PROC pStopThreadCallbackFunc, void *pStopThreadParam) |
int | StartStreamListening (char *pchIpAddressArg, long nTimeoutMS) |
int | StopStreamListening (char *pchIpAddressArg) |
int | GetLastStreamStandardBlockEx (SIOMM_StreamStandardBlock *pStreamData) |
*int | GetLastStreamCustomBlockEx (SIOMM_StreamCustomBlock *pStreamData) |
int | StreamHandler () |
int | CheckStreamTimeouts () |
Public Attributes | |
bool | m_bListenToStreaming |
A flag used in StreamThread() to know when to stop listening. | |
uint8_t * | m_pbyLastStreamBlock |
Byte array containing the last block received. | |
SIOMM_StreamCustomBlock | m_LastStreamBlock |
STREAM_CALLBACK_PROC | m_pStartThreadCallbackFunc |
User callback function. | |
STREAM_EVENT_CALLBACK_PROC | m_pStreamEventCallbackFunc |
User callback function. | |
STREAM_CALLBACK_PROC | m_pStopThreadCallbackFunc |
User callback functio. | |
void * | m_pStartThreadParam |
User callback parameter. | |
void * | m_pStreamEventParam |
User callback parameter. | |
void * | m_pStopThreadParam |
User callback parameter. | |
Protected Attributes | |
SOCKET | m_StreamSocket |
The handle to the UDP socket. | |
long | m_nStreamType |
The type set in OpenStreaming() | |
long | m_nStreamLength |
The length set in OpenStreaming() | |
O22StreamItem * | pStreamList |
Head of a list of I/O units to listen for. | |
long | nStreamListCount |
The number of items in pStreamList. | |
The O22SnapIoStream C++ class is used to listen to UDP stream packets from multiple Opto 22 SNAP Ethernet I/O units streaming to the same port on the computer running this code.
The basic procedure for using this class is:
This class will eat all UDP packets sent to the port specified in OpenStreaming(). No other program on the same computer can listen to UDP packets on the same port while this code is running.
int O22SnapIoStream::CheckStreamTimeouts | ( | ) |
Checks if any stream items have timed out.
NOTE: This method is not considered a public API and should not be called by user programs. It's public in the class sense only so that the StreadThread() function in O22SIOST.cpp can call it.
int O22SnapIoStream::CloseStreaming | ( | ) |
Stops all listening and closes the port.
int O22SnapIoStream::GetLastStreamCustomBlockEx | ( | SIOMM_StreamCustomBlock * | pStreamData | ) |
Returns the last stream packet received.
This method should be called immediately after receiving a packet event via the pStreamEventCallbackFunc callback function set in SetCallbackFunctions.
This method is used if you're using custom streams. If you're using standard streams, use GetLastStreamStandardBlockEx.
pStreamData | Pointer to a SIOMM_StreamCustomBlock instance to hold the received data. |
int O22SnapIoStream::GetLastStreamStandardBlockEx | ( | SIOMM_StreamStandardBlock * | pStreamData | ) |
Returns the last stream packet received.
This method should be called immediately after receiving a packet event via the pStreamEventCallbackFunc callback function set in SetCallbackFunctions.
This method is used if you're using standard streams. If you're using custom streams, use GetLastStreamCustomBlockEx.
pStreamData | Pointer to a SIOMM_StreamStandardBlock instance to hold the received data. |
int O22SnapIoStream::OpenStreaming | ( | long | nType, |
long | nLength, | ||
long | nPort | ||
) |
Opens and initializes the computer's port ot start listening for stream packets.
nType | SIOMM_STREAM_TYPE_STANDARD for standard streams, SIOMM_STREAM_TYPE_CUSTOM for custom streams. The type is set in the I/O unit's stream configuration. This must match it and all I/O units streaming to the same port should be of the same type. |
nLength | If using custom streams, the size of a single custom block. |
nPort | The port being streamed to |
int O22SnapIoStream::SetCallbackFunctions | ( | STREAM_CALLBACK_PROC | pStartThreadCallbackFunc, |
void * | pStartThreadParam, | ||
STREAM_EVENT_CALLBACK_PROC | pStreamEventCallbackFunc, | ||
void * | pStreamEventParam, | ||
STREAM_CALLBACK_PROC | pStopThreadCallbackFunc, | ||
void * | pStopThreadParam | ||
) |
Sets the three callback functions used by the stream listening thread.
pStartThreadCallbackFunc | This callback function is called whenever the stream listening thread is started. Can be NULL if the callback function is not needed. |
pStartThreadParam | User data that will be passed back to pStartThreadCallbackFunc. Can be NULL. |
pStreamEventCallbackFunc | This callback funciton is called whenver a stream packet from an I/O unit is received. |
pStreamEventParam | User data that will be passed back to pStreamEventCallbackFunc. Can be NULL. |
pStopThreadCallbackFunc | This callback function is called when the stream listening thread is stopped. Can be NULL. |
pStopThreadParam | User data that will be passed back to pStopThreadCallbackFunc. Can be NULL. |
int O22SnapIoStream::StartStreamListening | ( | char * | pchIpAddressArg, |
long | nTimeoutMS | ||
) |
Starts listening for packets from an I/O unit at the specified IP address.
More than one I/O unit may be listened to by multiple calls to this function.
pchIpAddressArg | IP address of I/O unit in string form, e.g. "1.2.3.4" |
nTimeoutMS | Timeout value used to generate error events if the specified length of time has passed since a stream packet has been received. Different I/O units can have different timeout values. |
int O22SnapIoStream::StopStreamListening | ( | char * | pchIpAddressArg | ) |
Stops listening to the I/O unit at the specified address.
pchIpAddressArg | IP address of I/O unit in string form, e.g. "1.2.3.4" |
int O22SnapIoStream::StreamHandler | ( | ) |
Main worker method.
NOTE: This method is not considered a public API and should not be called by user programs. It's public in the class sense only so that the StreadThread() function in O22SIOST.cpp can call it.
Called repeatedly by the StreamThread() function. This method checks the socket for new packets and determines if the user is interested in them.
SIOMM_StreamCustomBlock O22SnapIoStream::m_LastStreamBlock |
Structure containing the last stream block received. It can be converted to a SIOMM_StreadStandardBlock instance in GetLastStreamStandardBlockEx