1. 程式人生 > >Delphi使用spcomm串列埠通訊 串列埠號大於10出錯的解決辦法 spcomm error opening serial port

Delphi使用spcomm串列埠通訊 串列埠號大於10出錯的解決辦法 spcomm error opening serial port

//./com18是windows裡邊的SymbolLinkName,這個在WINAPI裡邊就需要這 樣寫,SPCOMM的這部分的原始碼如下:
procedure TComm.StartComm;
var
   hNewCommFile:   THandle;
begin
     // Are we already doing comm?
     if (hCommFile <> 0) then
        raise ECommsError.Create( 'This serial port already opened' );

     hNewCommFile := CreateFile( PChar(FCommName),                 & lt;------就是這裡,要加上//./
                                 GENERIC_READ or GENERIC_WRITE,
                                 0, {not shared}
                                 nil, {no security ??}
                                 OPEN_EXISTING,
                                 FILE_ATTRIBUTE_NORMAL or FILE_FLAG_OVERLAPPED,
                                 0 {template} );
 
     if hNewCommFile = INVALID_HANDLE_VALUE then
        raise ECommsError.Create( 'Error opening serial port' );    
                                  ^^^^^^^^^^^^^^^^^^^^^^^^^^^如果不是 SymbolLinkName寫法,串列埠號大於9這裡就出錯了