Page 1 of 1

about getdeviceserialnumber

Posted: Wed Apr 27, 2022 2:36 am
by Cuijwyn
I have three phidgetspatials that link to pc through usb. I use "getdeviceseiralnumber" to get device serial numbers,but I only get one device serial number. how should I do to get other device information.
thanks

Re: about getdeviceserialnumber

Posted: Thu Apr 28, 2022 9:04 am
by mparadis
If you're getting the device serial number that means you've already opened the channel. When you call open, it will open the first device of the appropriate channel that it can find. For example, in python:

Code: Select all

ch0 = Accelerometer()
ch0.openWaitForAttachment(5000)

print(str(ch0.getDeviceSerialNumber()))
So in this case, ch0 is the first Accelerometer object that your program could find, so you'll only get one number. If you open all three and call getDeviceSerialNumber on all of them, you'll get three different numbers:

Code: Select all

ch0 = Accelerometer()
ch1 = Accelerometer()
ch2 = Accelerometer()
ch0.openWaitForAttachment(5000)
ch1.openWaitForAttachment(5000)
ch2.openWaitForAttachment(5000)

print(str(ch0.getDeviceSerialNumber()))
print(str(ch1.getDeviceSerialNumber()))
print(str(ch2.getDeviceSerialNumber()))

You can also set the deviceSerialNumber before opening to ensure you open a specific spatial instead of the first one your program comes across:

Code: Select all

ch0 = Accelerometer()
ch0.setDeviceSerialNumber(123456)
ch0.openWaitForAttachment(5000)

Re: about getdeviceserialnumber

Posted: Fri Apr 29, 2022 4:10 am
by Cuijw
yes, I can get three device numbers following your advice. But I find it is not right for javascript. my scripts like this:
const ch0 = new phidget22.Accelerometer();
const ch1 = new phidget22.Accelerometer();
await ch0.open(5000);
await ch1.open(5000);
const deviceSerialNumber0 = ch0.deviceSerialNumber;
const deviceSerialNumber1 = ch1.deviceSerialNumber;
console.log("deviceSerialNumber0: " + deviceSerialNumber0);
console.log("deviceSerialNumber1: " + deviceSerialNumber1);
are there any problem for these scripts

and I have other questions:
1. I download the Accelerometer example for browser, when I run it, I met the"localhost show:failed to connect to server:PhidgetError: websocket error - check that server is available" and "No Phidget Attached"
2. I use a javascript in html that javascript text is from "https://www.phidgets.com/?tier=3&catid= ... rodid=1204" example, but there is a error for require(). html can not resovle require. My question is how to import phidget22 module

Re: about getdeviceserialnumber

Posted: Fri Apr 29, 2022 8:03 am
by Cuijw
it is right following your advice, but when I use javascript, it does not work, my code is:
const conn = new phidget22.USBConnection();
await conn.connect();
const ch0 = new phidget22.Accelerometer();
const ch1 = new phidget22.Accelerometer();
await ch0.open(5000);
await ch1.open(5000);
const deviceSerialNumber0 = ch0.deviceSerialNumber;
const deviceSerialNumber1 = ch1.deviceSerialNumber;
console.log("deviceSerialNumber0: " + deviceSerialNumber0);
console.log("deviceSerialNumber1: " + deviceSerialNumber1);
are there any problem?

For javascript, I have other questions:
1.when I run "Phidget22_Accelerometer_JavaScript_Browser_Ex_20220413",it shows "localhost:63342 show failed to connect to server:PhidgetError: websocket error - check that server is available" and "No Phidget Attached"
2. when I use javascript example in html, I met a error: require can not be resolve by html, my question is how to import phidget22 module in html+javascript

Re: about getdeviceserialnumber

Posted: Fri Apr 29, 2022 9:28 am
by mparadis
One thing to note about your javascript code is that it's using phidget22.USBConnection, which means it will try to open the Phidgets using WebUSB. Only VINT devices are supported under WebUSB, so if you're using a USB spatial like the 1044 you will need to use the NetworkConnection object instead.

I don't see anything else wrong with your javascript. Can you confirm that you are using version 3 of the phidget22 javascript package? The code you pasted uses syntax that is only supported in the recently released version 3.

When you say the code "does not work" what does it do? Are there any errors?

As for the HTML examples, double check to make sure the Network Server is running in the Phidget Control Panel. Then check the code sample to make sure the hostname and port match that of your hosted Network Server.

Re: about getdeviceserialnumber

Posted: Sun May 01, 2022 2:44 am
by Cuijw
the code "does not work" means I need it to get three device serial numbers , but it gives three same.

when I use phidget22.networkconnection, I get an error "PhidgetError: authentication failed: server rejected proof" and I don't know how to authentication. I got phidget22.js just recent days.

Thanks

Re: about getdeviceserialnumber

Posted: Mon May 02, 2022 1:37 pm
by mparadis
I just realized since we're talking about VINT spatials (they must be if you're using the USB object), these devices don't have their own serial number. When you request the serial number of a VINT device, you get the serial number of the Hub it's connected to. You can address the individual VINT devices using the Hubport property. Just like serial number, you can set Hubport before opening so you know which variable will correspond to the chosen port.