14.08.2013 Views

snap ethernet-based i/o units protocols and programming guide

snap ethernet-based i/o units protocols and programming guide

snap ethernet-based i/o units protocols and programming guide

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

CHAPTER 3: USING THE SNAP ETHERNET I/O DRIVER TOOLKIT<br />

Create the OptoSnapIoStreamX Component<br />

Define a global instance of the component <strong>and</strong> create it in a function. For example:<br />

Public WithEvents gBrain As OptoSnapIoStreamX<br />

Sub Main()<br />

Set gBrain = New OptoSnapIoStreamX<br />

End Sub<br />

Open a Connection to the Brain<br />

Use the OpenStreaming() method to prepare for listening to stream packets. For example:<br />

Dim nResult As Long<br />

' Open for st<strong>and</strong>ard streaming<br />

nResult = gBrain.OpenStreaming(1, 0, PortNumberEdit.Text)<br />

' Check for error<br />

If (nResult SIOMM_OK) Then<br />

H<strong>and</strong>leError (nResult)<br />

End If<br />

Start Listening to a Brain<br />

Use the StartStreamingListening() method to start listening for stream packets from the specified<br />

brain. For example:<br />

' Start listening<br />

If (nResult = SIOMM_OK) Then<br />

nResult = gBrain.StartStreamListening("10.20.30.40", 2000)<br />

End If<br />

H<strong>and</strong>le Stream Events<br />

Use the OnStreamEvent() event to h<strong>and</strong>le caught stream packets. For example:<br />

Private Sub gBrain_OnStreamEvent(ByVal nIpAddress As Long,<br />

ByVal nStatus As Long)<br />

Dim nResult As Long<br />

' Check the status of the event<br />

If (nStatus SIOMM_OK) Then<br />

' A timeout is the most likely error<br />

H<strong>and</strong>leError (nStatus)<br />

Else<br />

58 SNAP Ethernet-Based I/O Units Protocols <strong>and</strong> Programming Guide

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

Saved successfully!

Ooh no, something went wrong!