-
Notifications
You must be signed in to change notification settings - Fork 47
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
Details object vs Serial Port instance #20
Comments
So all of those seem to be specific to USB-to-serial adapters and not part of serial itself. |
Right. That's what I thought. At the system level, is all that we can expect is a path? |
Fundamentally, yes - just a path is all thats needed to open a serial port. Everything else is additional information that may or may not be available depending on the device. |
Ok, so it sounds to me that |
That's right Francis Gulotta On Wed, Nov 6, 2013 at 4:21 PM, Marcos Caceres notifications@github.comwrote:
|
ok, cool. We are basically answering #19 :) So, I'm going to move all those properties above to the |
Ok, so what I want to do here is have the serial port instance have an var serial = new SerialPort("/some/path");
serial.info.forEach( (value, key) => console.log(key, value)); What might also work is having a var serial = new SerialPort("/some/path")
, customInfo = serial.getInfo();
customInfo.forEach( (value, key) => console.log(key, value));
customInfo.delete("manufacturer");
customInfo.set("vendor", "Some One");
customInfo.set(controller, {someOtherObject}) Option 2 above could be quite useful, IMO. |
The |
Yeah, either have an immutable object / dictionary, or have a getter that returns an instance of |
@fbender so, immutable objects (proposal 1) kinda suck because they are not idiomatic: it's expected that if you have a map, it will behave like a map. Making the map immutable breaks that expectation because set, delete, etc. don't work as expected. |
#25, #20, #19, #4) Detailed discussions are in #25, #20, #19, #4. * Defined how requestPorts() method works * defined how getInfo() works * made SerialPortInfo into a map (was SerialPortDetails) * introduced the concept of "recommended serial port metadata" * defined the rules for "getting serial port metadata" * Updated the security considerations section.
IMHO I don't think a getter function is necessary. If we make it read only Francis Gulotta On Thu, Nov 7, 2013 at 11:55 AM, Florian Bender notifications@github.comwrote:
|
I'm of the position that we should change the underlying primitives as little as possible (if at all) - unless we have to. It makes the code easier to maintain, and doesn't have any side effects if, for instance, the Map prototype is extended with new functionality in the future. |
A getter makes it clear that the data tied to the port itself is immutable (by returning a copy of the internal Map), so you can never change it globally. This makes the API look more obvious though is not necessarily required … |
Do we know of any examples of APIs that contain a getter that returns an immutable array or map object? I was kinda basing the design on ES-402's @rwaldron, sorry to bother again - but what would be more idiomatic here? (Please see API proposal in #20 (comment) ). Having a getter that returns a frozen Map or having a method that returns a new Map every time? ... or should the properties of the "info" object just be folded into |
@marcoscaceres if you return a Map via getter, the Map does not need to be frozen – that's why I'd use a getter, to actually let it return a standard Map (or Object) that is a copy of the internal Map, so it does not need to be immutable. |
I'm worried that people will screw with it - and that will mean that the internal map and the JS map will differ (or worst, would lead to race conditions). |
That's the idea behind returning a copy via the getter: It does not matter if the Map gets edited. You always get the "fresh" copy from the getter, and if you mess with that copy, that's up to you. (I worried about the same, that's why I proposed the immutable object at first. Again, this is mitigated by returning a copy via the getter.) |
You already said that, BTW:
|
+1 |
Spoke to @fbender on IRC, we had a bit of confusion over terminology. When I was saying //object attribute.
Object.defineProperty(x,"someGetter", {get: function(){...}}); As opposed to "instance.someGetter()". @rwaldron, are you saying we should use a proper ES getter to return a new instance every time. This, of course, means that: fooSerial.info === fooSerial.info; // false Which might catch people out (though that is also the same for |
Using getInfo() also avoid the following gotcha (maybe, didn't help jQuery;)): //generating redundant objects on every call.
if (serial.info.foo === someValue && serial.info.bar === someOtherValue) {}
//vs, more efficient
var info = serial.getInfo();
if (info.foo === someValue && info.bar === someOtherValue) {} there might be other gotchas with looping while trying to read the values. |
The terminology mistake is that you're not using the right terminology. The thing you described above is an "accessor" property. I'm missing context for this bombardment of snippets, but I think this is pointless: The terminology mistake is that you're not using the right terminology. The thing you described above is an "accessor" property. I'm missing context for this bombardment of snippets, but I think this is pointless: var serial = new SerialPort("/some/path")
, customInfo = serial.getInfo();
customInfo.forEach( (value, key) => console.log(key, value));
customInfo.delete("manufacturer");
customInfo.set("vendor", "Some One");
customInfo.set(controller, {someOtherObject}) These are just properties of that serial port object, so why over complicate? var serial = new SerialPort("/some/path");
// readonly data properties, don't need to be accessors to be readonly. See example at end.
serial.comName;
serial.manufacturer;
serial.serialNumber;
serial.pnpId;
serial.locationId;
serial.vendorId;
serial.productId;
// serial instances should be Iterables, ie. implement @@iterator that
// yields [ key, value ]
for ([k, v] of serial) {
console.log(k, v);
}
// Using this API to connect to an Arduino Leonardo from OSX:
var leo = new SerialPort("/dev/cu.usbmodem1411");
console.dir(leo);
// output:
{
comName: "/dev/cu.usbmodem1411",
manufacturer: "Arduino LLC",
serialNumber: "",
pnpId: "",
locationId: "0x14100000",
vendorId: "0x2341",
productId: "0x0036"
}
for ([k, v] of leo) {
console.log(`${k} has a value of ${v}`);
}
// output:
comName has a value of /dev/cu.usbmodem1411
manufacturer has a value of Arduino LLC
serialNumber has a value of
pnpId has a value of
locationId has a value of 0x14100000
vendorId has a value of 0x2341
productId has a value of 0x0036 You could take it one step further and specify that these objects also implement This is a readonly data property example: function Readonly() {
Object.defineProperty(this, "foo", {
value: "bar"
});
}
var ro = new Readonly();
ro.foo; // "bar"
ro.foo = "something else";
ro.foo; // "bar" |
👍 Simple and efficient. |
Like it, it's why I dragged ya in here @rwaldron :) |
Sorry about the weird copy/paste shenanigans... I wrote that in an editor and pasted back, whoops! |
So the problem remains that we can't guarantee the availability and consistency of the information of the serial port (except for However, I think we can, to a degree merge the iterator idea with the // serial instances is Iterable
// yields [ key, value ]
for ([k, v] of serial) {
console.log(k, v);
} By adding an The other option is for us to pick the standard set of attribute (as @rwaldron suggests) and set them to |
So make them |
All things considered, this is solid.
|
👍 to @rwaldron's suggestion |
Sounds like a plan, @rwaldron. I'll update the spec to match. So, going back to the OP - what is the minimal set of properties that we absolutely must have? |
Are both valid |
Path is what chrome.serial.getPorts have - and that is useless to us in the
|
Can you elaborate on "useless"?
I'm sorry, but I'm lacking context—who is "we"? Note that "pnpId" is empty in the examples I provided here #20 (comment). That was the exact output from node-serialport. |
… and we are not discussion node-serialport here, but a Web API where for the most part the user selects the port(s) the script accesses, and not the script itself. Thus exposing as much as possible is a non-goal, IMHO. As Rick said, we can always expand the API, but for now we should aim for the minimum. |
On Tue, Nov 12, 2013 at 8:50 PM, Rick Waldron notifications@github.comwrote:
As Marcos mentioned, this should probably have been in #19 - but just to On Linux (at least), chrome.serial.getPorts replies with anything that On top of this, we need to find which one might be bound to the device we Besides this, at least in our (www.empirikit.com) case, where we are dong a As I also come from a "coding since the age of 12 and h4xing all kinds of We use the pnpId from node-serialport for ID.
br Lars
|
On Tue, Nov 12, 2013 at 9:00 PM, Florian Bender notifications@github.comwrote:
The geek in me says: yup - path should be fine .. I can just do a "port If you replace "user" with "geek", then I am in agreement. If "user" is
|
Note that in the above, what could be added is an "advanced" option to allow more geeky users to explicitly provide the port, or show the ports that the user agent didn't rank as important (e.g., the ones that didn't have a manufacturer or vendor and product ID, so didn't get an icon). |
Hi Marcos, From the UI mockup itself, I am not sure I get 100% how the detection and Thoughts? br On Tue, Nov 12, 2013 at 9:38 PM, Marcos Caceres notifications@github.comwrote:
|
On Tue, Nov 12, 2013 at 9:43 PM, Marcos Caceres notifications@github.comwrote:
|
@larsgk the PnP details for the midi device are acquired from USB. This "Proxima Direct® USB to Midi Cable Keyboard to PC Laptop Adapter" is what I've got here at home. I think we are all on the same page here and in agreement that we need the metadata to make decisions. I personally think that, of the three options you presented, only 1 is really viable on the web. However, we need to do some experimentation. |
@rwaldron, to be clear 'only has a path' is true only for the older RS232 ports. RS232 ports were 'obsoleted' on the PC alongside the floppy disk and the ISA bus back in August 2000 with the introduction of the Legacy-Free PC spec. Raise your hand if the computer you're using to browse Github has a nine pin RS-232 port on the back of it. Anyone? (edit: cough, sadly, my Dell T7600 workstation does...) In all other use cases we're discussing, the device is connected via USB (directly or indirectly) and has a mandatory USB Device Descriptor record associated with it. Let's not optimize for the vast minority case of only having a Path available. This cuts out the ability to make intelligent decisions on what device to talk to and places a technical burden on end users with insufficient information to make an informed choice. USB Device Properties Manufacturer and Product and Serial Number are programmable in the firmware of the USB device and can be used to convey detailed information when leveraged properly -- such as 'this device has Firmata 1.1 installed on it'. This would be very helpful for your own Johnny Five project, let's not lose this ability. The current behavior of node-serialport to not properly expose these properly on Linux or Windows can be fixed. This isn't a limitation of what can be done, it's a limitation of the state of the code as of today. I've already filed issue node-serialport #256 to get this fixed. We're correct that this isn't the spec for node-serialport, but let's be clear that a lot of the discussion here is being driven by the principals from the node-serialport project who have experience writing a well leveraged javascript API for serial ports. I'm assuming that like me, their motivation is to have as close as possible an API experience between the browser and nodejs, so let's not drive divergence when we don't have a strong reason. |
@JayBeavers, that's awesome. If serialport/node-serialport#256 shows that it's possible to have vendorId, productId, serialNumber, manufacturer, and product be consistent across platforms, then we are cooking :D I will add those, along with (platform specific) |
After reading everything that's been posted since I last responded, I feel like clicking the "Ignore" button this repo. @larsgk Yes, I too would prefer to have all the nice human readable property values |
@rwaldron please don't lose faith - we are trying to do our best here and nothing is set in stone. We are going to have to do some iterations to come up with a good design. Will try to find you on IRC for a chat so I can get a better understanding of your concerns. |
@marcoscaceres The only technical concerns I have are complexity and it appears those have been addressed in an agreeable way. |
#25, #20, #19, #4, #26) Detailed discussions are in #25, #20, #19, #4. * Defined how requestPorts() method works * defined how getInfo() works * made SerialPortInfo into a map (was SerialPortDetails) * introduced the concept of "recommended serial port metadata" * defined the rules for "getting serial port metadata" * Updated the security considerations section. * removed pnpId
#25, #20, #19, #4) Detailed discussions are in #25, #20, #19, #4. * Defined how requestPorts() method works * defined how getInfo() works * made SerialPortInfo into a map (was SerialPortDetails) * introduced the concept of "recommended serial port metadata" * defined the rules for "getting serial port metadata" * Updated the security considerations section.
* Define how ports are requested, including security/privacy model (closes #25, #20, #19, #4) Detailed discussions are in #25, #20, #19, #4. * Defined how requestPorts() method works * defined how getInfo() works * made SerialPortInfo into a map (was SerialPortDetails) * introduced the concept of "recommended serial port metadata" * defined the rules for "getting serial port metadata" * Updated the security considerations section. * style: whitespace fixes
I'm goin to throw a wrench into the mix here (years later) and say that some of the port info information, like BaudRate isn't really knowable until the operation of opening a port has happened. For example, you could provide an invalid buadrate and you wont know that it's invalid until after you've opened the port, set the rate and checked it again. These syscalls are sometimes blocking and better done asynchronously. Furthermore the information retrieved while enumerating the operating system for available ports is also often only available in a partially blocking or asynchronous fashion (interrogating services, the registry, usb, etc). Browsers may be able to cache this information by I think an async factory function to open and return ports would work around these limitations and allow us to return open port objects full of information. I don't think it's a good idea to do it in a blocking way during a serialport's object construction. |
Hi @reconbot 👋, would you mind formally joining the WICG? Your input will be invaluable as this ramps up again, so want to make sure you are formally part of the group. |
I'm pretty sure I have haven't I?
…On Tue, Sep 25, 2018, 10:16 PM Marcos Cáceres ***@***.***> wrote:
Hi @reconbot <https://github.com/reconbot> 👋, would you mind formally
joining the WICG?
https://www.w3.org/community/wicg/
Your input will be invaluable as this ramps up again, so want to make sure
you are formally part of the group.
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#20 (comment)>, or mute
the thread
<https://github.com/notifications/unsubscribe-auth/AABlbrGyhjl16n58xuA5yA-k6w1mauXWks5ueuOKgaJpZM4BLZJL>
.
|
Oh, apologies @reconbot. Just making sure! |
I wasn't sure, but I'm pretty sure now 👍 |
The
SerialPortDetails
dictionary currently has the following properties:However, an instance of
SerialPort
is currently lacking those properties. It seems annoying to have to request the available ports in order to find out the details about a port itself. You would have to find the matching object, etc. etc. which is just painful.I suggest we add the above as attributes to instances of
SerialPort
itself.The text was updated successfully, but these errors were encountered: