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
Create successful ePaper yourself
Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.
MemMap Example Code<br />
CHAPTER 3: USING THE SNAP ETHERNET I/O DRIVER TOOLKIT<br />
This section gives a few examples of how to use the OptoSnapIoMemMapX ActiveX component<br />
to connect to <strong>and</strong> communicate with the Ethernet-<strong>based</strong> brain. The same principles would apply<br />
to the OptoSnapIoMemMap C++ class. All example code is written with Microsoft Visual Basic.<br />
The interesting code is in boldface. For more example code, see the example files listed in the<br />
previous section.<br />
Create the OptoSnapIoMemMapX Component<br />
Define a global instance of the component <strong>and</strong> create it in a function. For example:<br />
Public gBrain As OptoSnapIoMemMapX<br />
Sub Main()<br />
Set gBrain = New OptoSnapIoMemMapX<br />
End Sub<br />
Open a Connection to the Brain<br />
Use methods OpenEnet() <strong>and</strong> IsOpenDone() to create a connection to the brain. For example:<br />
Dim nResult As Long<br />
' Attempt to open the brain...<br />
nResult = gBrain.OpenEnet("10.192.54.0", 2001, 10000, 1)<br />
' Check the result<br />
If (nResult = SIOMM_OK) Then<br />
' Keep calling IsOpenDone() until we succeed, time-out, or error<br />
nResult = gBrain.IsOpenDone()<br />
While (nResult = SIOMM_ERROR_NOT_CONNECTED_YET)<br />
' let other tasks get some CPU<br />
DoEvents<br />
' Check the status of the open operation<br />
nResult = gBrain.IsOpenDone() ' keep trying<br />
Wend<br />
End If<br />
Close the Connection to the Brain<br />
Use the Close () method. For example:<br />
gBrain.Close ()<br />
SNAP Ethernet-Based I/O Units Protocols <strong>and</strong> Programming Guide 55