1. portable devices - USB - and other horrors

I need some help. Devices in Euphoria. I need to interface with the keyboard and two additional serial (USB) devices. I do not have access to the machines nor do I know what else is attached to them. I need to know how (under Euphoria) to generate a list of system attached devices with device numbers or addresses that I can then use in an open(??,"r") instruction to attach to the device by generating a file number. Perhaps a system_exec() command to the system to generate a file which I can then open and parse?? Ultimately I want to to end up with a command:

sequence txt = gets(fn)

It's the "fn" that's causing the difficulty.

Please remember that things like device_view, control panel\device_manager, or Windows Portable Devices, etc. will probably not work as user intervention is required. It's probably easy and I am overly complicating it!

Ah, the good old days of "com 2:"

Thanks in advance for any guidance you can offer.

Regards,
jd

new topic     » topic index » view message » categorize

2. Re: portable devices - USB - and other horrors

USB device access is complicated to say the least.

If you've got USB-to-serial devices, they should still show up as "COM1" or whatever, so you may be able to still use that. But, if you need to reconfigure the port settings, you'll have to use the Communications API.

As far as direct USB device access, I think you'll have to use the WinUSB API. But, a keyboard is going to be detected as a HID device and Windows probably won't let you talk to it directly.

Unless we're talking about a musical keyboard, which probably shows up as a MIDI device.

-Greg

new topic     » goto parent     » topic index » view message » categorize

3. Re: portable devices - USB - and other horrors

Thanks for the quick reply. Two observations, so far:

1. There must be a way to do this. All I need is an input buffer to accept the character string from the device and an output buffer for sending info to the device. No driver or other software is supplied by the mfg. It relies on the fact that USB HID devices tell the OS what is required. Since there is no driver it must rely on a standard OS supplied driver. This is probably OK until two of these get plugged into the same machine. The, relatively dumb, OS just sends all the data to the same buffer. Try plugging two keyboards into the same machine and watch what happens! 2. I suppose I could supply some additional hardware to go between the device and the OS. All this would accomplish is to kick the can down the road. It would require a custom driver but at least one could add a device ID so more than one could be connected at a time. The thought of a hub comes to mind. The hub must somehow indicate to the parent which device is talking now, even if all devices are the same. 3. Even if there is a way to separate out all the devices I still need to know how to tell Euphoria which buffer to look at. The old integer fn = open( "com1:","r/w") should still work as the OS still does assign a logical device name to a physical port, even in windows 10. 4. I don't know enough to do this. Out of my depth. I just thought someone out there might have run across a solution. The archives only have one entry for USB.

new topic     » goto parent     » topic index » view message » categorize

4. Re: portable devices - USB - and other horrors

jessedavis said...

I need some help. Devices in Euphoria. I need to interface with the keyboard and two additional serial (USB) devices. I do not have access to the machines nor do I know what else is attached to them. I need to know how (under Euphoria) to generate a list of system attached devices with device numbers or addresses

Depends on the OS. On Linux/GNU, this is trivial - just run a system() command to redirect the output of "lsusb -v" to a file. Then open and read and parse that file.

That said, you hint later below that this is for Windoze. So, you can use the wmic command to get similar information (albeit in a different but still human-readable format).

wmic path CIM_LogicalDevice where "Description like 'USB%'" get /value 

https://stackoverflow.com/questions/44433346/

jessedavis said...

that I can then use in an open(??,"r") instruction to attach to the device by generating a file number. Perhaps a system_exec() command to the system to generate a file which I can then open and parse?? Ultimately I want to to end up with a command:

sequence txt = gets(fn)

It's the "fn" that's causing the difficulty.

Much easier under Linux/GNU, which has a variety of ways to get to a USB device, e.g. /dev/bus/usb/addr1/addr2 or /dev/ttyUSB* specifically for serial devices or /dev/input/* for USB keyboards et al, and /dev/disk/by-id/usb* for usb disks and flashdrives.

For Windoze, "COMX:" would probably work for the serial devices. I'm not sure how you'd directly access a USB keyboard if you needed to do that. Assuming by "keyboard" you just mean standard input - gets(0) and friends are enough for that.

Hopefully the output of wmic would help you identify which COMX: port to use. (I don't have access to a Windoze box atm to test.)

jessedavis said...



Please remember that things like device_view, control panel\device_manager, or Windows Portable Devices, etc. will probably not work as user intervention is required. It's probably easy and I am overly complicating it!

Ah, the good old days of "com 2:"

Thanks in advance for any guidance you can offer.

Regards,
jd

Would help if we knew what you were specifically trying to do. Forward input from the keyboard into the two serial devices on a Windoze server?

new topic     » goto parent     » topic index » view message » categorize

5. Re: portable devices - USB - and other horrors

Heh. Must have crossed posts.

jessedavis said...

Thanks for the quick reply. Two observations, so far:

1. There must be a way to do this. All I need is an input buffer to accept the character string from the device and an output buffer for sending info to the device. No driver or other software is supplied by the mfg. It relies on the fact that USB HID devices tell the OS what is required. Since there is no driver it must rely on a standard OS supplied driver. This is probably OK until two of these get plugged into the same machine. The, relatively dumb, OS just sends all the data to the same buffer. Try plugging two keyboards into the same machine and watch what happens!

A bit confused now. I thought you were trying to send data between two USB serial devices, not two USB HID devices.

jessedavis said...

2. I suppose I could supply some additional hardware to go between the device and the OS. All this would accomplish is to kick the can down the road. It would require a custom driver but at least one could add a device ID so more than one could be connected at a time. The thought of a hub comes to mind. The hub must somehow indicate to the parent which device is talking now, even if all devices are the same.

How much control over the choice of hardware do you have? If accessing a keyboard directly is required, can you request an RS-232 keyboard to be connected to a third USB-serial device? Then you'd be able to read from that keyboard via another COMX: port.

It's hard to get a true RS-232 keyboard these days, but I think this combination should work:

PS/2 keyboard ( https://www.amazon.com/Serial-Standard-Keyboard-70011-Windows/dp/B0075W8C8S/ref=sr_1_1?keywords=serial+keyboard ) + PS/2-to-RS-232 adaptor ( https://www.versalent.biz/seradpt.htm ) + usb serial dongle ( https://www.amazon.com/rs232-usb-dongle/s?k=rs232+to+usb+dongle )

jessedavis said...

3. Even if there is a way to separate out all the devices I still need to know how to tell Euphoria which buffer to look at. The old integer fn = open( "com1:","r/w") should still work as the OS still does assign a logical device name to a physical port, even in windows 10.

So basically you just need a way to tell which COM port belongs to the USB devices that you are interested in?

If the output from the wmic command doesn't have enough information, then see this VBScript at message #6 of https://forums.ni.com/t5/LabVIEW/How-to-find-COM-port-for-a-specific-USB-device/td-p/1029382?profile.language=en

Just combine that script with some VBScript code to write the answer into a file (that you can then read from your Euphoria side) https://stackoverflow.com/questions/2198810/creating-and-writing-lines-to-a-file

You can then run your VBScript from inside system() by using CScript. See https://www.vbsedit.com/html/f1741259-9501-478b-bad6-36039a057410.asp for an example of how to invoke CScript from the command prompt. (I figure once you can call CScript from the command prompt, you can adapt it into a system() call pretty easily.)

Keep in mind the warning from earlier in the ni.com thread - COM ports assigned to USB devices tend to change upon a reboot. So maybe lookup the COM ports everytime the application starts up or something.

jessedavis said...

4. I don't know enough to do this. Out of my depth. I just thought someone out there might have run across a solution. The archives only have one entry for USB.

Understandable. Regretablly, what you're trying to do is not particularly common. Most application writers depend heavily on the vendor to provide a device driver to sort out these tpyes of problems. For example, a different ni.com thread reports that their solution (with a barcode scanner) was to reconfigure the driver to emulate a serial port (COM port) instead of a USB HID keyboard to be able to read characters from the device. https://forums.ni.com/t5/Instrument-Control-GPIB-Serial/usb-HID-to-serial-emulation/td-p/951513?profile.language=en

new topic     » goto parent     » topic index » view message » categorize

6. Re: portable devices - USB - and other horrors

Would it be difficult to add support for reading and writing to USB devices in Euphoria directly? Is there a wrapper for USB that could be made fairly easily?

EDIT: Maybe this is something that could work in the meantime? I'm starting on writing a wrapper for it, right now. LibUSB

new topic     » goto parent     » topic index » view message » categorize

7. Re: portable devices - USB - and other horrors

Icy_Viking said...

Would it be difficult to add support for reading and writing to USB devices in Euphoria directly?

Yes, it's a pretty low-level thing to do and (unless using a library like LibUSB to abstract it, it's quite OS-specific).

Icy_Viking said...

Is there a wrapper for USB that could be made fairly easily?

EDIT: Maybe this is something that could work in the meantime? I'm starting on writing a wrapper for it, right now. LibUSB

Wrapping LibUSB in Eu would be the best thing right now for those who need such low level access to USB devices in Eu.

new topic     » goto parent     » topic index » view message » categorize

8. Re: portable devices - USB - and other horrors

OK, STOP STOP STOP

I need time to study all this information!

Thanks to Greg for the pointers to Windows info on USB.

For Jim: To explain what I am trying to do.

There are two problems that I am working on. They just happen to both use USB serial devices.

Art Gallery: Inventory and point of sale software. This makes use of HID barcode scanners. There could be more than one connected as well as the keyboard or two. Ideal for Linux multi-user, multi-tasking. Unfortunately, Linux has spent too many years cultivating the difficult to use, really only for geeks persona. No one wants to open that can of worms. Please use Windows.

The other project involves old machine tools. Upgrading to 20th century. There is the NC controller, the position readouts, the manual control dongle, etc. One thinks RS-232 to USB converters. Problem is when the power cycles how do you figure out what is what. Not a problem in the "good ole days" when ports were hard wired to the os.

It's time to retireThanks...I'll try to report back.

jd

new topic     » goto parent     » topic index » view message » categorize

Search



Quick Links

User menu

Not signed in.

Misc Menu