问题描述
我仍然对TComPort组件有问题,但这一次并不是组件本身就是逻辑。我有一个设备巫婆通过串口发送一些ascii字符串我需要prase这些字符串的问题是电脑反应非常快,所以在事件中,它只捕获字符串的一部分,其余的字符串后来回来...所以解析它,当它被收回使它不可能。
I am still having issues with the TComPort component but this time is not the component itself is the logic behind it. I have a device witch sends some ascii strings via serial port i need to prase those strings the problem is the computer reacts very fast so in the event char it captures only a part of the string the rest of the string comes back later... so parsing it when it is recived makes it impossible.
我正在考虑写一个计时器巫婆验证是否没有连续活动10秒或更多,然后prase字符串我正在保存到一个缓冲区。但是这种方法是不专业的,没有一个空闲的事件,我可以听...等待我的问题的最佳解决方案。谢谢。
I was thinking in writing a timer witch verify if there was no serial activity 10 secons or more and then prase the string that i am saving into a buffer. But this method is unprofessional isn't there a idle event witch i can listen...Waiting for the best solution for my problem. Thanks.
推荐答案
使用多个串行端口组件后,我获得了最好的结果,直到现在,通过使用将该句柄传递给THandleStream实例的CreateFile('\\?\COM1',GENERIC_READ或GENERIC_WRITE,0,nil,OPEN_EXISTING,FILE_ATTRIBUTE_NORMAL,0)启动一个专用线程从中读取。我知道线程需要比编写事件处理程序更多的工作,但它仍然是处理使用串行端口产生的任何同步问题的最佳方式。
After using a number of serial-port-components, I've got the best results until now, by using CreateFile('\\?\COM1',GENERIC_READ or GENERIC_WRITE,0,nil,OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL,0), passing that handle to a THandleStream instance, and starting a dedicated thread to read from it. I know threads take a little more work than writing an event handler, but it still is the best way to handle any synchronization issues that arise from using serial ports.
这篇关于Delphi中的串口同步的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!