Appendix b: example udp programs – Applied Motion SV7-Q-EE User Manual
Page 15
6/26/2010
920‐0032a3 eSCL Communication Reference Manual
Page 15
switch settings of your drive. You can edit the addresses and click “Save to Drive” to install a new set of
addresses in your drive. You can also save a copy of the IP address table to a file by selecting “Save to File”.
After saving a new set of IP addresses to your drive, the drive will continue to communicate using its existing IP
address until you cycle power.
Appendix B: Example UDP Programs
All example programs are available for download at
elements of the code and what tradeoffs you may encounter.
Visual Basic 6
Even though VB6 is an older language, its refreshing simplicity makes it a compelling choice for quickly
developing an Ethernet application.
To communicate over Ethernet UDP from VB6, you’ll need the Winsock control (MSWINSCK.OCX), which is
included in the Professional and Enterprise editions of the language. To configure an instance of Winsock, you
must specify the protocol as UDP, choose a local port number, and set the remote IP address and port number
to match the drive. In the code example below, 7775 is the port of the drive. driveIPaddress is the IP address
of the drive (“10.10.10.10” or “192.168.0.130” for example). 7777 is the port of the PC.
Winsock1.RemotePort = 7775
Winsock1.RemoteHost = driveIPaddress
Winsock1.Protocol = sckUDPProtocol
Winsock1.Bind 7777
// if port 7777 is in use by another application, you will get an error.
// that error should be trapped using the On Error statement
// and an alternate port should be chosen.
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
Winsock1.SendData myPacket
To receive a response, you will need to place some code in the Winsock_DataArrival event. This event is
automatically declared as soon as you add a Winsock control to your form. The DataArrival event will
automatically trigger each time a packet is received. The code below extracts the SCL response from the UDP
payload and displays it in a message box.
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,