我开发了一个涉及与 USB 设备通信的 ASP.NET Core 应用程序。为此,它使用CoreCompat.LibUsbDotNet库的2.2.8-r101 版本,这是针对 .NET Standard 1.5 的 LibUsbDotNet 的一个端口。
当我在 Windows 上托管服务器(使用 IIS Express)时,一切正常 - 我能够毫无问题地与 USB 设备通信。但是,我也尝试在两个 Linux 设备上托管服务器:
- 运行 Ubuntu 16.04 的 VMware 虚拟机
- 基于官方 ASP.NET Core docker 镜像构建的 docker 容器(
microsoft/aspnetcore:1.0.1
)
在这两种情况下,我的服务器都成功启动,但是当我尝试启动与 USB 设备的通信时(通过单击网页中的“开始”按钮),我看到浏览器控制台中显示以下错误:
[09:57:03 GMT+0100 (GMT Standard Time)] SignalR: communicationshub.StartComms failed to execute. Error: libusb-1.0 library not found. This is often an indication that libusb-1.0 was installed to '/usr/local/lib' and mono.net is not looking for it there. To resolve this, add the path '/usr/local/lib' to '/etc/ld.so.conf' and run 'ldconfig' as root. (http://www.mono-project.com/DllNotFoundException)
在这两种情况下,我都使用以下命令集配置 Linux 设备:
$ apt-get update && apt-get install -y libusb-1.0-0-dev usbutils
在 docker 容器的情况下,我以特权模式运行它,并且使用它和 VMware 机器,我可以看到我的 USB 设备是使用lsusb
.
我还能够在 Windows 和 Linux 上使用先前构建的面向 .NET Framework 的应用程序和使用 LibUsbDotNet 2.2.8 版与此设备进行通信(在 Linux 的情况下,这是通过在 Windows 上编译、复制二进制文件来完成的到 Linux VM 并使用mono
) 运行。
这是安装 libusb 后我正在运行的 docker 容器的输出:
root@fdf333675857:/app# apt-cache search libusb
libusbhid-common - Common files for the USB HID devices FreeBSD library
libhidapi-libusb0 - Multi-Platform library for communication with HID devices (libusb backend)
libhidapi-libusb0-dbg - Debugging symbols for libhidapi-libusb0
libdevice-usb-perl - Perl module to access USB devices using libusb
libgusb-dev - GLib wrapper around libusb1 - development files
libgusb-doc - GLib wrapper around libusb1 - documentation
libgusb2 - GLib wrapper around libusb1
libusb++-0.1-4c2 - userspace C++ USB programming library
libusb++-dev - userspace C++ USB programming library development files
libusb-0.1-4 - userspace USB programming library
libusb-dev - userspace USB programming library development files
libusb-1.0-0 - userspace USB programming library
libusb-1.0-0-dbg - userspace USB programming library development files
libusb-1.0-0-dev - userspace USB programming library development files
libusb-1.0-doc - documentation for userspace USB programming
libusb-java - Java wrapper for libusb
libusb-java-dbg - debug information for libusb java wrapper
libusb-java-doc - javadoc documentation for libusb-java
libusb-java-lib - C part of Java wrapper for libusb
libusbmuxd-dev - USB multiplexor daemon for iPhone and iPod Touch devices - devel
libusbmuxd-tools - USB multiplexor daemon for iPhone and iPod Touch devices - tools
libusbmuxd2 - USB multiplexor daemon for iPhone and iPod Touch devices - library
libusbmuxd2-dbg - USB multiplexor daemon for iPhone and iPod Touch devices - debug
libusbtc08-1 - Hardware interface library for PicoTech USB TC08 Thermocouple sensor
libusbtc08-dev - Development files for PicoTech USB TC08
libusbip-dev - USB device sharing system over IP network (development files)
libusb-ocaml - OCaml bindings to libusb-1.0 (runtime)
libusb-ocaml-dev - OCaml bindings to libusb-1.0
libusbprog-dev - Development files for libusbprog
libusbprog0 - Library for programming the USBprog hardware
libusbredirhost-dev - implementing the usb-host (*) side of a usbredir connection (development)
libusbredirhost1 - Implementing the usb-host (*) side of a usbredir connection (runtime)
libusbredirparser-dev - Parser for the usbredir protocol (development)
libusbredirparser1 - Parser for the usbredir protocol (runtime)
python-usbtc08 - Python wrapper for libusbtc08
whereis
:
root@fdf333675857:/app# whereis libusb-1.0
libusb-1: /usr/include/libusb-1.0
/lib
:
root@fdf333675857:/app# ls -la /lib
total 36
drwxr-xr-x 11 root root 4096 Sep 30 09:00 .
drwxr-xr-x 48 root root 4096 Sep 30 09:01 ..
drwxr-xr-x 2 root root 4096 Sep 23 17:25 init
drwxr-xr-x 3 root root 4096 Sep 23 17:25 lsb
drwxr-xr-x 2 root root 4096 Sep 23 17:25 startpar
drwxr-xr-x 8 root root 4096 Sep 23 17:25 systemd
drwxr-xr-x 15 root root 4096 Sep 17 2014 terminfo
drwxr-xr-x 4 root root 4096 Sep 23 17:26 udev
drwxr-xr-x 3 root root 4096 Sep 30 09:00 x86_64-linux-gnu
/usr/lib
:
root@fdf333675857:/app# ls -la /usr/lib
total 92
drwxr-xr-x 24 root root 4096 Sep 30 09:00 .
drwxr-xr-x 24 root root 4096 Sep 30 09:00 ..
drwxr-xr-x 4 root root 4096 Sep 23 17:26 apt
drwxr-xr-x 2 root root 4096 Sep 2 22:02 binfmt.d
drwxr-xr-x 2 root root 4096 Sep 23 17:25 coreutils
drwxr-xr-x 3 root root 4096 Sep 23 17:26 dpkg
drwxr-xr-x 3 root root 4096 Dec 19 2014 gcc
drwxr-xr-x 2 root root 4096 Sep 23 17:26 gnupg
drwxr-xr-x 3 root root 4096 Sep 5 06:10 locale
drwxr-xr-x 3 root root 4096 Jun 6 2013 mime
drwxr-xr-x 2 root root 4096 Sep 2 22:02 modules-load.d
-rw-r--r-- 1 root root 232 Sep 12 04:09 os-release
drwxr-xr-x 2 root root 4096 Aug 15 2014 perl5
drwxr-xr-x 3 root root 4096 Mar 19 2015 python2.7
drwxr-xr-x 3 root root 4096 Mar 19 2015 python3
drwxr-xr-x 2 root root 4096 Sep 25 2015 sasl2
drwxr-xr-x 3 root root 4096 Sep 29 22:14 ssl
drwxr-xr-x 2 root root 4096 Sep 2 22:02 sysctl.d
drwxr-xr-x 7 root root 4096 Sep 2 22:02 systemd
drwxr-xr-x 2 root root 4096 Nov 8 2014 tar
drwxr-xr-x 2 root root 4096 Sep 23 17:26 tc
drwxr-xr-x 2 root root 4096 Sep 23 17:25 tmpfiles.d
drwxr-xr-x 10 root root 4096 Sep 30 09:00 x86_64-linux-gnu
/usr/local/lib
:
root@fdf333675857:/app# ls -la /usr/local/lib
total 8
drwxrwsr-x 2 root staff 4096 Sep 23 17:25 .
drwxrwsr-x 11 root staff 4096 Sep 29 22:13 ..
更新 1
这是我的project.json
:
{
"version": "0.1.1-*",
"description": "Provides a testbed for validating the behaviour of <<Company>> .NET Communication Services",
"authors": [
"<<Author>>"
],
"buildOptions": {
"emitEntryPoint": true,
"preserveCompilationContext": true,
"debugType": "portable"
},
"dependencies": {
"<<Company>>.Communications.Core": "0.4.3",
"<<Company>>.Communications.<<Product>>Usb": "0.4.6",
"BundlerMinifier.Core": "2.2.281",
"Microsoft.ApplicationInsights.AspNetCore": "1.0.1",
"Microsoft.AspNetCore.Diagnostics": "1.0.0",
"Microsoft.AspNetCore.Mvc": "1.0.1",
"Microsoft.AspNetCore.Razor.Tools": {
"version": "1.0.0-preview2-final",
"type": "build"
},
"Microsoft.AspNetCore.Routing": "1.0.1",
"Microsoft.AspNetCore.Server.IISIntegration": "1.0.0",
"Microsoft.AspNetCore.Server.Kestrel": "1.0.1",
"Microsoft.AspNetCore.SignalR.Server": "0.1.0",
"Microsoft.AspNetCore.StaticFiles": "1.0.0",
"Microsoft.AspNetCore.WebSockets.Server": "0.1.0",
"Microsoft.Composition": "1.0.30",
"Microsoft.Extensions.Configuration.EnvironmentVariables": "1.0.0",
"Microsoft.Extensions.Configuration.Json": "1.0.0",
"Microsoft.Extensions.Logging": "1.0.0",
"Microsoft.Extensions.Logging.Console": "1.0.0",
"Microsoft.Extensions.Logging.Debug": "1.0.0",
"Microsoft.Extensions.Options.ConfigurationExtensions": "1.0.0",
"Microsoft.NETCore.App": {
"version": "1.0.1",
"type": "platform"
},
"Microsoft.VisualStudio.Web.BrowserLink.Loader": "14.0.0",
"System.Reactive": "3.1.0-rc"
},
"packOptions": {
"owners": [
"<<Company>>"
],
"repository": {
"type": "git",
"url": "https://bitbucket.org/<<Company>>-dev/communications-testbed"
}
},
"frameworks": {
"netcoreapp1.0": {
"imports": [
"dotnet5.6",
"portable-net45+win8"
]
}
},
"publishOptions": {
"include": [
"wwwroot",
"**/*.cshtml",
"appsettings.json",
"web.config",
"docker-compose.yml",
"Dockerfile",
".dockerignore"
]
},
"runtimeOptions": {
"configProperties": {
"System.GC.Server": true
}
},
"scripts": {
"prepublish": [
"bower install",
"dotnet bundle"
],
"postpublish": [
"dotnet publish-iis --publish-folder %publish:OutputPath% --framework %publish:FullTargetFramework%"
]
},
"tools": {
"BundlerMinifier.Core": "2.0.238",
"Microsoft.AspNetCore.Razor.Tools": "1.0.0-preview2-final",
"Microsoft.AspNetCore.Server.IISIntegration.Tools": "1.0.0-preview2-final"
}
}
此应用程序的想法是,它充当通信服务测试平台,将扫描其依赖项以查找 MEF 导出ICommunicationService
并允许对其进行测试。这意味着它不直接使用 LibUsbDotNet,而是引用了一个项目。这是project.json
为了:
{
"version": "0.4.6-*",
"description": "Provides a type of communication service that facilitates communication between .NET applications and <<Product>> over USB.",
"authors": ["<<Author>>],
"dependencies": {
"NETStandard.Library": "1.6.0",
"Microsoft.Composition": "1.0.30",
"Microsoft.NETCore.Portable.Compatibility": "1.0.1-rc2-24027",
"<<Company>>.Message": "0.4.2",
"<<Company>>.Communications.Core": "0.4.3",
"Thrower": "3.0.4",
"CoreCompat.LibUsbDotNet": "2.2.8-r101",
"Common.Logging.Portable": "3.3.1"
},
"packOptions": {
"owners": ["<<Company>>"],
"repository": {
"type": "git",
"url": "https://bitbucket.org/<<Company>>-dev/<<Product>>usb"
}
},
"frameworks": {
"netstandard1.6": {
"imports": [ "dnxcore50", "portable-net45+win8" ]
}
},
"buildOptions": {
"xmlDoc": true
}
}