Looking for some mutex-like mechanism for exclusive USB access - google-chrome-extension

I'm working on various USB hardware devices, each of which implementing a serial port. I'd like to access such serial ports by multiple (Chrome and non-Chrome) applications running on the system in a pseudo-parallel fashion.
Basically I'd like to use some mutex-like atomic primitive so that I could make sure that one application has access to the serial port at the same time and the others are temporarily blocked, waiting for the mutex to be released.
I'm afraid that the Chrome API doesn't offer any such low-level primitives but please disprove me. Also, I'm open to any suggestions.

I've just finished reading the full Chrome packaged apps API and mutexes are definitely not supported but mutexes only work inside a process anyways so it's not what I'm looking for to begin with.
I could create a native app that could bind to multiple ports on the local loopback interface and proxy those connections towards the /dev/ttyACM* serial interface.
The other solution is implementing multiple serial ports for my USB device in the firmware so that multiple clients could connect to my device without interference.
I think I'll go with the latter solution because I don't want to have a daemon proxy running in the background all the time.

Related

WebUSB API, for pushing commands/configuration to the device through webApp

I am doing some research on the WebUSB API for our company because we are going to start to manufacture devices in house.
Our current device manufacture comes with an application so the team can plug the device into a computer and diagnose it. Their application allows us to read outputs from the device, as well as pushing commands/configuration to the device over a wired connection.
Since this device is 100% ours, we are also responsible for building out the diagnostic tooling. We need some sort of interface that allows a user to read outputs and send commands/configuration to the device over a wired USB connection.
Is the webUSB the correct API? If not, what are some suggestions for accomplishing the requirement? Are we limited to building some sort of desktop or mobile application?
I would recommend resources below to read to help you understand if the WebUSB API fits your needs or not:
https://web.dev/devices-introduction/ helps you pick the appropriate API to communicate with a hardware device of your choice.
https://web.dev/build-for-webusb/ explains how to build a device to take full advantage of the WebUSB API.
From what you describe, WebUSB isn't strictly required but won't hurt either.
First and foremost, you will need to implement the USB interfaces reading data and sending configurations. It will be a custom protocol, and not one of the standard USB device classes such as HID, video or mass storage. The details of the protocol and if you use control, interrupt or bulk transfers is your choice.
I'm assuming you will connect the devices to Windows PCs, and you likely don't want to put money into writing device drivers. If so, the easiest approach is to add the required descriptors and control requests required for Microsoft OS 2.0 Descriptors. That way, the WinUSB driver will be installed automatically when the device is plugged in.
Using the WinUSB API, a Windows application will then be able to communicate with the USB device. No additional drivers are needed. (On macOS and Linux it's even easier as you don't need the Microsoft OS 2.0 Descriptors in the first place.)
On top of that you can implement the additional descriptors and control requests for WebUSB. It will provide the additional benefit that you can write a web application (instead of a native application) for communicating with the USB device. (Currently, you are restricted to the Chrome browser.) WebUSB devices should implement the WinUSB descriptors as the alternative (.INF files, manual installation process) is a pain.
The already mentioned web page https://web.dev/build-for-webusb/ is a complete example of how to implement it.

How to communicate using libcoap over USB in linux?

I would like to communicate over USB using COAP protocol.
I am currently planning to use libcoap, it has examples but it is based on UDP server-client.
If I want to use USB, what must be done?
Thanks
Depends a bit on the deployment scenario, but in general I'd recommend using USB Ethernet inbetween (CDC-ECM). Then you can use CoAP over USB like you use it over any other network connection. (If you use RIOT for your embedded device and build the gcoap example on a board with native USB and enable the usbus_cdc_ecm module, you get that almost out of the box).
The large downside of this approach is that you are subject to the whims of the host OS's network setup. Probably it'll take up at least the IPv6 link-local interface so you can go ahead with requests to fe80::addr:ess (or even use link-local multicast to find your device), but there may be pitfalls.
There is the slipmux proposal which would do CoAP over serial, but a) I don't know implementations thereof, and b) it leaves you with similar issues of how to make sure your application can really find the right serial port.
It wouldn't be impossible to specify CoAP over custom USB commands (which would then be taken up by an application), but there'd need to be really good reasons not to just go through USB networking to justify them, and I'm not sure that the complexity of ensuring that your NetworkManager is set up correctly counts.

Ethernet driver for ethercat modules

I have EK1101, EL6002, EL2034 modules which is based on network devices. These modules are connected PC Ethernet port via ethernet cable. I have tested these modules with some application program, its working fine on my PC.
EK1101 working as a Coupler. It connects PC Ethernet Port and Other slave modules( EL6002, EL2034,..)
EL6002 working as a RS232 communication. EL2034 working as digital I/O. Similarly we have more than 10 different devices. These modules interfaced with EK1101 coupler at same time.
How can i implement as Linux driver? and start?Do I modify the existing network driver or start new driver from scratch? what type of i need to write, character or network driver? If its character driver how can i transfer data through Ethernet port?
Using the serial slice (EL6002) you can only send 22 bytes (each direction) per exchange for each port. At full serial bandwidth (115k) updating at 1kHz, you won't be able to miss an update without starving the transmitter and/or dropping data on the receiver. If that's a concern you will probably need to claim exclusive control over the Ethernet port being used to master the EtherCAT loop. This requires some form of root permissions, otherwise someone can always try to send packets over the port, affecting your timings. You haven't given much detail about your application or timing requirements, so maybe that's not critical for you.
I've been using the Etherlab IgH open source stack, which requires root permissions to load its kernel module which implements the underlying stack. Once that's done you can set everything else up to run from user space without root permissions.
Once your application acquires access to the master stack, you setup a data exchange domain (what TwinCat calls a task) and you will have a region of shared memory that can be used to monitor the EtherCAT frame data. Your application is responsible for deciding when to send and receive domain updates.

Controlling a parallel port via USB adaptor on modern hardware and OS

I have a USB to parallel port device that i want to interface with through c++ on a modern windows OS (xp and newer).
I've done a little research but the information is a bit patchy when it comes to programming to one of these USB to parallel port devices (most of the information is dated and assumes that you have a parallel port built right into the motherboard, something my brand new computer doesn't have). One reference even says that it is not possible to interface with a USB to parallel port from a C++ program without some sort of software changes.
All i want to do is to is be able to read or write 8 bits to the parallel port through a USB to parallel port device on a modern computer running a modern windows OS (with ports being dedicated to reading or writing only).
Is there any quick and easy way of doing this? Some sample code would be greatly appreciated.
Also, how many of these USB to parallel ports can I interface with my computer? Am i limited to 3 due to some sort of legacy addressing or can i have as many as my USB and CPU are able to support?
Working off VC++ 2008, running Windows 7 x64 with a Core i7 860.
Edit: a bit more information...
I've tried using inpout23 along with some prewritten test program. It compiled just fine and ran just fine claiming to have both read and written to a parallel port. I had my USB to parallel port connected to the computer and that port connected to a cable in which i had identified, stripped and soldered each of the 25 wires onto a sort of plug for quickly plugging into a breadboard for testing. None of the output pins had changed to what the program had said was written to them (instead they were all set to high and never changed).
I've done this in the past and I have good news and bad news.
The good news is that it always worked (sometimes with tweaking), which is a tribute to the electronic manufacturers of designing extremely robust protocols. Apparently the USB to parallel converters all provided the hardware port emulation.
The bad news is that performance was awful on the 'bitbanging' interface models. If you do not mind slow updates this is not an issue at all. I used it for programming uControllers and soon the price of serial or USB programmers was overcome by my impatience.
Just use the windows API to read/write the LPT or COM ports and it works (slowly).
I've worked with a USB-to-serial port adapter before and I guess USB-to-parallel should be the same. You should have got a driver along with the adapter - this does most of the work for you, hiding the USB interface and presenting it to the OS as a traditional parallel port. For example, when I plug my adapter into the USB port, it just shows up as COM4 in Device Manager. I'm guessing yours will show up as LPT1 or something. From there on, it's a matter of using the standard Windows API to access these ports. (see Communications Resources on MSDN)
Misteriously I succeed with the USB to LPT-DB25 Wire bought in ebay.com.
We should connect a LED between the /LF Line Feed and GND pins.
After discard the USB registers in order to find that one associated to the USB Cable, we should build an API (Application Programming Interface) to interact with the outputs/Registers.
I'm going to try to attach a picture to have a look how I managed it:

Accessing Bluetooth virtual COM port on Windows without manual pairing

I need to connect to a Bluetooth device through virtual COM port created in Windows. It's easy when the port has been already created during manual pairing procedure. But I would like my application to relieve an user from the manual pairing of a device. I would like to present all devices in the range, allow user to chose one, and then create virtual COM port connected with the selected device. I'm not trying to avoid the pairing procedure itself, but rather I would like to invoke it by my application.
I started getting familiar with Microsoft Bluetooth API. And then some doubts arose. I've been wondering what happen if some user would use different (than Microsoft's) Bluetooth stack? Is the Microsoft's API the real Bluetooth API, which have to be implemented by any other Bluetooth stack provider? Or rather each provider has its own API, and the Microsoft's is only one of many other?
Thanks everyone for valuable input. I'd like to summarize what I've found so far. The Microsoft Bluetooth API is not operating system API. Application written against it will not cooperate correctly with any other Bluetooth stack. It seems that applications which are intended to cooperate with multiple stacks need to provide some stack abstraction layer, and stack specific code for all of them.The other solution is to allow user for manual pairing of the Bluetooth device, which eventually create some virtual device in the operating system (e.g., COM port). Then the application can use standard interface of such a device.
I can't speak for the Microsoft Bluetooth API, but there are multiple Bluetooth stacks available for the PC platform (even more for mobile devices).
The underlying API is defined by the Bluetooth Core Spec and so all stacks should be able to interact, in fact it is mandatory that they interop or they cannot use the Bluetooth name and logo.
As to pairing, your going to have a hard time getting devices to pair if they have default security, which requires a pin code.
Things might be simpler in the (near) future, as the Bluetooth standard has introduced a new security model, secure simple pairing, which has a 'just works' mode that requires no Pin code. This is still stronger then the current security, except against Man in the middle attacks. However, it could be a while before you see the chips with this feature in PCs.
If you can change to using .NET :-/ I can recommend our library 32feet.NET.
For explicit pairing there's BluetoothSecurity.PairDevice. We can also create the virtual port for you, for example:
BluetoothClient cli = new BluetoothClient();
BluetoothDeviceInfo[] list = cli.DiscoverDevices();
BluetoothDeviceInfo selected = GetUserToSelectOne(list);
BluetoothSecurity.PairDevice(selected, pin);
// Ask Win32 to create a virtual serial port
selected.SetServiceState(BluetoothService.SerialPort);
However I really don't like virtual serial ports so I always suggest that people use a normal sockets connection using our BluetoothClient class, it will automatically handle a pairing request if required.
On Win32 we support the stacks from Microsoft, Widcomm/Broadcom, and BlueSoleil. On Widcomm there's no support for SetServiceState there yet, and their API has no support for responding to pairing requests. BlueSoleil should support both.
A brief user's guide is at 32feet.NET — User’s Guide, and all the class documentation is available at the main site http://32feet.net, the Widcomm documentation is only in our code repository at the moment.

Resources