
8.8 Sample Programs
160
Shown below is a sample program which uses Visual Basic
®
2017 to enact RS-232C communication, set the
measurement conditions, read measurement results and then save them to file. The sample program will be
written in the following manner.
Button created to begin measurement .....................................................Start
Button created to close application ........................................................... Exit
When the [ Begin Measurement ] is pressed, 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.
Sample Programs (Visual Basic
®
2017)
Imports System
Imports System.IO
Imports System.IO.Ports
Public Class Form1
'Perform process when Button1 is pressed
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Dim recvstr As String
Dim i As Integer
Try
Button1.Enabled = False
'Disable buttons during communication......(a)
Button2.Enabled = False
'Communication port setting.......................(b)
SerialPort1.PortName = "COM1"
SerialPort1.BaudRate = 9600
SerialPort1.DataBits = 8
SerialPort1.Parity = Parity.None
SerialPort1.StopBits = StopBits.One
SerialPort1.NewLine = vbCrLf
'Terminator setting......................(c)
SerialPort1.ReadTimeout = 2000
'2 seconds time out.....................(d)
SerialPort1.Open()
'Open a port
SendSetting(SerialPort1)
'Instrument settings
FileOpen(1, "data.csv", OpenMode.Output)
'Create text file to be saved.........(e)
For i = 1 To 10
SerialPort1.WriteLine(":FETCH?")
'Begin measurement and read measurement results Command....(f)
recvstr = SerialPort1.ReadLine()
'Read measurement results
WriteLine(1, recvstr)
'Write to file
Next
FileClose(1)
'Close file
SerialPort1.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(":TRIG:SOUR IMM"
'Select internal triggering
sp.WriteLine(":INIT:CONT ON")
'Continuous measurement ON
Catch ex As Exception
MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
End Try
End Sub
HIOKI BT3564A961-02
Summary of Contents for BT3564
Page 2: ...HIOKI BT3564A961 02...
Page 44: ...3 7 Displaying Measurement Results 38 HIOKI BT3564A961 02...
Page 80: ...4 12 Reset Function 74 HIOKI BT3564A961 02...
Page 98: ...6 3 Printing 92 HIOKI BT3564A961 02...
Page 170: ...8 8 Sample Programs 164 HIOKI BT3564A961 02...
Page 182: ...10 3 Error Indication 176 HIOKI BT3564A961 02...
Page 202: ...Appendix 11 Dimensional Diagram A20 HIOKI BT3564A961 02...
Page 206: ...Index 4 HIOKI BT3564A961 02...
Page 207: ...HIOKI BT3564A961 02...
Page 208: ...HIOKI BT3564A961 02...
Page 209: ...HIOKI BT3564A961 02...
Page 210: ...HIOKI BT3564A961 02...