New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fixed invalid syntax of function declaration #14
Conversation
And regarding openSerial: on my system for some reason portToDevice is an empty array. That caused the code to crash on accessing undefined.open, because the check for the existence of the port was wrong. |
The function syntax is ES6 function syntax - all the Web Bluetooth code uses it and some got left in... but anything that supports Web Bluetooth should support ES6, so I'm surprised it caused you errors? Also, the serial code definitely does work, so I'm not sure the positioning of What system are you running on? and are you using it as a chrome extension? If portToDevice is an empty array, presumably that means that no serial ports have been found? You could go into settings, enable the 'seruial over audio' and see if you can connect with that. |
I'm running espruinotool on the command-line. If it uses the globally installed node.js, then that would be v0.10.26. The problem with the ! without the extra brackets (that I added) is that it negates only the string serialPort. Therefore the error check is not working and the code crashes later on when trying to access the function open of an undefined variable currentDevice. Look at this:
node on my machine doesn't eat that function declaration:
Besides, this is the ONLY place in the repo where a function is declared by that syntax. There's a whole sequence of lines in serial_web_bluetooth.js which declare functions in the old fashion and just a few lines below there is this one arrow function declaration. That's also incosistent (adding to the fact that it doesn't compile on systems like mine). |
Fixed invalid syntax of function declaration
Very true - sorry, had to head out earlier so didn't merge straight away. So you have node-serialport, and you're still not seeing any ports? |
The dependency serialport was installed by npm:
but true, I don't see any ports :( I just updated my old node.js to 5.0.0, but now it crashes on another dependency... |
I found what the problem was. The code of espruinotool (index.js) used to work this way: when no port is specified, it scans for ports and then connects to the first port found. That works fine. But if a port was specified, it does NOT scan for ports, it tries to connect right away. However the function openSerial in serial.js checks whether the specified port exists (by checking whether the string is an element of the array portToDevice). portToDevice is a variable in a higher scope and in this case an empty array, because the function getPorts that fills it has never been called. I fixed it here: Please let me know what you think. |
Thanks - yes, sounds to me like |
Ok, just done... |
No idea how this got in there, but the syntax is invalid. I guess it should have been a function.