procedure TForm1.btn1Click(Sender: TObject); var i : Byte; data : array[0..9] of Byte; begin for i := 0 To 9 Do data[i] := i; for i := 0 To 9 Do j := cm1.WriteCommData(@data[i],1); end; procedure TForm1.FormCreate(Sender: TObject); begin cm1.StartComm end
代码少定义一个j:boolean;
可以发送数据
hNewCommFile := CreateFile( PChar('\\.\' + FCommName), GENERIC_READ or GENERIC_WRITE, 0, {not shared} nil, {no security ??} OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL or FILE_FLAG_OVERLAPPED, 0 {template} );