OwenBrotherwood / EspruinoTools

JavaScript library of tools for Espruino - used for the Web IDE, CLI, etc.
Apache License 2.0
0 stars 0 forks source link

winnus does not fail with inactive Bluetooth adapter #2

Open OwenBrotherwood opened 7 years ago

OwenBrotherwood commented 7 years ago

https://github.com/OwenBrotherwood/EspruinoTools/tree/no_winnus_error_with_no_access

https://github.com/espruino/EspruinoTools/issues/57

The node bin\espruino-cli.js --list --verbose shows COM3 but shows no suprise at no winnus being available.

OwenBrotherwood commented 7 years ago

seems that winnus fails first with winnus.connect(device,path) with test hello.js

C:\source\repos\github\OwenBrotherwood\winnus>node hello.js
C:\source\repos\github\OwenBrotherwood\winnus\winnus.js:34
  winnus.connect(device.path);
                       ^

TypeError: Cannot read property 'path' of undefined
    at Object.exports.connect (C:\source\repos\github\OwenBrotherwood\winnus\winnus.js:34:24)
    at Object.<anonymous> (C:\source\repos\github\OwenBrotherwood\winnus\hello.js:4:8)
    at Module._compile (module.js:571:32)
    at Object.Module._extensions..js (module.js:580:10)
    at Module.load (module.js:488:32)
    at tryModuleLoad (module.js:447:12)
    at Function.Module._load (module.js:439:3)
    at Module.runMain (module.js:605:10)
    at run (bootstrap_node.js:418:7)
    at startup (bootstrap_node.js:139:9)
OwenBrotherwood commented 7 years ago

https://github.com/OwenBrotherwood/winnus/issues/3

OwenBrotherwood commented 7 years ago

repeated test with npm package from npmjs

OwenBrotherwood commented 7 years ago

As expected, from hello.js test, this did not catch I had, however expected the hello.js and therefor below to catch ...

(function () {
  if (typeof require === 'undefined') return;
  var winnus = undefined;
  try {
    winnus = require('winnus');
    var devices = winnus.getDevices();
  } catch (e) {
    console.log("'winnus' module not found, no Windows Bluetooth Low Energy", e);
    return;
  }
  console.log("Disable Web Bluetooth as we have Winnus instead");
  Espruino.Core.Serial.NO_WEB_BLUETOOTH = true;
OwenBrotherwood commented 7 years ago

c++ :: not going there, so see what winnus.js is doing.

OwenBrotherwood commented 7 years ago

Hmmm, var devices = winnus.getDevices(); should in theory catch as hello.js caught in quick test,

exports.getDevices = function() {
  // Merge the 2 sets of data we have
  var names = winnus.getDeviceNames();
  var paths = winnus.getDevicePaths();
void WINNUS_GetDevicePaths(const FunctionCallbackInfo<Value>& args) {
  Isolate* isolate = args.GetIsolate();
  Local<Array> array = Array::New(isolate);

  // NUS GUID
    GUID BluetoothInterfaceGUID;
    CLSIDFromString(TEXT(L"{6e400001-b5a3-f393-e0a9-e50e24dcca9e}"), &BluetoothInterfaceGUID);

  HDEVINFO hDI;
    SP_DEVICE_INTERFACE_DATA did;
    SP_DEVINFO_DATA dd;

    hDI = SetupDiGetClassDevs(&BluetoothInterfaceGUID, NULL, NULL, DIGCF_DEVICEINTERFACE | DIGCF_PRESENT);

    if (hDI == INVALID_HANDLE_VALUE)
        RETURN_ERR("Unable to access Bluetooth adaptor");

#define RETURN_ERR(text) {isolate->ThrowException(Exception::Error(String::NewFromUtf8(isolate, text)));return;}

OwenBrotherwood commented 7 years ago

Wait for espruino https://github.com/espruino/EspruinoTools/issues/57#issuecomment-281470309