Private Sub AQ637XTEST()
Dim intData As Integer
Dim dblMeanWL As Double
Dim dblSpecWd As Double
Dim strData As String
' === Connect ===
Winsock1.RemoteHost = "192.168.1.100"
Winsock1.RemotePort = 10001
Winsock1.Connect
' === Wait to connect complete ===
While (Winsock1.State <> sckConnected)
DoEvents
Wend
' === Authentication by OPEN Command ===
SendLan "open ""anonymous"""
ReceiveLan strData
SendLan " "
ReceiveLan strData
If (Left(strData, 5) <> "ready") Then
MsgBox "User authentication error."
Exit Sub
End If
' === Set the measurement parameter ===
SendLan "*RST"
SendLan "CFORM1"
SendLan ":sens:wav:cent 1550nm"
SendLan ":sens:wav:span 10nm"
SendLan ":sens:sens mid"
SendLan ":sens:sweep:points:auto on"
' === Sweep execute ===
SendLan ":init:smode 1"
SendLan "*CLS"
SendLan ":init"
' === Wait for sweep complete ===
Do
SendLan ":stat:oper:even?"
ReceiveLan strData
intData = Val(strData)
Loop While ((intData And 1) <> 1)
' === Analysis ===
SendLan ":calc:category swth"
SendLan ":calc"
SendLan ":calc:data?"
ReceiveLan strData
' === Capture analytical results ===
dblMeanWL = Val(Left(strData, 16))
dblSpecWd = Val(Mid(strData, 18, 16))
' === Output the result to the screen ===
MsgBox ("MEAN WL: " & dblMeanWL * 1000000000# & " nm" & vbCrLf & _
"SPEC WD: " & dblSpecWd * 1000000000# & " nm")
' === Disconnect ===
Winsock1.Close
While (Winsock1.State <> sckClosed)
DoEvents
Wend
End Sub
'==================================================
' Sub routine
' Send Remote Command
'==================================================
Sub SendLan(strData As String)
Winsock1.SendData strData & vbCrLf' 命令后面跟换行符
DoEvents
End Sub
'==================================================
' Sub routine
' Receive query data
'==================================================
Sub ReceiveLan(strData As String)
Dim strData2 As String
strData = ""
Do
Winsock1.GetData strData2, vbString
strData = strData + strData2
DoEvents
' vbLf换行
Loop While (Right(strData, 1) <> vbLf)
End Sub
Dim intData As Integer
Dim dblMeanWL As Double
Dim dblSpecWd As Double
Dim strData As String
' === Connect ===
Winsock1.RemoteHost = "192.168.1.100"
Winsock1.RemotePort = 10001
Winsock1.Connect
' === Wait to connect complete ===
While (Winsock1.State <> sckConnected)
DoEvents
Wend
' === Authentication by OPEN Command ===
SendLan "open ""anonymous"""
ReceiveLan strData
SendLan " "
ReceiveLan strData
If (Left(strData, 5) <> "ready") Then
MsgBox "User authentication error."
Exit Sub
End If
' === Set the measurement parameter ===
SendLan "*RST"
SendLan "CFORM1"
SendLan ":sens:wav:cent 1550nm"
SendLan ":sens:wav:span 10nm"
SendLan ":sens:sens mid"
SendLan ":sens:sweep:points:auto on"
' === Sweep execute ===
SendLan ":init:smode 1"
SendLan "*CLS"
SendLan ":init"
' === Wait for sweep complete ===
Do
SendLan ":stat:oper:even?"
ReceiveLan strData
intData = Val(strData)
Loop While ((intData And 1) <> 1)
' === Analysis ===
SendLan ":calc:category swth"
SendLan ":calc"
SendLan ":calc:data?"
ReceiveLan strData
' === Capture analytical results ===
dblMeanWL = Val(Left(strData, 16))
dblSpecWd = Val(Mid(strData, 18, 16))
' === Output the result to the screen ===
MsgBox ("MEAN WL: " & dblMeanWL * 1000000000# & " nm" & vbCrLf & _
"SPEC WD: " & dblSpecWd * 1000000000# & " nm")
' === Disconnect ===
Winsock1.Close
While (Winsock1.State <> sckClosed)
DoEvents
Wend
End Sub
'==================================================
' Sub routine
' Send Remote Command
'==================================================
Sub SendLan(strData As String)
Winsock1.SendData strData & vbCrLf' 命令后面跟换行符
DoEvents
End Sub
'==================================================
' Sub routine
' Receive query data
'==================================================
Sub ReceiveLan(strData As String)
Dim strData2 As String
strData = ""
Do
Winsock1.GetData strData2, vbString
strData = strData + strData2
DoEvents
' vbLf换行
Loop While (Right(strData, 1) <> vbLf)
End Sub