Have you ever wanted to transfer data from the real world into Visual Basic or other programming languages? The NetPorter DAQ ActiveX DLL allows you to easily incorporate data from the NetPorter DAQ into any program that can handle ActiveX DLLs. When used with the NetPorter DAQ, you are free to use the ActiveX DLL for any application.
NetPorter DAQ ActiveX can also interface with almost any serial device and is free for personal, non-commercial use. It is easy to make a Basic Stamp or any microcontroller output data in the same format that NetPorter uses (namely, ASCII strings in the form VARIABLE=VALUE).
You'll need to download the ActiveX DLL and install it. You'll also need Visual Basic and the MSCOMM32 control if you actually want to build the example code.
Here's a screen shot of the program in the examples.zip file you receive with the NetPorter DAQ software download:
In this case, the program simply display 3 of the values the DAQ sends. However, you could do any amount of custom processing with the data.
There are three required steps for using the ActiveX DLL, and two optional ones:
You must create an object of type AWCNetPorter.NetPorter
You pass any serial input to the objects' CommData subroutine -- the data need not be single lines or even entire lines, just raw data
Call the object's GetVar function when you want to retrieve the latest data
So in the above picture, obj.GetVar("A0") is returning "144". The program doesn't care if the data is numeric or not, although with the NetPorter DAQ, the data is always numeric.
The two optional steps are to include subroutines of your own to preprocess lines of data, and to receive notifications when a data item changes. If you provide these routines, you have to tell the object about it. Let's defer how that works, until you've mastered the basics. I'll call these two items step 4 and 5.
If you are using Visual Basic, you'll need to add a reference to AWCNetPorter (use Project | References on the menu bar). If you can't find it, you haven't installed the DLL on this computer. Run the setup program and try again.
Once the reference is in place, you can simply write:
Dim NetPorter As New AWCNetPorter.NetPorter
Now you have an object called NetPorter and it is ready to do the work.
Since everyone has different serial requirements, the DLL allows you to receive data from the serial port (or any other source of data, for that matter). It handles breaking the input into lines and parsing it for assignments. You don't have to send the DLL complete lines -- it will build them from the incoming data stream. You can also send the DLL multiple lines and it will correctly handle them.
The example program uses the MSCOMM32 library set for 19,200 baud. The callback function for MSCOMM32 looks like this:
Private Sub MSComm1_OnComm() If MSComm1.CommEvent = comEvReceive Then ' Pass all serial data to NetPorter module NetPorter.CommData (MSComm1.Input) End If If MSComm1.CommEvent >= 1000 Then Recon_Click ' try to recover from an error End If End Sub
This simply passes all received data to the NetPorter object. If there is an error (the event code is >1000) the program reconnects to attempt to clear the error.
Reading the data is simple. Here's an example of reading A0:
If you supply a variable name that the object doesn't know about (maybe it hasn't read it yet) you'll get an empty string in return.
If you like, you can have the object call you with each line it processes. You can then change the line in any way you see fit. You don't have to provide this callback function if you don't need it. If you do provide it, it must look like this:
Public Function ProcessLine(l As String) As String ' For this example, we will change D0 into hex format just to show how If Left(l, 3) = "D0=" Then ProcessLine = "D0=" & Hex(Val(Mid(l, 4))) Else ProcessLine = l ' pass it along if we don't care End If End Function
This example function looks to see if the line is in the form D0=XXX. If it is, the code changes XXX to hexadecimal and then passes it back to the object for processing. Note that if the function exists and doesn't want to change anything, it must return the line unchanged. Returning an empty line will prevent the object from processing any data for this input.
To activate this feature, you must set the object's Callback property to the object that contains the ProcessLine function. Here's a portion of the example program's Form_Load handler:
Set NetPorter.Callback = Me ' Register myself to listen for ProcessLine
If you aren't familiar with Visual Basic, the Set keyword assigns object references and Me is similar to a this pointer -- it refers to the current object.
You can also supply a subroutine the object will call when any data changes. It calls with the variable that changed as an argument. Here's a snippet from the example code. It tries to find a label control on the form with the same name as the variable and just plugs the data into the control as-is. Of course, you could do anything -- this is simply an example.
Public Sub OnChangeData(k As String) On Error Resume Next ' in case we get garbage! Me.Controls(k).Caption = NetPorter.GetVar(k) Status.Caption = "Data received " & Now End Sub
Notice the code also updates the time and date in the Status control. You could even store the last change time for each variable if that was important for your application.
Site contents © 1997-2018 by AWC, Houston TX (281) 334-4341