|     Inicio    |   |         |  |   FOROS      |  |      |      
   Elastix - VoIP B4A (Basic4Android) App inventor 2 PHP - MySQL
  Estación meteorológica B4J (Basic4Java) ADB Shell - Android Arduino
  Raspberry Pi Visual Basic Script (VBS) FireBase (BD autoactualizable) NodeMCU como Arduino
  AutoIt (Programación) Visual Basic Cosas de Windows Webs interesantes
Translate:
Búsqueda en este sitio:


.

Autoit en español
Aplicaciones con Autoit - Juan Antonio Villalpando

-- Tutorial de iniciación a Autoit --

Volver al índice del tutorial

____________________________

60.- Bluetooth.

- Vamos a conectar el ordenador por Bluetooth con un Arduino, NodeMCU y con el móvil mediante una aplicación en App Inventor.

-Si tienes un portátil probablemente ya tendrá Bluetooth. Si tienes un ordenador sin Bluetooth, puedes comprar lo que se denomina un "dongle" bluetooth, tiene un forma parecida a una memoria USB, pero es un emisor/receptor de Bluetooth, en Aliexpress lo puedes encontrar por menos de dos euros.

- Una vez que disponga del "dongle", para vincularlo con otro dispositivo te pedirá la clave que suele ser "0000" o "1234"

___________________________________________
1.- Comprobar si mi ordenador tiene habilitado el Bluetooth.

- Supongamos que hemos comprado un "dongle" Bluetooth, lo conectamos al ordenador y queremos comprobar mediante una aplicación AutoIt simplemente si el ordenador tiene habilitado el Bluetooth.

- Vamos a este post del foro https://www.autoitscript.com/forum/topic/139596-bluetooth-detectorswitching-script/

y lo ejecutamos mediante AutoIt.

- Este Script se basa en la herramienta de Windows bthprops.cpl

Comprobar si el ordenador tiene habilitado el Bluetooth.
				   
#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#Region ### START Koda GUI section ### Form=
$Form1 = GUICreate("Bluetooth Manager.", 409, 135, 192, 124)
$Label1 = GUICtrlCreateLabel("Este Script comprueba si el ordenador tiene habilitado el Bluetooth.", 8, 8, 500, 17)
$Button1 = GUICtrlCreateButton("Comprueba si el dispositivo esta activado.", 8, 48, 300, 25, $WS_GROUP)
$Checkbox1 = GUICtrlCreateCheckbox("Deshabilitar la comprobación de Bluetooth.", 16, 96, 300, 17)
$Button2 = GUICtrlCreateButton("Salir", 312, 96, 75, 25, $WS_GROUP)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###
While 1
$nMsg = GUIGetMsg()
Switch $nMsg
Case $GUI_EVENT_CLOSE
Exit
Case $Button1
$RESULT = DllCall("bthprops.cpl", "Bool", "BluetoothEnableIncomingConnections", "Handle", 0, "Bool", 1)
If $RESULT[0] = 1 then
msgbox(64, "Mensaje", "El ordenador tiene habilitado la conexión Bluetooth.")
    else
    msgbox(16, "", "No se ha encontrado ningún dispositivo Bluetooth del ordenador.")
EndIf
Case $Checkbox1
If BitAND(GUICtrlRead($Checkbox1), $GUI_CHECKED) Then
                $RESULT = DllCall("bthprops.cpl", "Bool", "BluetoothEnableDiscovery", "Handle", 0, "Bool", 0)
                msgbox(64, "", "Comprobación deshabilitada.")
            Else
                $RESULT = DllCall("bthprops.cpl", "Bool", "BluetoothEnableDiscovery", "Handle", 0, "Bool", 1)
                msgbox(64, "", "Comprobación habilitada.")
            EndIf
Case $Button2
Exit
EndSwitch
WEnd

___________________________________________
2.- Conocer los Bluetooth que tiene registrado el ordenador.

- Obtenemos un listado de dispositivos Bluetooth que están vinculados al ordenador, aunque en este momento no estén conectados.

- Es un código obtenido de https://www.autoitscript.com/forum/topic/142716-bluetooth-finder-tool-find-bluetooth-devices-near-you/

pero cuidado que en ese código no han puesto las librerías necesarias, en el código que presento sí he añadido las librerías.

- Son los mismos dispositivos que obtenemos mediante el Panel de Control de Windows.

Obtener los bluetooth registrados en el ordenador.
				   

#include <WinAPI.au3>
#include <GUIConstantsEx.au3>
#include <MsgBoxConstants.au3>
#include <WindowsConstants.au3>
#include <GuiListView.au3>
#include <GuiStatusBar.au3>
Local $phRadio
$hFind = _BluetoothFindFirstRadio($phRadio)
If $hFind = 0 then
msgbox(16, "Hardware error", "Unable to find compatible Bluetooth radio(s) on this machine.")
_WinAPI_CloseHandle($phRadio)
_BluetoothFindRadioClose($hFind)
Exit
else
_WinAPI_CloseHandle($phRadio)
_BluetoothFindRadioClose($hFind)
EndIf

$Form1 = GUICreate("Bluetooth Finder - by MKISH", 292, 394, 336, 268)
$ListView1 = GUICtrlCreateListView("Device name|Device address|Class of Device", 0, 0, 290, 318, -1, BitOR($WS_EX_CLIENTEDGE, _ 
$LVS_EX_GRIDLINES,$LVS_EX_FULLROWSELECT))

GUICtrlSendMsg(-1, $LVM_SETCOLUMNWIDTH, 0, 90)
GUICtrlSendMsg(-1, $LVM_SETCOLUMNWIDTH, 1, 100)
GUICtrlSendMsg(-1, $LVM_SETCOLUMNWIDTH, 2, 90)
$StatusBar1 = _GUICtrlStatusBar_Create($Form1)
Dim $StatusBar1_PartsWidth[2] = [50, -1]
_GUICtrlStatusBar_SetParts($StatusBar1, $StatusBar1_PartsWidth)
_GUICtrlStatusBar_SetText($StatusBar1, "Status", 0)
_GUICtrlStatusBar_SetText($StatusBar1, "Active", 1)
$Button1 = GUICtrlCreateButton("Find new", 16, 336, 75, 25, $WS_GROUP)
$Button3 = GUICtrlCreateButton("Exit", 192, 336, 75, 25, $WS_GROUP)
$Button2 = GUICtrlCreateButton("Go offline", 104, 336, 75, 25, $WS_GROUP)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

While 1
$nMsg = GUIGetMsg()
Switch $nMsg
Case $GUI_EVENT_CLOSE
Exit
Case $Button3
Exit
Case $Button2
If GUICtrlRead($Button2) = "Go offline" Then
$RESULT = DllCall("bthprops.cpl", "Bool", "BluetoothEnableDiscovery", "Handle", 0, "Bool", 0)
msgbox(64, "", "Discovery Disabled.")
GuiCtrlSetData($Button2, "Go online")
Else
$RESULT = DllCall("bthprops.cpl", "Bool", "BluetoothEnableDiscovery", "Handle", 0, "Bool", 1)
msgbox(64, "", "Discovery Enabled.")
GuiCtrlSetData($Button2, "Go offline")
EndIf
Case $Button1
GuiCtrlSetState($Button1, $GUI_DISABLE)
GuiCtrlSetData($Button1, "Please Wait...")
_GUICtrlListView_DeleteAllItems($ListView1)
_GUICtrlStatusBar_SetText($StatusBar1, "Finding", 1)
$RESULT = _BluetoothFindFirstDevice(True)
If _GUICtrlListView_FindInText($ListView1, "" & $RESULT[0]) = "-1" then
If $RESULT[0] <> "" then GuiCtrlCreateListViewItem($RESULT[0] & "|" & Hex($RESULT[1]) & "|" & $RESULT[2], $ListView1)
EndIf
$RESULTX = _BluetoothFindFirstDevice()
If _GUICtrlListView_FindInText($ListView1, "" & $RESULTX[0]) = "-1" then
If $RESULTX[0] <> "" then GuiCtrlCreateListViewItem($RESULTX[0] & "|" & Hex($RESULTX[1]) & "|" & $RESULTX[2], $ListView1)
EndIf
_GUICtrlStatusBar_SetText($StatusBar1, "Currently active", 1)
GuiCtrlSetData($Button1, "Find new")
GuiCtrlSetState($Button1, $GUI_ENABLE)

EndSwitch
WEnd

Func _BluetoothFindFirstDevice($REMEMBER = False)
Local $HRESULT[3], $tBLUETOOTH_DEVICE_INFO
$tBLUETOOTH_DEVICE_SEARCH_PARAMS = DllStructCreate('DWORD;BOOL;BOOL;BOOL;BOOL;BOOL;BYTE;HANDLE')
DllStructSetData($tBLUETOOTH_DEVICE_SEARCH_PARAMS, 1 , DllStructGetSize($tBLUETOOTH_DEVICE_SEARCH_PARAMS))
DllStructSetData($tBLUETOOTH_DEVICE_SEARCH_PARAMS, 2 , False)
DllStructSetData($tBLUETOOTH_DEVICE_SEARCH_PARAMS, 3 , $REMEMBER)
DllStructSetData($tBLUETOOTH_DEVICE_SEARCH_PARAMS, 4 , True)
DllStructSetData($tBLUETOOTH_DEVICE_SEARCH_PARAMS, 5 , True)
DllStructSetData($tBLUETOOTH_DEVICE_SEARCH_PARAMS, 6 , True)
DllStructSetData($tBLUETOOTH_DEVICE_SEARCH_PARAMS, 7 , 6)
DllStructSetData($tBLUETOOTH_DEVICE_SEARCH_PARAMS, 8 , 0)
$tBLUETOOTH_DEVICE_INFO = DllStructCreate('DWORD;UINT64;ULONG;BOOL;BOOL;BOOL;word[8];word[8];WCHAR[248]')
DllStructSetData($tBLUETOOTH_DEVICE_INFO,1,DllStructGetSize($tBLUETOOTH_DEVICE_INFO))
$RESULT = DllCall("bthprops.cpl", "handle", "BluetoothFindFirstDevice", "struct*", $tBLUETOOTH_DEVICE_SEARCH_PARAMS, _ 
"struct*", $tBLUETOOTH_DEVICE_INFO)

$HRESULT[0] = DllStructGetData($tBLUETOOTH_DEVICE_INFO, 9)
$HRESULT[1] = DllStructGetData($tBLUETOOTH_DEVICE_INFO, 2)
$HRESULT[2] = DllStructGetData($tBLUETOOTH_DEVICE_INFO, 3)
Do
$ULTRA = _BluetoothFindNextDevice($RESULT[0])
until $ULTRA = "0"
Return $HRESULT
EndFunc

Func _DelItem()
If GuiCtrlGetState($ListView1)<>0 then
_GUICtrlListView_DeleteItemsSelected($ListView1)
EndIf
EndFunc

Func _BluetoothFindFirstRadio(ByRef $phRadio)
$tBLUETOOTH_FIND_RADIO_PARAMS = DllStructCreate('DWORD')
DllStructSetData($tBLUETOOTH_FIND_RADIO_PARAMS, 1 , DllStructGetSize($tBLUETOOTH_FIND_RADIO_PARAMS))
$aResult = DllCall("bthprops.cpl", "handle", "BluetoothFindFirstRadio", "struct*", _ 
 $tBLUETOOTH_FIND_RADIO_PARAMS, "handle*", 0)
 
If @error Then Return SetError(2, @error, 0)
$phRadio = $aResult[2]
Return SetError($aResult[0] = 0, 0, $aResult[0])
EndFunc

Func _BluetoothFindRadioClose($hBtFind)
Local $aResult = DllCall("bthprops.cpl", "bool", "BluetoothFindRadioClose", "handle", $hBtFind)
If @error Then Return SetError(2, @error, 0)
Return SetError($aResult[0] = 0, 0, $aResult[0])
EndFunc

Func _BluetoothFindNextDevice($HANDLE)
$t1BLUETOOTH_DEVICE_INFO = DllStructCreate('DWORD;UINT64;ULONG;BOOL;BOOL;BOOL;word[8];word[8];WCHAR[248]')
$RESULTX = DllCall("bthprops.cpl", "Bool", "BluetoothFindNextDevice", "handle", $HANDLE, "struct*", $t1BLUETOOTH_DEVICE_INFO)
If _GUICtrlListView_FindInText($ListView1, "" & DllStructGetData($t1BLUETOOTH_DEVICE_INFO, 9)) = "-1" then
If DllStructGetData($t1BLUETOOTH_DEVICE_INFO, 9) <> "" then GuiCtrlCreateListViewItem(DllStructGetData($t1BLUETOOTH_DEVICE_INFO, 9) & _ 
"|" & Hex(DllStructGetData($t1BLUETOOTH_DEVICE_INFO, 2)) & "|" & DllStructGetData($t1BLUETOOTH_DEVICE_INFO, 3), $ListView1)

EndIf
Return $RESULTX[0]
EndFunc

_________________
- Propuesta.

-

_________________

- Mi correo:
juana1991@yahoo.com
- KIO4.COM - Política de cookies. Textos e imágenes propiedad del autor:
© Juan A. Villalpando
No se permite la copia de información ni imágenes.
Usamos cookies propias y de terceros que entre otras cosas recogen datos sobre sus hábitos de navegación y realizan análisis de uso de nuestro sitio.
Si continúa navegando consideramos que acepta su uso. Acepto    Más información