Anritsu 0701012 User Manual

Page 54

Advertising
background image

Using the Demo Application

Sample Visual Basic Code

B-2

MA24106A UG

************************************************************************

// This sample program shows how to control Anritsu MA24106A USB power sensor using

//Microsoft Visual basic 6.0

Option Explicit

Public gstrInputBuffer As String

'Event handler for InitializeComPort button

Private Sub btnInitializeComPort_Click()

Call SetCommPort(Val(Trim(txtCOMPORTNo.Text)))

End Sub

'Subroutine to set the com port

Public Sub SetCommPort(portNo As Integer)

On Error GoTo errHndler

'Setup MSComm control

MSComm1.Settings = "115200,n,8,1"

MSComm1.CommPort = Trim(txtCOMPORTNo.Text)

MSComm1.PortOpen = True

MSComm1.RThreshold = 1

MSComm1.SThreshold = 1

'

'Wait for half a second before sending START command

Delay (0.5)

'Arm sensor to start making measurements

txtCommand.Text = "START"

Call btnSend_Click

'

Exit Sub

errHndler:

MsgBox ("ERROR: " & Err.Description)

End Sub

'Event handler for ResetComPort button

Private Sub btnResetComPort_Click()

'Close com port

If MSComm1.PortOpen = True Then

MSComm1.PortOpen = False

End If

End Sub

'Event handler for Send button

Private Sub btnSend_Click()

Dim strResult As String

'Clear buffer & receive text window before sending command

gstrInputBuffer = ""

txtReceived.Text = ""

'Send command and appeand Termination character, 0x0A(10)with it.

MSComm1.Output = UCase(txtCommand.Text) & Chr(10)

'Display received result on the Received text box

txtReceived.Text = strResult

'

End Sub

Advertising
This manual is related to the following products: