- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我每 30 毫秒向 QR 码阅读器发送一个命令,然后接收响应,并将其大小显示在标签上。一切似乎都正常,直到我按下停止按钮,之后我开始连续听到 Windows USB 连接/断开连接的声音。如果我拔下 USB 设备并重新插入,声音就会消失。可能出了什么问题?
public ReaderForm()
{
InitializeComponent();
}
private void ReaderForm_Load(object sender, EventArgs e)
{
_timer = new System.Windows.Forms.Timer();
_timer.Interval = 270;
_timer.Tick += new EventHandler(_timer_Tick);
}
private void ConnectButton_Click(object sender, EventArgs e)
{
_errorCode = ErrorCode.None;
_myUsbFinder = new UsbDeviceFinder(0x0c2e, 0x0b6a);
// Find and open the usb device.
_myUsbDevice = UsbDevice.OpenUsbDevice(_myUsbFinder);
// If the device is open and ready
if (_myUsbDevice == null) throw new Exception("Device Not Found.");
IUsbDevice wholeUsbDevice = _myUsbDevice as IUsbDevice;
if (!ReferenceEquals(wholeUsbDevice, null))
{
// Select config #1
wholeUsbDevice.SetConfiguration(1);
// Claim interface #0.
wholeUsbDevice.ClaimInterface(2);
}
_writer = _myUsbDevice.OpenEndpointWriter(WriteEndpointID.Ep07);
_reader = _myUsbDevice.OpenEndpointReader(ReadEndpointID.Ep02);
}
private void StartButton_Click(object sender, EventArgs e)
{
_timer.Interval = Convert.ToInt32(speedTextBox.Text);
_timer.Start();
}
private void StopButton_Click(object sender, EventArgs e)
{
if (_myUsbDevice != null)
{
if (_myUsbDevice.IsOpen)
{
IUsbDevice wholeUsbDevice = _myUsbDevice as IUsbDevice;
if (!ReferenceEquals(wholeUsbDevice, null))
{
// Release interface #2.
wholeUsbDevice.ReleaseInterface(2);
}
_myUsbDevice.Close();
}
}
_myUsbDevice = null;
// Free usb resources
UsbDevice.Exit();
_timer.Stop();
}
private void _timer_Tick(object sender, EventArgs e)
{
try
{
if (!String.IsNullOrEmpty(cmdLine))
{
int bytesWritten;
_errorCode = _writer.Write(Encoding.Default.GetBytes(cmdLine), 0, cmdLine.Length, 40, out bytesWritten);
Console.WriteLine("Bytes Written: {0} ", bytesWritten, _errorCode);
if (_errorCode != ErrorCode.None) throw new Exception(UsbDevice.LastErrorString);
_reader.DataReceived += (_onRxEndPointData);
_reader.DataReceivedEnabled = true;
label1.Text = _findImageSize().ToString();
Response = "";
// Always disable and unhook event when done.
_reader.DataReceivedEnabled = false;
_reader.DataReceived -= (_onRxEndPointData);
Console.WriteLine("\r\nDone!\r\n");
}
else
throw new Exception("Nothing to do.");
}
catch (Exception ex)
{
Console.WriteLine();
Console.WriteLine((_errorCode != ErrorCode.None ? _errorCode + ":" : String.Empty) + ex.StackTrace);
}
finally
{
}
}
private static void _onRxEndPointData(object sender, EndpointDataEventArgs e)
{
Response += Encoding.Default.GetString(e.Buffer, 0, e.Count);
}
public static int _findImageSize()
{
int imageSizeInBytes = 0;
byte[] responseBytes = Encoding.Default.GetBytes(Response);
for (int i = 0; i < responseBytes.Length; i++)
{
if (responseBytes[i] == 0x1d)//Find the start of the image data
{
i++;
imageSizeInBytes = responseBytes.Length - i;
break;
}
}
return imageSizeInBytes;
}
[更新]我现在已经尝试了几种不同的实现,使用异步、winusb 库,并且在过去 3 天里我尝试了刷新端点并中止它们以及无数其他方法。简而言之,我已经尝试了所有可能的方法,但问题仍在继续。我决定解决问题的唯一方法是模拟我从 USB 端口移除设备并再次插入的行为。我是否有可能以某种方式识别 USB 设备连接到的确切端口,并在 C# 中将其关闭并再次打开?
最佳答案
我注意到响应以 5-6 个数据包的形式发送。每当我写了一个命令但没有使用读取命令读取所有数据包时(我在收到完整响应之前停止读取),我的 PC 就开始发出那种声音。为了修复它,我使用了一个 bool 值来指示是否收到了整个响应,并且每当我不得不停止程序时,我都会延迟停止,如下所示:
while(!responseComplete){
};
_timer.Stop();
关于c# - 在我停止我的 libusbdotnet 应用程序后,USB 设备保持连接和断开连接,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54710725/
是否可以在蓝牙设备连接到 iOS 或从 iOS 断开连接时收到通知,即使我的应用程序处于后台?在 Android 上,我使用 ACTION_ACL_CONNECTED 和 ACTION_ACL_DIS
我对使用 Delphi 使用 USB 设备感到不舒服,并且对编写设备驱动程序的细节几乎一无所知(尽管我在学习使用 GoASM 进行汇编时遇到过一些)。 该设备可以是 USB 调制解调器或 USB 打印
我正在使用 java/servlet 和前端 JSP 开发 Web 应用程序。 我的页面为用户显示一些信息。 是否有任何适当的方法来检查网络连接是否处于 Activity 状态(开/关)以及支持所有浏
这个问题在这里已经有了答案: C# -- TcpListener.Start() causing SocketException with message "Only one usage of ea
我想向我的应用程序添加功能,以允许在 Windows 操作系统上检测播放/捕获设备的到达和断开连接。就像在 Skype 中一样 - 当您拔下设备时 - 它会显示设备丢失的通知,例如要求您选择另一个。
如何断开 org. apache. http. client.HttpClient 对象? 我正在这样创建它,但它没有任何 disconnect() 或 getHttpConnectionManage
我们正在开发一个 .NET 应用程序,其中一个要求是监视系统是否连接到 Internet。 我们能够获得“以太网电缆断开连接”的 .NET 事件,但如果调制解调器被重置,则不会触发此事件。我不想一直通
我正在尝试与使用自签名证书的后端服务器建立 websocket 连接。在 Firefox 中,我为自签名证书添加了一个异常(exception)。 但是我的 websocket 连接 wss://连接
我正在使用由 Excel 生成的用户窗体来修改 PowerPoint 演示文稿(这是避免需要启用宏的电子表格的迂回方法)。该表单工作得很好,但每次我将焦点放在它上时,Excel 应用程序都会获得焦点(
您好,我成功地开始了视频通话,但是当我断开视频通话时,摄像头 LED 指示灯仍然亮着。我怎样才能完全断开通话? Video.createLocalVideoTrack().then(track =>
您好,我成功地开始了视频通话,但是当我断开视频通话时,摄像头 LED 指示灯仍然亮着。我怎样才能完全断开通话? Video.createLocalVideoTrack().then(track =>
我正在尝试断开客户端与服务器的连接,但服务器仍将其视为已连接。我找不到解决这个问题的方法,关机、断开连接和关闭都不起作用。 我与客户端断开连接并检查服务器的一些代码: 客户: private vo
我正在使用 magic record 来完成我所有的核心数据工作。 一切都很好,除了有时我在后台进行更新时我需要从上下文中分离或断开实体。 例如 ButtonList = [Buttons MR_fi
我正在尝试实现一个颜色选择器,它从屏幕上各处的像素中获取颜色。为此,我计划使用全局鼠标 Hook 来监听 WM_MOUSEMOVE,以便在鼠标四处移动时更新颜色,并监听鼠标点击以确认 (WM_LBUT
我有一个使用 C# 编写的 TLS 连接的客户端/服务器 TCP 场景。 客户端在安静并恢复后无法传递消息(不活动时间约为 25 分钟)。但如果我让客户聊天(每 30 秒),就没有问题。 客户端和服务
我编写的这段代码完美运行,但我担心每 2 秒执行一次 ping 操作会消耗太多资源,或者可能导致互联网连接出现一些问题。 new Thread(() => {
关闭带有附加 MediaPlayer 的 MediaController 的正确方法是什么? 您不能执行 mediaController.setMediaPlayer(null) - 立即调用 upd
从我的笔记本电脑上断开外接显示器后,我丢失了一些应用程序,因为断开连接的显示器仍设置为默认显示器。我的一些窗口试图在断开连接的显示器上显示。 我有一个解决方法,例如右键单击应用程序图标并选择移动,然后
是否可以将分片节点从分片集中取出并独立运行? 例如,每个分片都有一个特定的客户。 谢谢。 最佳答案 是的,这是可能的。 MongoDB“主”节点不知道分片。只有路由器(和配置服务器)知道。如果您使用正
我正在探索 Cassandra 及其复制系统。为此,我在本地创建了 3 个节点并测试了不同的场景。我想暂停节点之间的通信,用相同的键写入不同的值,然后观察它们将决定什么。 那么问题来了:如何限制节点在
我是一名优秀的程序员,十分优秀!