Example programs – Applied Motion RS-232 User Manual

Page 277

Advertising
background image

277

920-0002 Rev. I

2/2013

Host Command Reference

Example Programs

Both example programs are available for download at www.applied-motion.com/example_code. You should

still read this section so that you understand the key 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 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

Advertising
This manual is related to the following products: