MSCOMMは、Microsoftの強力なシリアルコミュニケーションコントロールです。次のコードは、送信と受信のために16進数で処理されます。
var
senddata:charの配列[1..10]。
Redata:バリアントの配列。
SendStr:文字列;
抑制:文字列;
I:Longint;
始める
mscomm1.commport:= 1;
mscomm1.settings:= '9600、n、8,1';
mscomm1.inbufferize:= 1024;
mscomm1.outbufferize:= 1024;
mscomm1.inputmode:= cominputmodebinary;
mscomm1.inputlen:= 0;
mscomm1.sthreshold:= 0;
mscomm1.inbuffercount:= 0;
mscomm1.outbuffercount:= 0;
mscomm1.portopen:= true;
MSCOMM1.RTHRESHOLD:= 16; // ONCOMMイベントを生成するために受信するバイト数を設定します
senddata [1]:= chr($ 06);
senddata [2]:= chr($ 03);
senddata [3]:= chr($ 00);
senddata [4]:= chr($ 03);
senddata [5]:= chr($ 10);
sendstr:= '';
i:= 1〜5の場合
sendstr:= sendstr + senddata [i];
mscomm1.output:= sendstr;
i:= 0;
BZW:= false;
繰り返す
睡眠(10);
application.processmessages;
i:= i + 1;
> 30000の場合
始める
showmessage( 'Timeoutを送信!');
壊す;
終わり;
bzw = trueまで;
Redata:= mscomm1.input;
抑制:= '';
i:= 0からvararrayhighbound(Redata、1)はそうです
抑制:= rest + inttohex(redata [i]、2) + '';
mscomm1.portopen:= false;
flatmemo1.text:= stent;
終わり;
// oncommイベント
手順tform1.mscomm1comm(sender:tobject);
始める
ケースMSCOMM1.Commeventの
comevreceive:bzw:= true;
終わり;
終わり;
最後に、ソフトウェアをリリースするときは、MSCOMM32.ocxファイルを持参する必要があります。