I'm trying to connect to barcode scanner (is a HID device). I was able to receive data using RawInput, but I want to try using CreateFile().
deviceInformation.ReadHandle = Kernel32.CreateFile(
deviceInformation.DevicePathName,
Constants.GenericRead,
Constants.FileShareRead | Constants.FileShareWrite,
IntPtr.Zero,
Constants.OpenExisting,
Constants.FileFlagOverlapped,
0);
int it = Marshal.GetLastWin32Error();
CreateFile() returns this:
Marshal.GetLastWin32Error() returns 5 which is ERROR_ACCESS_DENIED
I'm using this source code as the reference.
My questions are: Is it possible to create a handle to that hid device using CreateFile()? If yes, why do I receive Access denied? and what is the correct way to create a handle?
PS: Windows 10, Visual Studio 2015
Related
I am using Lecia Disto e7100i which basically measures distance and area using laser. This device has bluetooth and can be paired with windows.
I am trying to develop an wpf app that reads the mesaured data using c#
There is no sdk that comes along with the device.
I have tried to use 32feet.Net but since there is no proper documentation I don't know where to start.
Is there any way that I can do to solve my problem?
This is not a full response, instead its more of a guideline on how to resolve your issue:
Pair the device with your Computer
Run the included software that displays the data somehow
Use WireShark to analyze the traffic
see if it is a standard protocol type or something custom
understand the protocol and reimplement it using c# and BluetoothSockets
To get started, you can try:
var client = new BluetoothClient();
// Select the bluetooth device
var dlg = new SelectBluetoothDeviceDialog();
DialogResult result = dlg.ShowDialog(this);
if (result != DialogResult.OK)
{
return;
}
BluetoothDeviceInfo device = dlg.SelectedDevice;
BluetoothAddress addr = device.DeviceAddress;
Console.WriteLine(device.DeviceName);
BluetoothSecurity.PairRequest(addr, "PIN"); // set the pin here or take user input
device.SetServiceState(BluetoothService.HumanInterfaceDevice, true);
Thread.Sleep(100); // Precautionary
if (device.InstalledServices.Length == 0)
{
// handle appropriately
}
client.Connect(addr, BluetoothService.HumanInterfaceDevice);
Also make sure that
Device appears in "Bluetooth devices" in the "Control panel".
Device is HID or change code accordingly.
Hope it helps. Cheers!
Try this demo project, and the following articles after that one.
Try to follow this tutorial
Here you can see a direct answer by the mantainer of 32feet, with which you can get in touch
Check also this answer
I'm trying to connect to a device (SecuGen Hamster Pro 20) through Windows.Devices.Usb APIs using Universal Windows App for PC only (no phones)(WinRT).
The device is a fingerprint scanner.
I've done all the steps found online to do that:
I've looked for all devices using:
var myDevices = await Windows.Devices.Enumeration.DeviceInformation.FindAllAsync();
This returns about 1400 devices. After some filteration using:
var resultList = myDevices.Where(s => s.Name.ToLower().Contains("secu")).ToList<DeviceInformation>();
resultList contains 3 devices in my machine (I've tried it on other machine and found 10 results on some).
I didn't use the overload for finding devices DeviceInformation.FindAllAsync(String aqsFilter) because it returns 0 results althought I'm sure I've done it right (used correct VID & PID)
The problem here is when I try to create a UsbDevice object from any of the 3 results using:
UsbDevice device = await UsbDevice.FromIdAsync(resultList[0].Id);
The return value is null, I've tried all of them (resultList[0] , resultList[1] , resultList[2]) with no luck.
I configured the capabilities using:
<DeviceCapability Name="usb">
<Device Id="vidpid:1162 2200">
<Function Type="name:vendorSpecific"/>
</Device>
</DeviceCapability>
I also tried to create a UsbDevice object from any of the 1400 devices returned from DeviceInformation.FindAllAsync() but all returned null and even some throw an exception that says the system cannot find the file specified 0x80070002
I tried to read DeviceAccessInformation for the device it returned DeviceAccessStatus.Unspecified
Anyone can lead me to what am I missing here?
You have to use UsbDevice.GetDeviceSelector and then use the selector when searching for the device. If that returns nothing, then the device isn't properly 'configured' to use the WinUSB.sys driver. (And from what I understand, it must use that driver to be used with the usbdevice class).
If you manually told it to use that driver in the device manager, then, in theory, you still have to change a key with regedit before that works (Note: I did that and it still wouldn't work). I found a solution that solved it here:
http://www.lewisbenge.net/2013/09/20/integrating-windows-8-1-with-owi-535-robotic-arm/
Basically, you have to install the driver using an inf file. use the one linked on that site and replace the NTamd64 with NTarm depending on the target platform
Firstly, try to narrow down your search by vendor and product Id
This method will help you do that:
public static async Task<List<wde.DeviceInformation>> GetDevicesByProductAndVendorAsync(int vendorId, int productId)
{
return ((IEnumerable<wde.DeviceInformation>)await wde.DeviceInformation.FindAllAsync($"System.Devices.InterfaceEnabled:=System.StructuredQueryType.Boolean#True AND System.DeviceInterface.Hid.VendorId:={vendorId} AND System.DeviceInterface.Hid.ProductId:={productId} ").AsTask()).ToList();
}
https://github.com/MelbourneDeveloper/Hid.Net/blob/c69e3368343e59e51e8818c87dbea00e6ccfecae/Hid.Net.UWP/UWPHelpers.cs#L11
You will be able to get a list of connected devices from that. You should then be able to connect with FromIdAsync.
I am using windows media foundation for keeping track of all the mics and cameras in an application. I am getting event type MEError instead of MECaptureAudioSessionDeviceRemoved when I unplug a Mic. I have tried unplugging Mics connected via USB and audio jack and I always get an eventtype with id MEError. The issue is not seen with video capture device(webcam) as I get the expected MEVideoCaptureDeviceRemovedevent type.
The mic's are getting initialized correctly as I can hear the audio correctly.
I have found zero information on this particular(unplugging mic with media foundation) issue on the internets. On top of this, I am a newbie C# dev. I am curious to understand why I am not getting the MECaptureAudioSessionDeviceRemoved but getting the MEError? Is this something the Mic driver developer did not implement or is it something expected if an error exists in my code?
Here's my code for getting the EventType(Not exactly necessary for my question) The class this function belongs to implements IMFAsyncCallback-
HRESULT MicCaptureSession::Invoke(IMFAsyncResult* pAsyncResult)
{
ComPointerCustom<IMFMediaEvent> pEvent;
HRESULT hr = S_OK;
std::lock_guard<std::mutex> lock(m_critSec);
if (pAsyncResult == 0)
{
return E_UNEXPECTED;
}
hr = m_localSession->EndGetEvent(pAsyncResult, &pEvent);
MediaEventType eventType;
HRESULT hr = S_OK;
HRESULT hrStatus = S_OK;
UINT32 TopoStatus = MF_TOPOSTATUS_INVALID;
if (pEvent== NULL)
return E_UNEXPECTED;
hr = pEvent->GetType(&eventType); <------ Y U NO WORK ??
if (FAILED(hr))
{
return E_UNEXPECTED;
}
hr = pEvent->GetStatus(&hrStatus);
if (FAILED(hr))
{
return E_UNEXPECTED;
}
/* ----- MORE CODE -----*/
}
I cannot say exactly reason of it, but I can advice you check more error invokes. Audio capture is different from video capture - video capture usually has about 33 ms between frames, but audio capture has about 5 - 10 ms, and it can generate MEError before then Windows Audio driver generate MECaptureAudioSessionDeviceRemoved.
Also, usually MF sources generate chain of errors. Try to check more error invokes from audio capture source.
I need to Integrate Cognex Dataman Wireless Handheld scanner in to existing Application developed using LabWindows CVI. Cognex has provided SDK in C#. Below SDK link
http://www.cognex.com/support/downloads/File.aspx?d=2628
I used CVI Tool .Net Controller to create C# Wrapper.
http://zone.ni.com/reference/en-XX/help/370051T-01/cvi/libref/cvidotnet_sample_code/
Below is code that suppose to connect to cognex scanner.
Cognex_DataMan_SDK_EthSystemConnector__Create (&DM_Connector, IPAddress,0);
Cognex_DataMan_SDK_EthSystemConnector_Set_UserName (DM_Connector,"Admin", 0);
Cognex_DataMan_SDK_EthSystemConnector_Set_Password (DM_Connector, "", 0);
Cognex_DataMan_SDK_DataManSystem__Create (&DM_system, DM_Connector, 0);
Cognex_DataMan_SDK_DataManSystem_Connect (DM_system, 0);
My problem is below line
Cognex_DataMan_SDK_EthSystemConnector__Create (&DM_Connector, IPAddress, 0);
I can create execute but it's not connecting, Constructor is not taking ipaddress.
Below help on generate from C# Wrapper Prototype
/*
Creates a new instance of the ethernet connector with the specified system IP address.
-------------------- Prototype
int Cognex_DataMan_SDK_EthSystemConnector__Create
(Cognex_DataMan_SDK_EthSystemConnector *Instance_Handle,
System_Net_IPAddress address,
CDotNetHandle *Exception_Handle);
Please advise , I have no success so far with this
Thank You
VBoxManage.exe is an Oracle VirtualBox companion utility, which allows to control VMs via command line. It can do numerous operations, including start/stop and screen capturing.
I am interested, which API it uses?
How can I capture VM screen or send keyboard or mouse commands there without this heavy commandline utility? Which language is better? Is is possible to access this API with Java?
One of the advantages to using an open source project is supposed to be that you can answer such questions by looking at the source.
VBoxManage is located in the source repository under /src/VBox/Frontends/VBoxManage. The code you're looking for is in VBoxManageControlVM.cpp under the condition if (!strcmp(a->argv[1], "screenshotpng")):
ComPtr<IDisplay> pDisplay;
CHECK_ERROR_BREAK(console, COMGETTER(Display)(pDisplay.asOutParam()));
ULONG width, height, bpp;
CHECK_ERROR_BREAK(pDisplay,
GetScreenResolution(displayIdx, &width, &height, &bpp));
com::SafeArray<BYTE> saScreenshot;
CHECK_ERROR_BREAK(pDisplay, TakeScreenShotPNGToArray(displayIdx,
width, height, ComSafeArrayAsOutParam(saScreenshot)));
RTFILE pngFile = NIL_RTFILE;
vrc = RTFileOpen(&pngFile, a->argv[2], RTFILE_O_OPEN_CREATE | RTFILE_O_WRITE |
RTFILE_O_TRUNCATE | RTFILE_O_DENY_ALL);
if (RT_FAILURE(vrc))
{
RTMsgError("Failed to create file '%s'. rc=%Rrc", a->argv[2], vrc);
rc = E_FAIL;
break;
}
vrc = RTFileWrite(pngFile, saScreenshot.raw(), saScreenshot.size(), NULL);
if (RT_FAILURE(vrc))
{
RTMsgError("Failed to write screenshot to file '%s'. rc=%Rrc",
a->argv[2], vrc);
rc = E_FAIL;
}
RTFileClose(pngFile);
So it's done via a COM API, and you can look at:
Is it possible to call a COM API from Java?
Googling for TakeScreenShotPNGToArray finds the display interface:
https://www.virtualbox.org/sdkref/interface_i_display.html
From there you can find the list of all the other things like mouse and keyboard:
https://www.virtualbox.org/sdkref/annotated.html