本文介绍了仅在我第一次与SerialPort通信时出现错误时,它才能正常工作.的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好朋友

•我有一个 USB设备(例如条形码扫描仪等)
•我使用SerialPort 与它进行通信(可以从VS2008的工具箱中很好地找到它)

我的问题是

PC 启动后,第一次启动我的应用程序时….
我的应用程序挂断卡住或进入无响应模式
当它尝试将字符串发送到串行端口时……..
出来吧……..
我只是从我的 PC ...的USB端口中拔出USB电缆....

拔下电缆后,我会收到错误消息……

我按下继续按钮…并插入后部拔下USB电缆…..
现在我的应用程序可以正常工作了…………

注意:我仅在启动PC后第一次启动我的应用时遇到此错误.
在那之后,我启动或关闭了我的应用程序几次,我没有收到任何错误...

注意:要考虑的另一件事是……如果我将代码放入try catch
仅当我从PC上拔下USB电缆时,我才捕捉到异常.

在我看来,当将字符串发送到串行端口时,控件将进入无限循环内
此处


注意:
重新启动计算机后... 如果可以,
1.从PC的USB端口拔出并插入USB电缆,然后
2.我启动我的应用程序,然后它可以正常工作

谢谢.....

Hello friends

•I have one USB device (e.g. barcode scanner etc.)
•I communicating with it using SerialPort (which is found nicely from toolbox of VS2008)

My problem is,

After starting my PC when I starting my Application first time….
My application hanging up or stuck up or going in to Not Responding Mode
when it tries to sending string to serial port……..
To come out of it ……..
I just remove the USB cable from USB port of my PC….

As soon as I remove cable I getting error message……

I pressing Continue button…and plug-in back Removed USB cable…..
Now my application working fine………

NOTE: I am getting this error only start my app First time after starting my PC.
After that how many times I start or close my app I does not getting any error...

NOTE: another thing to consider is that …… if I put my code in try and catch
I catch exception only when I remove the USB cable from my PC.

It seems to me that control is going inside infinite loop when sending string to serial port
See the detail of my code over here


NOTE:
After restart my PC......if I do
1.pulg-out and plug-in USB cable from USB Port Of PC, and then
2. I start my App then its working fine

Thanks…..

推荐答案

mySerialPortObj.SendFunc("{3QFG}");

string receivedString = mySerialPortObj.ReadFunc();


之间添加一些延迟(例如Sleep(100);)
也许在发送响应(第一次)时会有延迟,这是导致您的应用程序挂起的原因.



Perhaps there is a delay in sending the response (the first time) and is that what is causing your application to hang.


这篇关于仅在我第一次与SerialPort通信时出现错误时,它才能正常工作.的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

11-02 09:48