Witam.
Napisałem pewien skrypt w Autohotkey do komunikacji po przez port COM. Wszystko działa świetnie do czasu kiedy chcę się połączyć z użyciem Bluetooth.
Otóż jeśli łączę się poprzez urządzenie BT to dostaje error 87 z funkcji BuildCommDCB(), co ciekawe to jeśli zignoruje ten błąd podczas inicjalizacji to z powodzeniem nawiązuje połączenie jednak nadal mierzi mnie z czego wynika ten błąd.
Mój odbiornik BT to ten ze zdjęcia, a w systemie z niewiadomych dla mnie powodów figuruje jako 2 porty COM 12 i 13 z czego tylko 12 służy do komunikacji.
Z początku myślałem, że jest to wina tego iż numer portu jest powyżej 9 ale sprawdziłem na innych urządzeniach i wszystko działa OK

Tak więc ktoś wie z czego może wynikać ten błąd?

images.jpgscreenshot.1534067091.png


SERIAL_Settings = COM12:baud=115200 parity=N data=8 stop=1 dtr=on

Initialize(SERIAL_Settings){
		
		
		;###### Extract/Format the COM Port Number ######
		StringSplit, SERIAL_Port_Temp, SERIAL_Settings, `:
		SERIAL_Port_Temp1_Len := StrLen(SERIAL_Port_Temp1)  ;For COM Ports > 9 \\.\ needs to prepended to the COM Port name.
		If (SERIAL_Port_Temp1_Len > 4)                   ;So the valid names are
			SERIAL_Port = \\.\%SERIAL_Port_Temp1%             ; ... COM8  COM9   \\.\COM10  \\.\COM11  \\.\COM12 and so on...
		Else                                          ;
			SERIAL_Port = %SERIAL_Port_Temp1%
		;MsgBox, SERIAL_Port=%SERIAL_Port%
		
		
		;StringTrimLeft, SERIAL_Settings, SERIAL_Settings, SERIAL_Port_Temp1_Len+1 ;Remove the COM number (+1 for the semicolon) for BuildCommDCB.
		;MsgBox, Port=%SERIAL_Port% `nSERIAL_Settings=%SERIAL_Settings%
		;msgbox,% SERIAL_Settings
		;###### Build COM DCB ######
		;Creates the structure that contains the COM Port number, baud rate,...
		VarSetCapacity(DCB, 28)
		BCD_Result := DllCall("BuildCommDCB"
			,"str" , SERIAL_Settings ;lpDef
			,"UInt", &DCB)           ;lpDCB
		If (BCD_Result <> 1){ 
			error := DllCall("GetLastError") ; <------------------------- TUTAJ dostaje błąd 87
			;MsgBox, There is a problem with Serial Port communication. `nFailed Dll BuildCommDCB, BCD_Result=%BCD_Result% `nLasterror=%error%`nThe Script Will Now Exit.
			;ExitApp
			;return
		}
		;return
		;###### Create COM File ######
		;Creates the COM Port File Handle
		;StringLeft, SERIAL_Port, SERIAL_Settings, 4  ; 7/23/08 This line is replaced by the "Extract/Format the COM Port Number" section above.
		;msgbox,% SERIAL_Port
		SERIAL_FileHandle := DllCall("CreateFile"
			,"Str" , SERIAL_Port  ;File Name
			,"UInt", 0xC0000000   ;Desired Access
			,"UInt", 3            ;Safe Mode
			,"UInt", 0            ;Security Attributes
			,"UInt", 3            ;Creation Disposition TODO: TRUNCATE_EXISTING?
			,"UInt", 0            ;Flags And Attributes
			,"UInt", 0            ;Template File
			,"Cdecl Int")
		If (SERIAL_FileHandle < 1){
			error := DllCall("GetLastError")
			;MsgBox, There is a problem with Serial Port communication. `nFailed Dll CreateFile, SERIAL_FileHandle=%SERIAL_FileHandle% `nLasterror=%error%`nThe Script Will Now Exit.
			;ExitApp
			return
		}
		
		;###### Set COM State ######
		;Sets the COM Port number, baud rate,...
		SCS_Result := DllCall("SetCommState"
			,"UInt", SERIAL_FileHandle ;File Handle
			,"UInt", &DCB)          ;Pointer to DCB structure
		If (SCS_Result <> 1){
			error := DllCall("GetLastError")
			;MsgBox, There is a problem with Serial Port communication. `nFailed Dll SetCommState, SCS_Result=%SCS_Result% `nLasterror=%error%`nThe Script Will Now Exit.
			this.Close(SERIAL_FileHandle)
			;ExitApp
			return
		}
		
		;###### Create the SetCommTimeouts Structure ######
		ReadIntervalTimeout        = 0xffffffff
		ReadTotalTimeoutMultiplier = 0x00000000
		ReadTotalTimeoutConstant   = 0x00000000
		WriteTotalTimeoutMultiplier= 0x00000000
		WriteTotalTimeoutConstant  = 0x00000000
		
		VarSetCapacity(Data, 20, 0) ; 5 * sizeof(DWORD)
		NumPut(ReadIntervalTimeout,         Data,  0, "UInt")
		NumPut(ReadTotalTimeoutMultiplier,  Data,  4, "UInt")
		NumPut(ReadTotalTimeoutConstant,    Data,  8, "UInt")
		NumPut(WriteTotalTimeoutMultiplier, Data, 12, "UInt")
		NumPut(WriteTotalTimeoutConstant,   Data, 16, "UInt")
		
		;###### Set the COM Timeouts ######
		SCT_result := DllCall("SetCommTimeouts"
			,"UInt", SERIAL_FileHandle ;File Handle
			,"UInt", &Data)         ;Pointer to the data structure
		If (SCT_result <> 1){
			error := DllCall("GetLastError")
			;MsgBox, There is a problem with Serial Port communication. `nFailed Dll SetCommState, SCT_result=%SCT_result% `nLasterror=%error%`nThe Script Will Now Exit.
			this.Close(SERIAL_FileHandle)
			;ExitApp
			return
		}
		
		Return SERIAL_FileHandle
	}