MSComm est un puissant contrôle de communication série pour Microsoft. Les codes suivants sont traités en hexadécimal pour l'envoi et la réception.
var
SendData: Array [1..10] de Char;
Redata: tableau de variantes;
sendStr: String;
retenue: chaîne;
I: Longint;
Commencer
MSCOMM1.COMMPORT: = 1;
msomm1.settings: = '9600, n, 8,1';
MSCOMM1.InbuffeSize: = 1024;
MSCOMM1.outBuffeSize: = 1024;
MSCOMM1.InputMode: = COMINPUTMODEBINAL;
MSCOMM1.Inputlen: = 0;
MSCOMM1.STHRESHOLD: = 0;
MSCOMM1.inbuffercount: = 0;
MSCOMM1.outBuffercount: = 0;
MSCOMM1.PORTOPEN: = TRUE;
MSCOMM1.ReThreshold: = 16; // Définissez le nombre d'octets à recevoir pour générer l'événement OnComm
SendData [1]: = Chr (06 $);
sendData [2]: = chr (03 $);
sendData [3]: = chr ($ 00);
sendData [4]: = chr (03 $);
sendData [5]: = chr (10 $);
sendStr: = '';
pour i: = 1 à 5 faire
sendStr: = sendStr + sendData [i];
MSCOMM1.output: = Sendstr;
i: = 0;
bzw: = false;
répéter
sommeil (10);
application.ProcessMessages;
i: = i + 1;
Si je> 30000 alors
Commencer
ShowMessage («Envoyer un temps mort!»);
casser;
fin;
Jusqu'à bzw = true;
Redata: = MSCOMM1.Input;
retenue: = '';
pour i: = 0 à Vararrayhighbound (Redata, 1) faire
SESTIN: = contrac + intohex (redata [i], 2) + '';
msomm1.portOpen: = false;
Flatmemo1.Text: = retenue;
fin;
// Événement OnComm
Procédure TForm1.MSCOM1COMM (Sender: Tobject);
Commencer
cas MSCOMM1.MomENTENT DE
comeVreceive: bzw: = true;
fin;
fin;
Enfin, lors de la publication du logiciel, vous devez apporter le fichier MSCOM32.ocx.