6/26/2010
920‐0032a3eSCLCommunicationReferenceManual Page16
‘ 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.NETlanguagesareMicrosoft’smodern,objectorientedWindowsapplicationbuildingtoolsandinclude
robustEthernetsupport.WepresentthisexampleinC#.
Makesureyourprojectincludesthisline,providingaccesstoanEthernetsocket:
using System.Net.Sockets;
Inyourformheaderyoumustdeclarea UdpClientobjectandcreateaninstance,whichcanbedoneinthe
sameline.Thelocalportnumberisincludedinthe“newUdpClient”call.Thisistheportnumberthatwillbe
reservedonthePCforyourapplication.
static UdpClient udpClient = new UdpClient(7777);
Toopentheconnection,invoketheConnectmethod,specifyingthedrive’sIPaddressandportnumber:
udpClient.Connect(“192.168.0.130”, 7775);
Tosend“RV”tothedrive:
//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);
GettingresponsesbackfromthedriveinC#isamorecomplicatedthanVB6.Youhavetwochoices:pollfora
responseorcreateacallbackfunctionthatwillprovideatruereceiveevent.
Comentários a estes Manuais