Hidden Hidden Hidden Hidden
 
 

PROGRAMMING OVERVIEW
PROGRAMMING > GETTING STARTED >

An instruNet data acquisition system is controlled with one main subroutine, called iNet(), that is callable from C, C++ or Visual Basic.  The actual iNet() code resides in the instruNet iNet32.dll Driver file that is automatically installed during instruNet Software Installation. For details on what is compatible with what, see instruNet Compatibility

iNet() Function Call
The iNet() function includes 7 parameters that specify a field in the network hierarchy that is to be read or written to, as shown below:

iNetUINT8 netNum
NETWORK number = {0...numNetworks}, 0 is Driver, 1 is 1st Controller installed into the computer, 2 is the 2nd Controller, etc.

iNetUINT8 deviceNum
DEVICE number {0...numDevices}, 0 = "Controller", 1 = 1st device on net...

iNetUINT8 moduleNum
MODULE number within a hardware DEVICE {1...32}. Each DEVICE can contain up to 32 separate modules.  Many devices have only 1 module.

iNetUINT8 chanNum
Hardware CHANNEL number {1...32}. Each device contains a number of channels (i.e. signals that are accessed//via a screw terminal or connector), each of which has its own channel #.

iNetINT16 fieldGroupNumOrType
If > 0, this is a field Group Number {1...numFieldGroups}.  if < 0, this is a field Group Type.

iNetINT16 fieldNum
Field number within the fieldGroup of the CHANNEL.

iNetUINT8 intention
ion_intention = {intention_getValue, intention_setValue, intention_getNameStr, intention_getMaxValue}

iNetUINT8 argType
argument type {int16, int32, str15, etc}(void *ptrToArg) this is where data is kept (we read or write to this location).

These parameters specify a field, such as the cut-off frequency of a low pass filter, the sample rate, or the actual real-time value of a channel.  This function can both read from and write to any field on the network.  For a description of each field, please refer to Settings Reference.  One uses iNet() to both set up the networks, and then do I/O with the various channels.  Also, iNet() can be used to tell the instruNet Controllers to digitize, and then download the digitized data into computer memory.  iNet() is extremely powerful -- it can even open the instruNet World window and turn over control to the user.

Simple Format Functions
There are also a collection of Simple Format functions that read and write instruNet fields using a structure that specifies a channel address {netNum, deviceNum, moduleNum, chanNum}. This structure ("User Defined Variable Type" if in Visual BASIC) is defined as follows:

typedef struct iNetChannelAddr {

iNetUINT8 netNum;
NETWORK number = {0...numNetworks}, 0 is Driver, 1 is the first controller installed into the computer.

iNetUINT8 deviceNum;
DEVICE number = {0...numDevices}, 0 = "Controller", 1 = 1st device on network.

iNetUINT8 moduleNum;
MODULE number within hardware DEVICE {1-32}.  Many devices have only 1 module.

iNetUINT8 chanNum;
Hardware CHANNEL number {1...32}. Each device contains a number of channels, each of has which its own channel number.

} iNetChannelAddr;                                            

To read or write an instruNet field with a Simple Format function, one must first load an iNetChannelAddr structure with the netNum, deviceNum, moduleNum, chanNum.  This is often done with the LoadChannelAddress() routine:

LoadChannelAddress()
Specify an instruNet channel address.

After the structure is loaded (it holds the netNum, moduleNum, deviceNum, chanNum information), one can then read or write an instruNet field with any of the following routines:

SetField_int32()
Set instruNet field with 32bit signed integer number.

SetField_uint32()
Set instruNet field with 32bit unsigned integer number.

SetField_flt32()
Set instruNet field with 32bit floating point number.

SetField_cStr()
Set instruNet field with C string (terminated with 0x00).

GetField_int32()
Read instruNet field into a 32bit signed integer variable.

GetField_uint32()
Read instruNet field into a 32bit unsigned integer variable.

GetField_flt32()
Read instruNet field into a 32bit floating point variable.

GetField_cStr()
Read instruNet field into a C string variable (terminated with 0x00).

For example, the following C code would read the real-time value of Channel 1 at Device 1, Module 1, Network 1:

iNetChannelAddr vin;
iNetFLT32 V;
iNetError e;

LoadChannelAddress(&vin, 1, 1, 1, 1);

V = GetField_flt32(&vin,sgt_General,fldNum_General_valueEu,&e);

Digitizing
There are several routines, summarized below, that are used to simultaneously digitized channels to ram or to disk, as described in C file INET_INT.C and Visual BASIC file INET_Common_Code.bas.

EnableChannelForDigitizing() 
Mark this channel for digitizing (i.e. when digitizing is started).

DisableAllChannelsForDigitizing()
Disable all channels for digitizing.

Set_iNet_TIMING_Parameters_32or64()
Set digitize timing parameters (e.g. sampleRate, ptsPerScan, etc).

Set_iNet_TRIGGER_Parameters()
Set digitize trigger parameters (e.g. trigger on/off, trigger source).

Service_All_iNet_Digitize_Buffers_32or64()
Services internal buffers while digitizing.

Access_Digitized_Data_In_Ram_Buffer_32or64()
Provides access to digitized data (even during acquisition).

Simple digitizing is illustrated nicely in Example#2.  In summary, to digitize, one must:

1.   Call DisableAllChannelsForDigitizing() to disable all channels for digitizing.

2.   Specify which channels are to be digitized by calling LoadChannelAddress() and EnableChannelForDigitizing() for each digitize channel.

3.   Specify timing parameters (e.g. sample rate) with Set_iNet_TIMING_Parameters_32or64().

4.   Specify trigger parameters with Set_iNet_TRIGGER_Parameters().

5.   Tell the instruNet driver to start digitizing with PRESS_iNet_BUTTON( iNetCM_BtnPress_Record_Start ).

6.   Periodically (e.g. 4 times per second) call Service_All_iNet_Digitize_Buffers_32or64() to provide the instruNet Driver time to service internal buffers (this is mandatory).

7.   Call Access_Digitized_Data_In_Ram_Buffer_32or64() to access digitize data for each channel.

Support Functions
Additional functions defined and described in C file INET_INT.C, and in Visual BASIC file INET_Interface.bas, are listed as follows:

UTILITY FUNCTIONS

iNet_Peek_int16()
Reads 16bit integer number from a specific logical address.

iNet_Peek_int32() 
Reads 32bit integer number from a specific logical address.

iNet_Peek_flt32()
Reads 32bit floating point number from a specific logical address.

iNet_Poke_int16()
Writes 16bit integer number to a specific logical address.

iNet_Poke_int32()
Writes 32bit integer number to a specific logical address.

iNet_Poke_flt32()
Writes 32bit floating point number to a specific logical address.

iNet_Get_VarPtr()
Returns a pointer to the passed variable.

iNet_memcopy()
Copies memory block from one place to another.

ADVANCED FIELD READ/WRITE ROUTINES

iNet_int32()
Reads or writes to a field via a 32bit signed integer variable.

iNet_uint32()
Reads or writes to a field via a 32bit unsigned integer variable.

iNet_flt32()
Reads or writes to a field via a 32bit floating point variable.

iNet_cString()
Reads or writes to a field via a C string variable.

iNet_pString()
Reads or writes to a field via a Pascal string variable.

iNet_DLL()
Reads or writes to a field via any type of variable.

DRIVER ROUTINES   

Load_instruNet_Driver()
Loads instruNet driver into memory.

CloseDriverAndReleaseDriverRam()
Closes instruNet driver and releases memory.

Show_ALERT_if_hit_iNet_Error()
Shows an alert if instruNet hit an error.

Show_Simple_Alert()
Displays a message in an alert dialog box.

Get_iNet_Error()
Gets error code to last instruNet function call.

Get_Last_iNet_Call()
Returns pointer to struct with params to last iNet call.

Interface Files
The instruNet disk includes interface files for C and Visual BASIC that enable your program to call the above listed functions.  No compiler object files are used; therefore, you are not at the mercy of a specific version of a specific compiler on a specific computer.  Instead, you simply add the following glue source code to your program:

VB Files C Files Interface Description
INET_Interface.vb INET_INT.C Contains low level source code that interfaces to the instruNet driver.
INET_Declarations.vb INET_INT.H Contains many low level enums and #defines that support instruNet.
INET_Macros.vb INET_MCS.H Contains macros that help set/read instruNet fields.

Every instruNet C program must include the following files: INET_INT.C, INET_INT.H, and INET_MCS.H.

Every instruNet Visual BASIC program must include the following files: INET_Interface.vb, INET_Common_Code.vb, INET_Declarations.vb, and INET_Macros.vb.

Programming Examples
The instruNet disk includes example programs in Visual BASIC and C. The C Example #1 and VB Example #1 do the same thing, yet just in different languages.  In fact, they do many of the same things that are done in Tutorial.  For example, one is asked to turn on a low pass filter by selecting a popup menu.  Example#1 will do the same thing with the iNet() function call.  With instruNet, each task can be done automatically under program control, or manually in the instruNet World window.  This will become more clear as you work with the example programs.  The instruNet disk includes the following example programs:

C Files VB Files Example Description
INET_EX1.C EndUser Example1.sln This is a lengthy and comprehensive example that shows how to call almost every instruNet function in a text window-based environment.
INET_EX2.C EndUser Example1.vb This is a simple example that shows how to read and write instruNet fields and how to digitize.

 

instruNet Data Types

instruNet defines its own data types that allow you to keep your code platform, machine, and operating system independent.  instruNet data types are defined in the file INET_INT.H.  An example of an instruNet data type definition is:

typedef unsigned short iNetUINT16;  /* 16bit unsigned integer */

Always use instruNet data types when calling the instruNet driver and macros. This website uses the following labels to refer to variable types:

iNetINT8       signed 8bit integer, -128 to +127.

iNetUINT8      unsigned 8bit integer, 0 to +255.

iNetINT16      signed 16bit integer, -32768 to +32767.

iNetUINT16     unsigned 16bit integer, 0 to +65536.

iNetINT32      signed 32bit integer, -2.147e9 to +2.147e9

iNetUINT32     unsigned 32bit integer, 0 to +4,294,967,295.

iNetINT64      signed 64bit integer, -9e18 to +9e18.

iNetUINT64     unsigned 64bit integer, 0 to 1.8e19.

iNetFLT32      32bit floating point number

instruNet Macros

instruNet defines a number of macros for the more common driver calls.  The macros are defined in file INET_MCS.H.  The macros are platform, machine and operating system independent.  An example of a macro call is:

OPEN_instruNet_WINDOW( instruNetCM_OpenWindow_Network );

which when called will open the Network Page of instruNet.  The Network Page could also have been opened by directly calling the instruNet C function:

iNet(netNum_DRIVER, deviceNum_CONTROLLER, moduleNum_1stModule,  driver_ChanNum_OpenWindow, sgt_General, fldNum_General_valueEu, intention_setValue, instruNetDT_INT16, (void *) ((gINT16TempArg = specificPage) ? &gINT16TempArg : &gINT16TempArg));

Example Code

Example#1 does the following things using the instruNet interface functions. C source code is shown in Courier font.

1.   Load instruNet Driver

The C code below calls Load_instruNet_Driver() to load the instruNet Driver, and to get the number of installed controller cards.  If the driver does not load properly, an error is returned and Show_ALERT_if_hit_iNet_Error() displays a dialog box with an error code.  If this occurs, please see Troubleshooting.

iNetError e;
iNetINT16 driverIsInstalledOK, numNetworks;
e = Load_instruNet_Driver(TRUE /* reset_instruNet */,
&driverIsInstalledOK, &numNetworks);
if (e != iNetErr_None)  {
Show_ALERT_if_hit_iNet_Error(e);  return 0;  }

2.   Tell the instruNet Driver to open the Network Page Window

The C code below tells the driver to open the Network Page Window.  From the Network Page, fields can be viewed and set following the procedures in Tutorial .  If a non zero error code is returned the program will jump to an exit routine.

if (e = OPEN_instruNet_WINDOW( instruNetCM_OpenWindow_Network )) { goto Exit; }

3.   Read several voltage inputs and set a voltage output

The next few lines of code read several voltage inputs and write to a voltage output.  They assume a Model 100 is attached to the 1st network controller card.

4.   Print the values for the first 5 channels on instruNet

The C code below calls the function Print_iNet_Channels() which reads one value from each of the first five input channels of an instruNet Network, and prints them to the console window. The function call is defined in file INET_EX1.C.

if (e = Print_iNet_Channels(5)) { goto Exit; }

6.   Print the first 3 Fields

The C code below calls the function Print_iNet_Fields() which scans the network and prints the values of the first 5 fields that it finds.  The function call is defined in file INET_EX1.C

if (e = Print_iNet_Fields(3)) { goto Exit; }

7.   Read and write instruNet Fields

The C code below calls the function ReadWriteFields_iNet()prompts the user for a field address, displays the current value of the field and allows the user to change the field value.  The function call is defined in the program INET_EX1.C.

if (e = ReadWriteFields_iNet()) { goto Exit; }

8.   Digitize some analog input channels

The C code below calls the function SimultaneouslyDigitizeAndAnalyze() which digitizes several channels.  When writing code that acquires data seamlessly it is important to continuously call  Service_All_iNet_Digitize_Buffers_32or64() while the data acquisition is running.  This function call is defined in the file Example#1 file.

if (e = SimultaneouslyDigitizeAndAnalyze()) { goto Exit; }

9.   Modify the Example source code to meet your own needs.

Tutorial Summary

In summary, the Programming Tutorial will involve the following steps:

1.   Make sure you have done Tutorial in its entirety.

2.   Install your programming environment on your hard disk, load an example program shipped with your Programming Language, compile, and then run to verify that your Programming Environment is set up properly.

3.   Create a new Folder/Directly on your hard disk.  Make a copy of the instruNet example program and place it into this folder, along with include files.

4.   Compile and link the code.  If you have any compile or link errors, please use the source code to debug the system -- all source code is provided.

5.   Run the example programs to verify that the compiler, example files, driver, and computer are all working well together.

6.   Read the example program source code and comments to get a feel for instruNet programming.