Get information from /dev/sda - usb

I'am able to detect the presence of USB device connected or not to my embedded device imediattely after the boot, using
access(path, F_OK);
function, where path is /dev/sdax with x=1,2,...
Next step is retrieve from /dev/sdax which type of device is conncted (e.g. pen drive, mouse, etc etc), maybe I could use "udev" and/or "libudev", but in this case I loose the information about which sdax is pointed.
Any suggestion? I'm looking for some IOCTLs, but I didn't found somenthing which return e.g. vendor id

Related

Pass values from two Barcode Scanners to two specific texboxes.

I have two textboxes in a windowsform textbox1 and textbox2, I am trying to use two barcode scanners to send the values to each textbox.
If i Scan anything from Barcode Scanner 1 it should send value to textbox 1 without clicking on it!.
If i Scan anything from Barcode Scanner 2 it should send value to textbox 2 without clicking on it!.
Is there a way to do this?
Barcode scanners that are USB utilize HID or Human Interface Device. Typically, these are devices that humans use to directly control the operation of computer systems.
Microsoft offers a complete break down in this technology, I wish I could up load the PDF. I hate posting url's, as they can become stale; https://learn.microsoft.com/en-us/windows-hardware/drivers/hid/introduction-to-hid-concepts
There are a few API's you can research and can be found above, I would investigate these:
Device Discovery and Setup
The following list identifies the HID API that an application can use to: identify the properties of a HID device, and to establish communication with that device. In addition, an application can use some of these API to identify a Top Level Collection.
HidD_GetAttributes
HidD_GetHidGuid
HidD_GetIndexedString
HidD_GetManufacturerString
HidD_GetPhysicalDescriptor
HidD_GetPreparsedData
HidD_GetProductString
HidD_GetSerialNumberString
HidD_GetNumInputBuffers
HidD_SetNumInputBuffers
Data Movement
The following list identifies the HID API that an application can use to move data back and forth between the app and a selected device.
HidD_GetInputReport
HidD_SetFeature
HidD_SetOutputReport
ReadFile
WriteFile
Another approach would be to see if the barcode scanner could emulate a serial port. This would denote which scanner is which, via the comm port.
For such use, there is POS for.NET or OPOS.
Both are part of UnifiedPOS.
Document -- retail/17-07-32 (UnifiedPOS Retail Peripheral Architecture, Version 1.14.1)
There is information and download here.
POS for .NET v1.14.1 SDK Documentation
Download Microsoft Point of Service for .NET v1.14.1 (POS for.NET)
OPOS
CCO Current Version
Since the program that actually controls the scanner is provided by the scanner vendor, you will obtain it.
Using them you need to create control objects for each individual scanner.
Which object is responsible for which scanner is specified by the DeviceName parameter of the Open method. The DeviceName is associated with USB VID/PID or connected COM port by configuration file or registry data.
Barcodes can be read from the scanner by processing Open, Claim, DeviceEnabled=true, DataEventEnabled=true on that object.
The object is notified by the DataEvent that the barcode has been read.
An application can register a separate event handler for each object, or by registering the same event handler and determining the sender parameter of the event notification, it is possible to identify from which scanner the barcode was read .
An application can read barcode data from the properties of the corresponding object and write it in the corresponding TextBox.

Can I use a USB pen drive with libusbdotnet

I have just started on libusbdotnet. I have downloaded the sample code from http://libusbdotnet.sourceforge.net/V2/Index.html.
I am using a JetFlash 4GB Flash drive (a libusb-win32 filter driver was added for this drive).
The ShowInfo code works perfectly, and I can see my device info with two endpoints. Following is the device info from pastebin
http://pastebin.com/2Jdph6bY
However, the ReadOnly sample code does not work.
http://pastebin.com/hNZaEt8N
My code is almost same as that from the libsubdotnet website. I have only changed the endpoint that UsbEndpointReader uses. I have changed it from Ep01 to Ep02, because I read that the first endpoint is a control endpoint used for configuration, access control and similar stuff.
UsbEndpointReader reader = MyUsbDevice.OpenEndpointReader(ReadEndpointID.Ep02);
I always get the message "No more bytes!".
I thought that this is because of the absence of data, so I used the ReadWrite sample code.
http://pastebin.com/NiN5w9Jt
But here I also get "No more bytes!" message.
Interestly, the line
ec = writer.Write(Encoding.Default.GetBytes(cmdLine), 2000, out bytesWritten);
executes without errors.
Can pen drives be used for read write operations? Or is something wrong with the code?
A USB thumb drive implements the USB mass storage device class, which is a subset of SCSI. The specification is here.
You're not going to get anything sensible by just reading from an endpoint - you have to send the appropriate commands to get any response.
You have not chosen an easy device class to begin your exploration of USB - you may be better starting with something easier - a HID class device, perhaps (Mouse/Keyboard) though Windows does have enhanced security around mice and keyboards which may prevent you installing a filter.
If you meddle with the filesystem on the USB stick while it's mounted as a drive by Windows, you'll almost certainly run into cache-consistency problems, unless you're extremely careful about what kind of access you allow Windows to do.

Route audio to specific device output on OS X

Am looking to add a preview channel to an AV project, so that a video or audio file can be playing on the master output channel but the user can preview a separate audio or video file on a different channel.
Naturally the prerequisite is that the user has a sound device capable of multiple channels or a separate device for master output than for preview. For example, the output could go to a USB audio device which provides balanced audio output but the preview could be via the standard headphone jack.
I am struggling to find the right documentation on enumerating sound devices connected to the mac and then linking either AVAudioPlayer or AVPlayer/AVPlayerLayer or an underlying API.
Anyone know where I should be looking?
Is this a case of discovering the sound devices, selecting the appropriate one then using something like NSSound to set the device before I start playing the file? What happens with files already playing?
Thanks
Note that AVAudioSession is iOS-only.
You can change the audio output device for a given AVPlayer instance by setting the instance property 'audioOutputDeviceUniqueID' to the UniqueID of the desired device. This also works for AVAudioPlayer.
I can confirm that it works as expected in MacOS 10.11.6, using Key-Value coding ( setValue:forKey:). The AVAudioPlayer API also has a specific method to do this 'setCurrentDevice:'
The messiest part of the process is obtaining the list of valid UniqueIDs for the current system. 0 always means' System Default", but any other specific device is identified by a CF$ that appears to be constructed by CoreAudio at runtime using the a combination of manufacturer's name, product name, and a bunch of other mysterious codes. The process to get the current list is described here: AudioObjectGetPropertyData to get a list of input devices
Apple's doc on 'audioOutputDeviceUniqueID' :
Instance Property
audioOutputDeviceUniqueID
Specifies the unique ID of the Core Audio output device used to play audio.
Declaration
#property(nonatomic, copy) NSString *audioOutputDeviceUniqueID;
Discussion
The default value of this property is nil, indicating that the default audio output device is used. Otherwise the value of this property is a string containing the unique ID of the Core Audio output device to be used for audio output.
Core Audio's kAudioDevicePropertyDeviceUID is a suitable source of audio output device unique IDs.
Please check EZAudio.
There is EZMicrophone and EZOutput.
By using them, you can route audio to specific device output on OS X.

Can I have same upnp device with different description/services during run time?

While going through upnp spec I got the following doubts .
Can I define a basic upnp device with all mandatory fields and with no servicelist and
when providing the description xml I will modify my description xml to advertise my service based to different conditions.
eg: services may playmusic OR switch light OR playfootball.
Can i modify the xml per device basis on run time to inlcude completely different and random services?
I hope the description and service xmls are not static .
Just like almost everything else in UPnP Device Arch document this is not 100% clearly defined, but the idea of dynamic device/service descriptions is mentioned:
If a device needs to
change one of these descriptions, it MUST cancel its outstanding
advertisements and re-advertise. Consequently, control points SHOULD
NOT assume that device and service descriptions are unchanged if a
device re-appears on the network, but they can detect whether
descriptions changed if a changed CONFIGID.UPNP.ORG field value is
present in the announcements.
So descriptions are not static, but you do need need to cancel and re-advertize.
That said, abusing this does not sound useful (Why not use separate root devices or at least sub-devices for totally unrelated services) and is bound to lead to compatibility issues.

How to use the USB/HID port with objective-c under a Mac environment

I try to implement an application in snow Leopard, Reading Data from USB/HID device.In my application i tried following steps:
IOHIDManagerCreate()
CreateDeviceMatchingDictionary()
IOHIDManagerSetDeviceMatching()
IOHIDManagerOpen()
IOHIDManagerCopyDevices()
Create a Reference for device(IOHIDDeviceRef)
Based On the IOHIDDeviceRef i Fetch device details such as(Device ProductIDKey, Device VendorIDKey,Device ProductKey,Device Serial NumberKey,Device VersionNumberKey ect.)
IOHIDDeviceOpen(),ie :Using IOHIDDeviceRef i opened Device;
IOHIDDeviceCopyMatchingElements(); Ie Copy Matching Elements from the Device;
Create a Reference element(ie IOHIDElementRef);
Using IOHIDElementRef i retrieved Device Usage,Device Cocookie,Device UsagePage etc.
Up to this My application working Fine.
My doubts are
How can read data From Endpoint 1, My device is special purpose device having only one End point(Interrupt no synchronization data end point)?
Is their any Pipe associated with end point 1(HID Device)?;
Is their any ReadPipe and WritePipe functions in HIDManager Based Application?
Is it possible to retrieve data from USB/HID using IOHIDDeviceSetReoprtWithCallback()?
Every thing Did based on this Link:
http://developer.apple.com/library/mac/#documentation/DeviceDrivers/Conceptual/HID/new_api_10_5/tn2187.html#//apple_ref/doc/uid/TP40000970-CH214-SW7 ...
Thank you so much for your help ..
You are trying to use HID functions with non-HID device.
HID is Human Interface Device. Any HID device must conform "Device Class Definition for HID".
I suspect, your device does not conforms this specification.
So you should use other OS interface to work with your device. I suggest to use libusb. This is cross-platform library for working with USB devices on low level. It will allow you to read/write your endpoint directly.