EasyManua.ls Logo

Hioki 3560 - Sample Programs (Visual Basic 2005)

Hioki 3560
156 pages
To Next Page IconTo Next Page
To Next Page IconTo Next Page
To Previous Page IconTo Previous Page
To Previous Page IconTo Previous Page
Loading...
98
────────────────────────────────────────────────────
7.7 Sample Program
────────────────────────────────────────────────────
7
.7.4 Sample Programs (Visual Basic 2005)
Shown below is a sample program which uses VB2005 to enact RS-232C
communication, set the 3560 measurement conditions, read measurement
results and then save them to file. The sample program will be written in
the following manner.
7.7.3 Creation Procedure (Visual Basic 2005) (Page 96) description
Write using sample program
Button created to begin measuremen
Button1
Button created to close application
Button2
When the [ Begin Measurement ] is pressed, the 3560 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.
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) ’3560 settings
FileOpen(1, "data.csv", OpenMode.Output)’Create text file to be saved (e)
Fori=1To10
sp.WriteLine(":MEAS:BATT?") ’Begin read measurement results
command (f)
recvstr = sp.ReadLine() ’Read measurement results
PrinteLine(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

Table of Contents

Related product manuals