在熟悉了SCPI的语法后,现在开始着手编写上位机程序。正如Guide文件所言,上位机可以用多种语言编写。然而为了借鉴学长的VB程序,所以我也用了VB这种号称已经要被淘汰的语言。
1、在安装IO library时会默认安装一个VISA库(名为VISA COM 5.9 Type Library)。在项目里引用它。
2、拖拉控件,创立事件等。不必细说。随意的画了一个这样的界面:
3、建立电脑与仪器的通信!
在使用USB连接的情况下,关键代码如下:
(函数外已声明, Public ESG As Ivi.Visa.Interop.IFormattedIO488)
Dim RM As Ivi.Visa.Interop.ResourceManager
Dim response As String
Dim vRes() As String
RM = New Ivi.Visa.Interop.ResourceManager
ESG = New Ivi.Visa.Interop.FormattedIO488
Try
ESG.IO = RM.Open(Visa_Address_TextBox.Text)
ESG.WriteString("*RST")
ESG.WriteString("*IDN?") 'IDN语句后也需要读出返回值,否则出错
response = ESG.ReadString
Connect_Status.Text = "设备已连接"
Connect_Status.ForeColor = Color.Red
Connect_Status.Update()
Visa_Address_TextBox.ReadOnly = True
Exit Sub
Catch ex As Exception
Connect_Status.Text = "连接失败"
MsgBox("连接超时:" & Err.Description)
End Try
创立ResourceManager对象和FormattedIO488对象,并调用IO方法。
4、编写控制代码:
Try
Dim Sine_VPP As String
ESG.WriteString(":MEASURE:VPP? CHANNEL1") ' Query for Pk to Pk voltage.
Sine_VPP = ESG.ReadNumber ' Read VPP.
VPP_Text.Text = Sine_VPP
Dim Sine_Frequency As String
ESG.WriteString(":MEASure:FREQuency? CHANNEL1") ' Query for Pk to Pk voltage.
Sine_Frequency = ESG.ReadNumber ' Read VPP.
Frequency_Text.Text = Sine_Frequency
Catch ex As Exception
MsgBox("尚未连接设备!")
用FormattedIO488的WriteString方法以及ReadNumber方法即可。值得注意的是,ReadNumber方法返回的似乎也是String类型。
5、执行效果:(直流偏置还没有做,所以空着)