SerialPort.ReadTimeout是否在C#上运行?! [英] Is SerialPort.ReadTimeout working on C#??!

查看:359
本文介绍了SerialPort.ReadTimeout是否在C#上运行?!的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好,

我正在C#上创建一个程序,并且正在使用函数"string SerialPort.ReadTo(string value)".从串行端口读取数据.
这应该一直读到您提供的字符或字符串.
如果找不到此字符串,它将在SerialPort的ms值之后返回Timeout Exception.


我的问题是我的代码只能在装有Visual Studio环境且安装了C#的PC上正常工作.
在我尝试过的所有其他PC中,我总是会立即拥有" System.TimeoutException'"; 完全不读取任何数据,也无需等待2500毫秒等待TimeoutException出现..

我的代码如下:


推荐答案

似乎读超时问题仅在我使用虚拟COM端口时才存在.我有串行以太网服务器!
当我将设备直接连接到物理端口或高质量USB到RS232时(我说的是高质量,因为在便宜的USB到RS232转换器上我总是接收***数据),这一切都是正常的可以正常工作!

无论如何,很奇怪,我仅在未安装Visual Studion的计算机上遇到此问题...
在计算机中,我正在开发程序,但在该处没有任何读取超时问题全部,并且我正在使用此虚拟端口进行开发...
一切都应该正常工作!
还在另外两台计算机上,我尝试了可执行文件,没有读取超时问题!这两台计算机还安装了带有C#环境的Visual Studio..

在两台Windows XP和一台未安装Visual Studio的Windows Vista计算机上,我遇到了此读取超时问题.它是否可以在装有Visual Studio的PC上正常工作?!?
我不这么认为...
我现在正在其中一台机器上安装Visual Studio 2008 Express,但我遇到了问题一些更多的测试.
It seems that the readtimeout problem exists only when I am using a Virtual COM Port from a Serial Ethernet Server I have!
When I connect the device direclty on a physical port or a high quality USB to RS232 (I am saying high quality because on cheap USB to RS232 Converters I am always receiving *** data) everything is working perfectly!!

Anyway, it is weird that I am encountering this problem only on computers without Visual Studion Installed...
In the computer I am developing the program I do not have any readtimeout problems at all and I am using this Virtual Port for my development...
Everything is working as it should be!
Also on two more computers I tried just the executable there was no readtimeout problem! These two computers had also Visual Studio with C# environment installed..

On two windows XP and one Windows Vista machine without Visual Studio Installed I am encountering this readtimeout problem..

Maybe it was coincidence that it was working on the pc`s with Visual Studio installed?!?
I don`t think so...
I am installing now visual studio 2008 express on one of the machines I had the problems to do some more testing.


这篇关于SerialPort.ReadTimeout是否在C#上运行?!的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆