Background info:
I am using a DAQ from US Digital (The USB4 Encoder DAQ). The DAQ is connected to my computer via USB. It comes with a library to access and control the DAQ. The library is written in C++ but has a provided C# library wrapper and a bunch of demo programs.
The C# Wrapper is built using .NET Framework, there I created a .NET Core 3.1 project and built the wrapper again in there. on the test console application (that is on .NET Core 3.1), the wrapper class works great and I am able to write commands and retrieve data from the DAQ.
The Problem:
When I try to do the same thing as my console program inside my UWP application, I get nothing. I don't get any errors whatsoever, just none of the functions work. I am running a UWP app built for target version 1903. What could possibly be the issue between my console application and my UWP that is making this not work? Is there things I can do to resolve this issue.
Thanks in advance for any help. Let me know if there is anything I can help clarify about the problem.
using System;
using USB4Wrapper;
namespace TestDAQ
{
class Program
{
static void Main(string[] args)
{
// Declare USB4 variable.
USB4 mUSB4;
// Create new USB4 object and assign it to mUSB4 variable.
mUSB4 = new USB4();
// Connects to all USB4 devices found on USB bus.
// If a device is found, then Initialize will return true
// and mUSB4.DeviceNo will default to 0. To talk to a second
// device, set the mUSB4.DeviceNo = 1;
if (mUSB4.Initialize())
{
// Output the number of USB4 devices found.
Console.WriteLine("Found {0} USB4 device(s).", mUSB4.DeviceCount().ToString());
mUSB4.WriteOutputPortRegister(0b00000101);
uint[] arCount = new uint[4];
uint timeStamp = 0;
if (mUSB4.CaptureTimeAndCounts(arCount, out timeStamp))
{
Console.WriteLine("Encoder 0 = {0}\nEncoder 1 = {1}\nEncoder 2 = {2}\nEncoder 3 = {3}\nTimeStamp = {4}",
arCount[0].ToString(), arCount[1].ToString(), arCount[2].ToString(), arCount[3].ToString(), timeStamp.ToString());
}
// Close connection to USB4 devices.
mUSB4.Shutdown();
}
else
{
Console.WriteLine("Failed to initialize USB4. No device found.");
}
Console.WriteLine("Press any key to continue...");
Console.ReadKey(true);
}
}
}
UPDATE After testing, it also works on WPF apps running on .NET Core 3.1 as well, it seems to be just UWP it does not work on
UPDATE 2 Here is what is inside the wrapper class. After debugging it on UWP, the m_sLastResult
returns -32 and compares it to SUCCESS
which is 0, therefore returning false
[DllImport("USB4.dll")]
private static extern short USB4_Initialize(out short sDeviceCount);
/// <summary>
/// This function is used to open a connection with all installed and detected USB4 encoder
/// interface devices. This function returns the number of devices detected in the in/out parameter
/// piDeviceCount. This function must be called before any other function. Almost all other
/// function calls require a device number. If there are two boards detected, then the first
/// board will be device number 0 and the second device number 1.
/// During initialization, a device’s module address is read and compared to previously read module
/// addresses. If the module address already exists, then the newly read device’s module address
/// is assigned the next available module address.
/// If the USB4’s FPGA code is not running, then it is downloaded and executed and the previously
/// saved encoder control parameters are restored.
/// After USB4_Initialize is called, DLL functions can be used to change the configuration if needed.
/// </summary>
/// <returns>Returns true if successful, other false.</returns>
public bool Initialize()
{
lock (mThisLock)
{
short count = 0;
m_sLastResult = USB4_Initialize(out count);
m_sDeviceCount = count;
}
return (m_sLastResult == SUCCESS);
}
C# Library works on .NET Core 3.1 but not on UWP
Please check this document , The following table lists the minimum platform versions that support each .NET Standard version. That means that later versions of a listed platform also support the corresponding .NET Standard version. For example, .NET Core 2.2 supports .NET Standard 2.0 and earlier .
Currently UWP does not support .Net Core 3.0, it is TBD state, please pay attention to the following update.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.