接收到的数据+ =和-= [英] datareceived += and -=
问题描述
这不容易描述:
我正在使用"port.datareceived += dataReceived
"开始处理来自串行端口的传入数据流.
当我想停止它时,我使用"-=
",它可以正常工作.问题是似乎要花费一些时间,并且至少要再有一个数据样本正在处理,这会由于处理而导致错误.
我在"port.datareceived -= dataReceived
"后面放置了"thread.sleep(500)
"
但这没有帮助.
这似乎也是Windows处理的问题,因为在某些情况下它可以正常工作,而在某些情况下却不能.
我希望这对任何人都有意义.
预先感谢,
Mike
Hi,
This is not easy to describe:
I''m using "port.datareceived += dataReceived
" to start processing an incoming data stream from a serial port.
When I want to stop that, I use the "-=
" and it works. Problem is that it seems to take some time and that theres is at least one more data sample going through which causes an error due to the processing.
I put a "thread.sleep(500)
" behind "port.datareceived -= dataReceived
"
But it didn''t help.
This also seems to be a windows processing problem, because in some cases it works fine and in some it doesn''t.
I hope this makes sense to anyone.
Thanks in advance,
Mike
推荐答案
我会尝试关闭串行端口,删除处理程序,然后再次打开端口.
I would try closing the serial port, removing the handler, and the opening the port again.
我会如果您要避免阻止UI延迟,建议您使用后台线程进行所有通信,包括打开和关闭串行端口.
I would recommand you to use a background thread for all communications including opening and closing serial port if you want to avoid blocking delays in your UI.
这篇关于接收到的数据+ =和-=的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!