简体   繁体   English

打开串行端口时USB相机崩溃

[英]USB Camera crashes when opening Serial Port

I'm writing a program in WPF that needs to connect to a serial port to get and send data to a piece of machinery, and connect to a camera mounted on the machinery to show the video stream. 我正在用WPF编写一个程序,该程序需要连接到串行端口以获取数据并将其发送到一台机器,并连接到安装在机器上的摄像机以显示视频流。

So last week we bought a mini PC (a beelink bt3 pro) to give to our customers when they bought this machinery, so they could install our program on this dedicated pc. 因此,上周我们购买了一台微型PC(beelink bt3 pro),以便在客户购买此机器时将其赠送给客户,以便他们可以在此专用PC上安装我们的程序。 We immediately noticed that on the program startup, the camera would crash with that notorious sound that windows makes when you disconnect an usb device. 我们立即注意到,在程序启动时,当您断开USB设备的连接时,摄像机会崩溃,并发出Windows发出的臭名昭著的声音。 So after searching for clues on the problem I found out that when I called serialport.Open(), the camera would crash. 因此,在寻找有关该问题的线索后,我发现当我调用serialport.Open()时,相机将崩溃。 For the serial port I use the standard Microsoft library, while for the camera I first used Directshow, then EMGUCV (I switched last week because i tought that the problem was caused by the camera library). 对于串行端口,我使用标准的Microsoft库,而对于摄像机,我首先使用Directshow,然后使用EMGUCV(我上周进行了切换,因为我坚信问题是由摄像机库引起的)。

This is the code I use in the test program: 这是我在测试程序中使用的代码:

VideoCapture c = new VideoCapture(0);
c.ImageGrabbed += c_ImageGrabbed;
c.Start();
SerialPort port = new SerialPort("COM5", 9600, Parity.None, 8, StopBits.None); 
port.Open();

Just after calling Open(), the camera crashes and stops recording, making the windows error sound like it was removed from the PC. 在调用Open()之后,相机崩溃并停止记录,使Windows错误声像它已从PC中删除。 No Exceptions are thrown out, and the program keeps running. 没有异常抛出,该程序继续运行。

It is important to notice that this problem happens only on this PC, and I have the doubt that Windows 10 was not installed correctly, as I found a Windows.old folder in C:, and the system prompts me sometimes to delete the old windows folder. 重要的是要注意,此问题仅在此PC上发生,并且我怀疑Windows 10安装不正确,因为我在C:中找到了Windows.old文件夹,并且系统有时提示我删除旧的Windows夹。

If the camera is powered over USB, it is probably a power problem, ie the USB port on the computer does not deliver enough current for a stable operation of the camera. 如果相机是通过USB供电的,则可能是电源出现问题,即计算机上的USB端口无法为相机的稳定运行提供足够的电流。

You may try 你可以试试

  • to connect the camara to a USB port with higher current specification 将camara连接到具有更高电流规格的USB端口
  • to connect the camera over an externally powered USB Hub. 通过外部供电的USB集线器连接相机。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM