
9.9 Sample Programs
162
Shown below is a sample program which uses VB2005 to enact RS-232C communication, set the
RM3542 measurement conditions, read measurement results and then save them to file. The sam-
ple program will be written in the following manner.
When the [ Begin Measurement ] is pressed, the RM3542 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 2005)
Creation Procedure (Visual Basic 2005) description
Write using sample program
Button created to begin measurement
Button1
Button created to close application
Button2
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)
'RM3542 settings
FileOpen(1, "data.csv", OpenMode.Output) 'Create text file to be saved ....................................................... (e)
For i = 1 To 10
sp.WriteLine("
FETCH?")
'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(":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
‘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
Summary of Contents for RM3542
Page 2: ......
Page 6: ...Contents iv ...
Page 16: ...Operating Precautions 10 ...
Page 26: ...1 3 Screen Organization 20 ...
Page 32: ...2 3 Turning the Power On and Off 26 ...
Page 46: ...3 8 Confirming Faulty Measurements 40 ...
Page 64: ...4 12 Compensating for Thermal EMF Offset Offset Voltage Compensation OVC 58 ...
Page 84: ...6 4 Auto Exporting Measured Values at End of Measurement Data Output Function 78 ...
Page 90: ...7 3 Printing 84 ...
Page 172: ...9 10 Device Compliance Statement 166 ...
Page 190: ...11 4 Disposing of the Instrument 184 ...
Page 200: ...Appendix 5 Dimensional Diagram A10 Appendix 5 Dimensional Diagram ...
Page 214: ...Index Index 4 ...
Page 215: ......
Page 216: ......
Page 217: ......
Page 218: ......