8.11 Creating Programs
248
Shown below is a sample program which uses VB2005 to enact RS-232C com-
munication, set the Models 3504-40, 3504-50, 3504-60 measurement condi-
tions, read measurement results and then save them to file. The sample program
will be written in the following manner.
8.11.1 "Creation Procedure" (p. 246)
description ..... Write using sample program
Button created to begin measuremen .......................................................Button1
Button created to close application ...........................................................Button2
When the [ Begin Measurement ] is pressed, the Models 3504-40, 3504-50,
3504-60 takes 10 measurements and writes the measurement values to a [
data.csv ] file.
When the [ Quit ] button is pressed the program closes.
The following program is written entirely in [ Form1 ] code.
8.11.2 Sample Programs
Imports System
Imports System.IO
Imports System.IO.Ports
Public Class Form1
‘
Perform process when Button1 is pressed
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim recvstr As String
Dim i As Integer
Try
Button1.Enabled = False
'
Disable buttons during communication
...................... (a)
Button2.Enabled = False
Dim sp As New SerialPort("COM1", 9600, Parity.None, 8, StopBits.One) '
Communication port setting
.... (b)
sp.NewLine = vbCrLf
'
Terminator setting
...........................................................(c)
sp.ReadTimeout = 2000
'
2 second time out
.......................................................... (d)
sp.Open()
'
Open port
SendSetting(sp)
'Models 3504-40, 3504-50, 3504-60
settings
FileOpen(1, "data.csv", OpenMode.Output)
'
Create text file to be saved
.......................................... (e)
For i = 1 To 10
sp.WriteLine("
*
TRG;:MEAS?") '
Begin measurement and read measurement
results command
............................................................ (f)
recvstr = sp.ReadLine()
'
Read measurement results
WriteLine(1, recvstr)
'
Write to file
Next i
FileClose(1)
'
Close file
sp.Close()
'
Close port
Button1.Enabled = True
Button2.Enabled = True
Catch ex As Exception
MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
End Try
End Sub
'
Set measurement conditions
Private Sub SendSetting(ByVal sp As SerialPort)
Try
sp.WriteLine(":HEAD OFF")
'
Header
: OFF
sp.WriteLine(":LEV 0.5")
'
Signal level
: 500 mV
sp.WriteLine(":FREQ 1E6")
'
Measurement frequency
: 1 MHz
sp.WriteLine(":TRIG EXT")
'
Trigger
:
external trigger
Catch ex As Exception
MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
End Try
End Sub
‘
Close program when Button2 is pressed
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
Me.Dispose()
End Sub
End Class
Содержание 3504-40 C HiTester
Страница 2: ......
Страница 22: ...1 4 Names and Functions of Parts 16 ...
Страница 28: ...2 5 Turning the Power On and Off 22 ...
Страница 40: ...3 3 Setting the Measurement Conditions 34 OF UF Evaluation Flow Chart ...
Страница 66: ...4 4 Self Calibration 60 ...
Страница 96: ...5 2 BIN Measurement Function Model 3504 50 3504 60 only 90 ...
Страница 136: ...7 4 About Measurement Times 130 ...
Страница 279: ...Appendix 5 External View Appendix A7 Appendix 5 External View Unit mm 220 3 260 1 100 1 32 5 25 21 54 20 5 95 5 15 ...
Страница 286: ...Appendix 7 Initial Settings Table A14 ...
Страница 289: ......
Страница 290: ......
Страница 291: ......
Страница 292: ......