Click here to Skip to main content
15,887,746 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
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

EDIT:
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…..
Posted
Updated 26-May-11 21:24pm
v10

1 solution

I don't know if this is really going to help but you can clear the buffers after connecting:

SerialPort.DiscardOutBuffer()
SerialPort.DiscardInBuffer()

and add some delay (like Sleep(100);) between
mySerialPortObj.SendFunc("{3QFG}");
and
string receivedString = mySerialPortObj.ReadFunc();


Perhaps there is a delay in sending the response (the first time) and is that what is causing your application to hang.
 
Share this answer
 
Comments
Pritesh Aryan 27-May-11 3:16am    
after trying your code.........
it seems to me that this problem is from USB device to which i communicate...........
after restart my PC......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 for replying.....

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900