我给你写了三个过程,记得给我加分
FUNCTION OpenComm( number :integer ):THandle ;
var dcb : TDCB ;
comm : pchar ;
begin
comm := pchar('com' + inttostr(number) );
result := CreateFile( comm,
GENERIC_READ or GENERIC_WRITE,
0, {not shared}
nil, {no security ??}
OPEN_EXISTING,
FILE_ATTRIBUTE_NORMAL or FILE_FLAG_OVERLAPPED,
0 {template} );
GetCommState(result,DCB) ; WITH DCB DO
BEGIN
Baudrate := 9600 ;
Bytesize := 8 ;
Parity := 0 ;
StopBits := 0 ;
END ;
SetcommState(result,DCB) ;
end;
//传送数据到串口,handle为OpenComm()返回的handle.
procedure SendToComm( handle :THandle; date : pchar ) ;
begin
FileWrite( handle,date^,length(date)) ;
end;
//关闭COM口
procedure CloseComm( handle:THandle ) ;
begin
CloseHandle( handle ) ;
end;
FUNCTION OpenComm( number :integer ):THandle ;
var dcb : TDCB ;
comm : pchar ;
begin
comm := pchar('com' + inttostr(number) );
result := CreateFile( comm,
GENERIC_READ or GENERIC_WRITE,
0, {not shared}
nil, {no security ??}
OPEN_EXISTING,
FILE_ATTRIBUTE_NORMAL or FILE_FLAG_OVERLAPPED,
0 {template} );
GetCommState(result,DCB) ; WITH DCB DO
BEGIN
Baudrate := 9600 ;
Bytesize := 8 ;
Parity := 0 ;
StopBits := 0 ;
END ;
SetcommState(result,DCB) ;
end;
//传送数据到串口,handle为OpenComm()返回的handle.
procedure SendToComm( handle :THandle; date : pchar ) ;
begin
FileWrite( handle,date^,length(date)) ;
end;
//关闭COM口
procedure CloseComm( handle:THandle ) ;
begin
CloseHandle( handle ) ;
end;
嘿嘿
[email protected]
这是基于有连接数据表的