串口设置
with SpCommdo
begin
CommName:='COM1';
BaudRate:=9600;
ByteSize:=_8;
//TByteSize = ( _5, _6, _7, _8 );
ParityCheck:=True;
Parity:=Even;
//TParity = ( None, Odd, Even, Mark, Space )
StopBits:=_1;
//TStopBits = ( _1, _1_5, _2 )
StartComm;
//StopComm;
end;
发送数据
var
Buffer: Array[1..8] of Byte;
begin
Buffer[1]:=$02;
...
Buffer[ 8 ]:=$FF;
SpComm.WriteCommData(@Buffer,8);
end;
接收数据
procedure TForm1.SpCommReceiveData(Sender: TObject;
Buffer: Pointer;
BufferLength: Word);
var
Buf: PChar;
begin
GetMem(Buf,BufferLength);
try
Move(Buffer^,Buf^,BufferLength);
...
finally
FreeMem(Buf);
end;
end;