Applied Motion SV7-Q-EE User Manual
Page 16
6/26/2010
920‐0032a3 eSCL Communication Reference Manual
Page 16
‘ 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
C#.NET
The .NET languages are Microsoft’s modern, object oriented Windows application building tools and include
robust Ethernet support. We present this example in C#.
Make sure your project includes this line, providing access to an Ethernet socket:
using
System.Net.Sockets;
In your form header you must declare a UdpClient object and create an instance, which can be done in the
same line. The local port number is included in the “new UdpClient” call. This is the port number that will be
reserved on the PC for your application.
static
UdpClient
udpClient =
new
UdpClient
(7777);
To open the connection, invoke the Connect method, specifying the drive’s IP address and port number:
udpClient.Connect(“192.168.0.130”, 7775);
To send “RV” to the drive:
//create a string loaded with the SCL command
Byte
[] SCLstring =
Encoding
.ASCII.GetBytes(“RV”);
// create a byte array that will be used for the actual
// transmission
Byte
[] sendBytes =
new
Byte
[SCLstring.Length + 3];
// insert opcode (07 is used for all SCL commands)
sendBytes[0] = 0;
sendBytes[1] = 7;
// copy string to the byte array
System.
Array
.Copy(SCLstring, 0, sendBytes, 2, SCLstring.Length);
// insert terminator
sendBytes[sendBytes.Length - 1] = 13; // CR
// send it to the drive
udpClient.Send(sendBytes, sendBytes.Length);
Getting responses back from the drive in C# is a more complicated than VB6. You have two choices: poll for a
response or create a callback function that will provide a true receive event.