08-11-2010 12:50 PM
Hello,
I worte a program (please see in attachment) to acquire data by serial ports (RS232) from two instruments--one is a force sensor and another is a position sensor. When I connected those two instruments directly to my desktop by RS232, the data looked good. But when I connected those two instruments to USB ports on my laptop by RS232-USB adaptors, there was then a lot of noise for both data. Someone told me that it was due to the hardware interfering. Since I know little about hardware, could anyone please tell me if that really a hardware interfering or any problems with my code? Why it worked well on desktop and is there any way to fix it? Thanks a lot!
Solved! Go to Solution.
08-11-2010 01:10 PM - edited 08-11-2010 01:12 PM
Your code looks fine with one exception. You should convert the error terminals on the loop border to shift registers. That way, any error that happens will be propogated to the next loop. The way you have it, if an error occurs, it will be lost on the next loop iteration and you will never know about it.
You aren't the first person that has complained about USB to Serial converters messing up their program. The only suggestion I have is to go back to the serial port, or maybe buy another brand of USB-Serial converter.
Edit: Just noticed that you do not have any Wait funtion in your loop. This will cause 100% CPU usage, and this may be what is causing your problem because the OS doesn't have time to tend to the USB properly. This is just a guess. Put in a small delay (Wait function), say 10mS. See if that fixes your problem. Even if it doesn't, keep the delay in there.
08-11-2010 02:24 PM
Thanks a lot!
08-11-2010 03:12 PM
Did the Wait function fix the problem? Or did you go back to the serial port?
08-16-2010 03:30 PM
I tried on desktop and laptop several times by adding the wait function. For desktop, it was ok in the range from 10 ms to 200 ms. I did not try longer time, but I think it will be still OK. On the laptop, the noise might be reduced a little bit, but the data still looked ugly. Going back to serial ports may be the only way. Just one more question: will the mini PC board for serial ports work better than the USB on laptop? Thanks!
08-16-2010 03:35 PM
@dreamxin wrote:
one more question: will the mini PC board for serial ports work better than the USB on laptop? Thanks!
There is only one way to find out. Try it. USB requires more overhead from the OS. So I am guessing serial would be better.
08-16-2010 03:48 PM
I will try, thanks again!