Home
Up
Products
Surplus Parts
Specifications
How to Order
Terms and Conditions
Product Design
FAQ
Contact Us
Company
Press Release
Support
Software
International Sales

Visual Basic for Applications NETcomm Serial Port Software Example

We will continue the serial port control demonstration using the NETcomm.ocx driver.  After downloading the NETcommocx.zip file you need to unpack the file in a blank temp directory.  Click on setup.exe to install and register the files.  In windows explorer locate the netcomm.ocx file on your computer and copy this file into the c:\windows\system directory if the file is not already there.  Visual Basic for Applications may not find this file if it is not in this directory.

The NETcomm driver is a direct replacement for the mscoom32.ocx driver except for data input.  The mscomm32.ocx driver uses the command "input" to capture input data where netcomm.ocx driver uses "inputdata" to capture the same data.

Note: as stated before, this example is tailored to the first time Visual Basic for applications user, but the information is useful for the advanced user that is unfamiliar with serial port control.  Click here if you're familiar with VBA and want to jump directly to the code segment.

Our screen should show a blank user form as shown below where we had left off.

Now we are going to add serial port control to the control box so that we may use it in our application.

Right click in the controls box and select >> Additional Controls… Scroll down till you see the NETcommOCX.NETcomm Control, and click on the check box on the left, as shown below.

Click OK to continue.  The control box will now have an additional icon displayed in the controls window as shown below.

Select this control and place your cursor on the user form, click the left button and the control will be placed on the screen.

Click on the command button icon in the tool box (rectangular box) and place two buttons on the user form. Click on CommandButton1 and the options will appear in the properties window. Click to the right of the Caption in the properties window and change commandButton1 to "All Relays ON".  Click on the commandButton2 or select this name from the pull down at the top of the properties window, and change this to read "All Relays OFF" as shown in the picture below.

Click on the NETcomm icon or use the properties pull down menu to view the properties for this control as shown below.

Click on the property labeled RThreshold, change this value from a "0" to a "1".  Do the same for the SThreshold property. Everything else in this window can remain the same for this example. 

Note: If you need to read the port status on the board (which is not shown in this example) you need to change the InputMode property to "1-comInputModeBinary" by selecting the right pull down.

We are now finished with the configuration of the serial port and command buttons. The default settings are already set for com port 1, 9600 baud, 8 bits, no parity, and one stop bit.

From the menu at the top of the Visual Basic for Applications screen select View >> Code or press F7, and a code window will be displayed where the form currently resides.  Click in the following box and select the contents of the box by holding the left mouse button and dragging down over the contents.  Hold the Ctrl Button down and press "C'' to copy the contents to the clipboard.

Switch to Visual Basic for Applications and click inside the code window and highlight any information in this window -- press Ctrl "V" to paste the contents into the code window.  The window should now look like the following picture.

That's all the code that is required to turn all the relays ON and OFF on our relay boards, it will work on the 1, 2 & 8 Channel relay boards.  Select File >> Save Book1 from the pull down menu to save your project before you attempt to run the program.

All that's left to do is run our program, but first make sure the relay board is connected to com1 on the the back of your computer using the 9 pin serial to modular cable adapter.  Connect the modular cable from the adapter to the input of the relay board.  Plug the wall transformer cable into the board and the wall transformer into the wall receptacle or apply power to the board if your using the internal transformer version.

Assuming that everything is connected up properly, press the blue right arrow at the top of the screen and our program will run.  To stop the program click the box on the top right of the user form,  DO NOT close the program using the blue square box in the VBA editor.  If you would close the program using the blue box the serial port will not be closed properly, and it may not operate properly if you would restart the program.

The running program is shown below.

 Click the "All Relays ON" button and you will hear an audible click from the relays that is turning them ON and pressing the "All Relays OFF" button will turn them OFF.

Congratulations on your first Visual Basic For Applications control program using the Netcomm OCX driver.  We're sure you will find many practical applications for using your RS232 serial controlled relay board.

If you have any other questions you may contact the support dept at or you may request information using our feedback form.

[ Home ] [ Products ] [ Surplus Parts ] [ Terms & Conditions ] [ How To Order ] [ PDF Order Form ] [ HTML Order Form ]

Copyright © 2000-2009 Pencom Design, Inc. All rights reserved. Made in USA