R
rcazy
Unregistered / Unconfirmed
GUEST, unregistred user!
做了一个这样的函数
function TForm1.openport(T:TCOMPORT; connect:boolean; commfile:thandle; xport:Tcomport):boolean;
var S : string;
size : dWord;
Buffer : PCommConfig;
DCB : TDCB;
Config : String;
CommTimeouts : TCommTimeouts;
Begin if connect Then closeport(t, connect, commfile);
// open communication
CommFile := CreateFile(Pchar(t.COMNAME), Generic_Write + Generic_Read , 0, nil, Open_Existing, File_Attribute_Normal,FILE_FLAG_OVERLAPPED);
connect := (CommFile <> INVALID_HANDLE_VALUE);
If connect Then
Begin If Not(setupComm(CommFile,256,256)) Then ShowMessage('Communicatoin Setup Error!');
If Not(GetCommState(CommFile,dcb)) Then ShowMessage('Communication Get State Error!');
Config := 'baud='+T.comspeed+' parity='+copy(t.comparity,1,1)+' data='+t.combit+' stop='+t.comstop;
If Not(BuildCommDCB(@Config[1],DCB)) Then ShowMessage('Communication Build DCB Error!');
If Not (SetCommState(CommFile, DCB)) Then ShowMessage('Communication Set New State Error!');
with CommTimeouts Do Begin
ReadIntervalTimeout := 0;
ReadTotalTimeoutMultiplier := 0;
ReadTotalTimeoutConstant := 1000;
WriteTotalTimeoutMultiplier := 0;
WriteTotalTimeoutConstant := 1000;
End;
If Not(SetCommTimeouts(CommFile,CommTimeouts)) Then ShowMessage('Communication Set Time-out Error!');
xport := T;
End
Else ShowMessage('COM port not found or problem!');
Result := connect;
我想在调用
openport(Comport,isconnect,hcommfile,port)
返回出Comport,isconnect,hcommfile,port的值
function TForm1.openport(T:TCOMPORT; connect:boolean; commfile:thandle; xport:Tcomport):boolean;
var S : string;
size : dWord;
Buffer : PCommConfig;
DCB : TDCB;
Config : String;
CommTimeouts : TCommTimeouts;
Begin if connect Then closeport(t, connect, commfile);
// open communication
CommFile := CreateFile(Pchar(t.COMNAME), Generic_Write + Generic_Read , 0, nil, Open_Existing, File_Attribute_Normal,FILE_FLAG_OVERLAPPED);
connect := (CommFile <> INVALID_HANDLE_VALUE);
If connect Then
Begin If Not(setupComm(CommFile,256,256)) Then ShowMessage('Communicatoin Setup Error!');
If Not(GetCommState(CommFile,dcb)) Then ShowMessage('Communication Get State Error!');
Config := 'baud='+T.comspeed+' parity='+copy(t.comparity,1,1)+' data='+t.combit+' stop='+t.comstop;
If Not(BuildCommDCB(@Config[1],DCB)) Then ShowMessage('Communication Build DCB Error!');
If Not (SetCommState(CommFile, DCB)) Then ShowMessage('Communication Set New State Error!');
with CommTimeouts Do Begin
ReadIntervalTimeout := 0;
ReadTotalTimeoutMultiplier := 0;
ReadTotalTimeoutConstant := 1000;
WriteTotalTimeoutMultiplier := 0;
WriteTotalTimeoutConstant := 1000;
End;
If Not(SetCommTimeouts(CommFile,CommTimeouts)) Then ShowMessage('Communication Set Time-out Error!');
xport := T;
End
Else ShowMessage('COM port not found or problem!');
Result := connect;
我想在调用
openport(Comport,isconnect,hcommfile,port)
返回出Comport,isconnect,hcommfile,port的值