读不到串口数据?
procedure TForm1.Timer1Timer(Sender: TObject);
var
bf: array[0..10] of char;
n:cardinal;
begin
n:=0;
if readfile(hcom,bf,10,n,nil) then
listbox1.Items.Add(bf);
end;
procedure TForm1.FormCreate(Sender: TObject);
var dcb:TDCB;
begin
hcom:=createfile('com1',GENERIC_READ and GENERIC_WRITE,0,nil,OPEN_EXISTING,FILE_ATTRIBUTE_NORMAL,0);
if hcom=invalid_handle_value then
begin
showmessage('打开串口失败!') ;
exit;
end;
if not GetCommState(hCom,dcb) then
begin
showmessage('读串口状态失败!') ;
exit;
end;
dcb.BaudRate:=1200;
dcb.ByteSize:=8;
dcb.Parity:=NOPARITY;
dcb.StopBits:=ONESTOPBIT;
if SetCommState( hCom, dcb ) then
if not SetupComm( hcom, 1024, 1024 ) then
begin
CloseHandle( hcom );
showmessage('设置缓冲失败!')
end;
end;