6/26/2010
920‐0032a3eSCLCommunicationReferenceManual Page19
mustspecifytheprotocolasTCP,choosealocalportnumber,andsettheremoteIPaddressandportnumber
tomatchthedrive.Inthecodeexamplebelow,7776istheportofthedrive.driveIPaddressistheIPaddress
ofthedrive(“10.10.10.10”or“192.168.0.130”forexample).
Winsock1.RemotePort = 7776
Winsock1.RemoteHost = driveIPaddress
Winsock1.Protocol = sckTCPProtocol
Sending“RV”command:
Dim myPacket(0 to 4) as Byte ‘ declare a byte array just large enough
myPacket(0) = 0 ‘ first byte of SCL opcode
myPacket(1) = 7 ‘ second byte of SCL opcode
myPacket(2) = “R” ‘ R
myPacket(3) = “V” ‘ V
myPacket(4) = vbCR ‘ carriage return
‘ after 20 seconds of inactivity, the drive will close the connection
‘ resulting in a Winsock state error
‘ check for the error and close this end of the connection
If Winsock1.State = sckError Then Winsock1.Close
‘ if necessary, open a new connection
If Winsock1.State = sckClosed Then
Winsock1.Connect
Delay 0.1 ‘ 0.1 second delay
End If
If Winsock1.State = sckConnected Then
Winsock1.SendData myPacket
End If
Toreceivearesponse,youwillneedtoplacesomecodeintheWinsock_DataArrivalevent.Thiseventis
automaticallydeclaredassoonasyouaddaWinsockcontroltoyourform.TheDataArrivaleventwill
automaticallytriggereachtimeapacketis received. ThecodebelowextractstheSCLresponsefromthe
payloadanddisplaysitinamessagebox.
Private Sub Winsock1_DataArrival(ByVal bytesTotal As Long)
Dim udpData() As Byte, n As Integer
Dim hexbyte As String, packetID As Long, SCLrx As String
Winsock1.GetData udpData
' remotehost gets clobbered when packet rec'd,
‘ next line fixes it
Winsock1.RemoteHost = Winsock1.RemoteHostIP
' first 16 bits of packet are the ID (opcode)
If UBound(udpData) >= 1 Then
packetID = 256 * udpData(0) + udpData(1)
If packetID = 7 then ' SCL response
SCLrx = ""
For n = 2 To UBound(udpData)
SCLrx = SCLrx & Chr(udpData(n))
Next n
MsgBox SCLrx
End If
End If
End Sub
Kommentare zu diesen Handbüchern