Serial Port Tool focuses on COM Port communication software for RS232 related works.
Sample for Using NCDProXR Control in Visual Basic 2008

Visual Basic is our preferred language for communicating to the NCD product line. Visual Basic 2008 is an evolution of the Visual Basic language that is engineered for productively building type-safe and object-oriented applications.The Visual Basic 2008 Express Edtion is free download from Microsoft. If you are a programmer of VB6 or VB2005, it is easy to switch to Visual Basic 2008.

The following guide will teach ANYONE how to operate ProXR using NCDProXR Control in Visual Basic 2008 Express Edition. The example provided on this page is developed for Visual Basic 2008 Express Edition. These directions are about 99% compatible with other VS2008 edition which include VB. Follow these simple steps and you will be on your way to controlling ProXR from your desktop computer in 30 minutes or less.

If you have questions, please contact us.

 

Step 1: Create a New Project
  • Open Microsoft Visual Basic 2008 Express Edition. The following screen appears.

 

  • On the File menu, click NewProject.
  • The New Project dialog box opens as below.
  •  Select Windows Application .
  • Input project Name.

  • Click "OK" to get the new project.

 

Step 2: Add NCDProXR Control to the Project
  • Right click the mouse within Toobox window to show popup menu as below.(If the Toolbox window is not shown. You can open it by clicking menu View|Toolbox.)

  • Click Choose Items to open the following window.

  • Click Browse to show the open window as below.
  • Look in C:\Program Files\NCD\ProXR to find the file NCD.ProXR.dll. (If it does not appear in this location, you need to install the NCDProXR Control before you open Visual Basic 2008.)

  • Click Open to return to the Choose Toolbox Items window. The NCDProXR Control will be found in the list.

  • Click OK to add NCDProXR Control to the Toolbox.

  • Drag NCDProXR Control onto frame Form1 to add NcdProXR1 for the Form1.(If the properties window is opened, the properties of NcdProXR1 will be shown on the right window.)

 

Step 3: Add Other Controls to the Project
  • Drag GroupBox control from Toolbox onto frame Form1 to add GroupBox1.
  • In the Properties window, select the Text property of the GroupBox1. In the right-hand column, delete GroupBox1 and replace it with Turn ON/OFF Relay.

  • Add GroupBox2 and GroupBox3 into GroupBox1.
  • In the properties window,select the Text property, replace GroupBox2 and GroupBox3 with Relay1 and Relay2 respectively, shown as below.

  • Drag Button control from Toolbox into GroupBox Relay1 and Relay2 to add Button1 and Button2.
  • In the properties window,select the Text property, replace Button1 and Button2 with OFF.
  • This two buttons will be used as swich to turn on or turn off Relay1 and Relay2.

  • Following above steps to add GroupBox4(Read Relay Status), GroupBox5(Relay1), GroupBox6(Relay2), Button3(Read) and Button4(Read).
  • Drag Label control from Toolbox upto button Read to add Label1and Label2.
  • This two labels will be used to display the status of Relay1 and Relay2.
  • Since the status of Relays is not sure, replace Label1 and Label2 with ??? in the Text property, show as below. (You may resize the controls or Form1 according to your favourites.)

 

Step 4: Type Code to the Program
  • In the Form1.vb[ Designer], double click anywhere on the frame Form1 to open the file Form1.vb.
  • Type the following code to open the serial port and select bank 1at where the cursor is.

    NcdProXR1.OpenPort()

    NcdProxR1.SelectBank(1)

  • After typing NcdProXR1. , the method list of NcdProXR Control will appear as below. You can select OpenPort in the list or type it directly.

  • You may hide Toolbox window and Properties window to get more room to show code as below.

 

  • Return to the Form1.vb[ Designer], double click Button1.
  • Type following code at where the cursor is.
  • If Button1.Text = "OFF" Then

    NcdProXR1.TurnOffRelay(1)

    Button1.Text = "ON"

    Else

    NcdProXR1.TurnOnRelay(1)

    Button1.Text = "OFF"

    End If

  • Return to the Form1.vb[ Designer], double click Button2.
  • Type following code at where the cursor is.

    If Button2.Text = "OFF" Then

    NcdProXR1.TurnOffRelay(2)

    Button2.Text = "ON"

    Else

    NcdProXR1.TurnOnRelay(2)

    Button2.Text = "OFF"

    End If

  • You also can find TurnOnRelaly and TurnOffRelay in the method list of NcdProXR Control.

  • Return to the Form1.vb[ Designer], double click Button3.
  • Type following code at where the cursor is.

    Dim Status As Long

    Status = NcdProXR1.GetStatus(1)

    If Status = 0 Then

    Label1.Text = "OFF"

    Else

    If Status = 1 Then

    Label1.Text = "ON"

    Else

    MessageBox.Show("Can not Read the Status!")

    End If

    End If

  • Return to the Form1.vb[ Designer], double click Button4.
  • Type following code at where the cursor is.

    Dim Status As Long

    Status = NcdProXR1.GetStatus(2)

    If Status = 0 Then

    Label2.Text = "OFF"

    Else

    If Status = 1 Then

    Label2.Text = "ON"

    Else

    MessageBox.Show("Can not Read the Status!")

    End If

    End If

  • You also can find GetStatus in the method list of NcdProXR Control.

 

Step 5: Run the project
  • On the Debug menu of the Visual Basic2008, click Start Debugging.( A shortcut to run the program is to press F5.)
  • The result of running the program is displayed as below.
  • Now, you can turn on or turn off Relay1 and Relay2 using this applicationprogram. You also can read the status of Relay1 and Relay2.

 

Above is a simple sample of using NCDPorXR Control in VB 2008. Based on those steps, more buttons can be added to meet your requirement.

Here, a more detial ProXR Sample is given. The framwork of this example is show as below.

 

 

 

Download VB2008 NCDProXR Control Sample Program

Download VB2008 NCDProXR Control ProXRSample1 Program

Download VB2008 NCDProXR Control ProXRSample2 Program

Note: the diffrence between ProXRSample1 and ProXRSample2 is that the code in ProXRSample2 has been optimized.

See How to Use NCDProXR Control in Visual Basic 2008