Applied-motion SV7-Q-EE Manual de usuario Pagina 18

  • Descarga
  • Añadir a mis manuales
  • Imprimir
  • Pagina
    / 19
  • Tabla de contenidos
  • MARCADORES
  • Valorado. / 5. Basado en revisión del cliente
Vista de pagina 17
6/26/2010
9200032a3eSCLCommunicationReferenceManual Page18
Byte[] SCLstring = new Byte[receiveBytes.Length - 2];
// remove opcode
System.Array.Copy(receiveBytes, 2, SCLstring, 0, SCLstring.Length);
receiveString = Encoding.ASCII.GetString(SCLstring);
AddToHistory(receiveString);
}
else if (opcode == 99) // ping response
{
MessageBox.Show("Ping!", "eSCL Utility", MessageBoxButtons.OK,
MessageBoxIcon.Information);
}
}
Thecallbackfunctionwill notbecalledunlessitis“registered”withtheUdpClientobjectusingthe
BeginReceivemethod,asshownbelow.StartRecvCallbackcanbecalledfromtheFormLoadevent.Itmust
alsobereregisteredeachtimeitiscalled(thisistopreventrecursion),whichismosteasilya ccomplishedby
makingacalltoStartRecvCallbackeachtimeyousendapacket.
private void StartRecvCallback()
{
UdpState s = new UdpState();
s.e = new IPEndPoint(IPAddress.Any, 0);
s.u = udpClient;
udpClient.BeginReceive(new AsyncCallback(ReceiveCallback), s);
}
ThisexamplerequiresthatyoudeclareaclasscalledUdpStateasdescribedbelow.
class UdpState
{
public UdpClient u;
public IPEndPoint e;
}
Asifthiseventdriventechniquewasn’tquirky enough,italsocreatesathreadingerrorunlessthefollowing
statementinincludedintheformloadevent:
CheckForIllegalCrossThreadCalls = false; // this must be so for callbacks which
operate in a different thread
AppendixC:ExampleTCPProgram
Allexampleprogramsareavailablefordownloadatwww.applied
motion.com/ampinfo/software/samplecode/.Youshouldstillreadthissectionsothatyouunderstandthekey
elementsofthecodeandwhattradeoffsyoumayencounter.
VisualBasic6
EventhoughVB6isanolderlanguage,itsrefreshingsimplicitymakesitacompellingchoiceforquickly
developinganEthernetapplication.
TocommunicateoverEthernetTCPfromVB6,you’llneedtheWinsockcontrol(MSWINSCK.OCX),whichis
includedintheProfessionalandEnterpriseeditionsofthelanguage.ToconfigureaninstanceofWinsock,you
Vista de pagina 17
1 2 ... 13 14 15 16 17 18 19

Comentarios a estos manuales

Sin comentarios