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.
CHAPTER 3: USING THE SNAP ETHERNET I/O DRIVER TOOLKIT<br />
Structures<br />
Since some ActiveX containers, such as Visual Basic, support predefined structures rather than<br />
just the basic data types, several methods also support structures. These structures can be easier<br />
to use. The names of these methods all end with Ex, <strong>and</strong> they are similar to other methods.<br />
For example, in the table on page 65, compare GetDigPtReadArea to GetDigPtReadAreaEx. The<br />
former takes individual parameters, whereas the latter takes the following structure:<br />
struct SIOMM_DigPointReadArea<br />
{<br />
long nState; // bool<br />
long nOnLatch; // bool<br />
long nOffLatch; // bool<br />
long nCounterState; // bool<br />
long nCounts; // unsigned int<br />
};<br />
See the file OptoENET-IO\DriverToolkit\Source\C++\O22STRCT.h for structure definitions. These<br />
definitions are included in the ActiveX type library.<br />
[In] <strong>and</strong> [Out] Parameter Types<br />
Parameters marked as [in] are not changed by the method. Parameters marked as [out] can be<br />
changed by the method. The exact parameter mechanism depends upon the <strong>programming</strong><br />
environment being used. For instance, in C++, all [out] parameters use pointers.<br />
Variant Methods<br />
A variant is a special data type that can represent values of many different types, such as<br />
integers, floats, Booleans, strings, or pointers. A variant represents only one type at a time. Some<br />
languages, such as Visual Basic, make extensive use of the variant data type. VBScript supports<br />
only variants.<br />
The OptoSnapIoMemMapX interface includes two versions of the most commonly used methods.<br />
The regular versions have parameters <strong>and</strong> return values that are strongly typed, with types such<br />
as long integer <strong>and</strong> float. The variant versions have parameters <strong>and</strong> return values of the variant<br />
type only, because some languages, such as VBScript, support only the variant data type. All<br />
variant-only methods start with the letter V.<br />
We recommend you use the non-variant methods whenever possible to provide the strong typing.<br />
Even though a parameter is a variant, the variant type must match that of the corresponding<br />
regular method. For example, the method VSetStatusOperation (VARIANT nOpCode) takes one<br />
parameter, nOpCode. The variable nOpCode must be a long integer at the time when<br />
VSetStatusOperation is called. In VBScript, use CLng() to force a variant to be a long integer.<br />
Example:<br />
gBrain2.VSetStatusOperation(CLng(OpCode))<br />
60 SNAP Ethernet-Based I/O Units Protocols <strong>and</strong> Programming Guide