The Hellfire Road to Solve a Problem: IoException raise when Serials Port Open in WinCE-(1)
2010-01-03 22:58
465 查看
首先要说的是:困扰一个星期的问题终于解决了~~~!!而之所以用英文来写题目,是因为这个问题外国朋友们也或语焉不详,或
解答令人误入歧途。中文是:
WinCE中串口Open的时候报IoException错误的一种原因以及解决方法。
首先考虑出错的原因是不是串口不存在。由于VDX6354有4个串口,因此改变程序从com1到com4的。发现com3和com4的报错是与com1、com2是不一样的。研究错误原因是com3,com4的错误是串口不存在,而com1和com2不是。检查了一下os bsp中的设置,发现4th serial port没有勾选,这一选项是用来选择com3,4是否使用的。从这一现象可以分析出com1、2是存在的,现在的问题转变为com1,2为什么不能正常打开。
(2)串口已打开?
上面是打开串口的代码,从代码中可以看出,在打开串口的之前已经检查过串口是否已被打开,从道理上来讲应该不存在串口已打开的问题。于是询问ICOP段工,段工指出CE中是用”COM1:”来指定端口的。我试了一下发现还是同样错误,然后仔细思考后发现这个肯定不是原因,因为这个程序是在Ebox3300中跑过的,没有问题。而且C#是managed的,因此类的封装在CF中应该和.net framework中没有什么区别。
(3)原来不是串口程序的问题!
经过几次小的调整后发现无法解决,于是我考虑是不是SDK之类的问题。联系段工请他发一个串口程序过来,很快得到了回复。实验结果是,段工的程序也同样的IoException。既然我已经测试通过的程序和段工的程序均没有问题,那么程序本身问题基本就排除了,剩下的就只有另一方面OS出了问题。有了这个思路我将VDX6354使用原配的OS启动(这里特别提醒大家,如果有预装的OS一定要保存好),运行段工发过来的串口程序一切正常(运行我自己的程序则直接在启动的时候报错,这个应该是OS配置不同的原因)!至此已经能够基本肯定是OS Builder出了问题。
解答令人误入歧途。中文是:
WinCE中串口Open的时候报IoException错误的一种原因以及解决方法。
1、问题来源
为了接受GPS信息,所以我使用VDX6354串口来读取GPS模块的串口信息。GPS模块可以通过台式机读取数据,是正常工作的。而且该CE串口程序是在EBox3300上成功过的,因此原以为是一个手到擒来的事情,但没想到一个简单的问题折腾了1个星期。没想到程序在打开串口的时候就抛出异常IoException。2、解决过程
(这里事先说明,我的blog除了提供问题的解决方法,更希望能用自己的学习过程为新手提供解决问题的思路,高手可以略过这一大段)
(1)串口不存在?首先考虑出错的原因是不是串口不存在。由于VDX6354有4个串口,因此改变程序从com1到com4的。发现com3和com4的报错是与com1、com2是不一样的。研究错误原因是com3,com4的错误是串口不存在,而com1和com2不是。检查了一下os bsp中的设置,发现4th serial port没有勾选,这一选项是用来选择com3,4是否使用的。从这一现象可以分析出com1、2是存在的,现在的问题转变为com1,2为什么不能正常打开。
(2)串口已打开?
SerialPort private void Open_Click(object sender, EventArgs e) { //set the SerialPort sp.PortName = "COM2";//choose one correct; sp.BaudRate = 4800; sp.RtsEnable = true; sp.DtrEnable = true; sp.DataBits = 8; sp.Parity = Parity.None; sp.StopBits = StopBits.One; if (!sp.IsOpen) { sp.Open(); } sp.DiscardInBuffer(); sp.DiscardOutBuffer(); sp.ReadTimeout = 5000; sp.ReceivedBytesThreshold = 1; sp.DataReceived += new SerialDataReceivedEventHandler(this.sp_DataReceived); }
上面是打开串口的代码,从代码中可以看出,在打开串口的之前已经检查过串口是否已被打开,从道理上来讲应该不存在串口已打开的问题。于是询问ICOP段工,段工指出CE中是用”COM1:”来指定端口的。我试了一下发现还是同样错误,然后仔细思考后发现这个肯定不是原因,因为这个程序是在Ebox3300中跑过的,没有问题。而且C#是managed的,因此类的封装在CF中应该和.net framework中没有什么区别。
(3)原来不是串口程序的问题!
经过几次小的调整后发现无法解决,于是我考虑是不是SDK之类的问题。联系段工请他发一个串口程序过来,很快得到了回复。实验结果是,段工的程序也同样的IoException。既然我已经测试通过的程序和段工的程序均没有问题,那么程序本身问题基本就排除了,剩下的就只有另一方面OS出了问题。有了这个思路我将VDX6354使用原配的OS启动(这里特别提醒大家,如果有预装的OS一定要保存好),运行段工发过来的串口程序一切正常(运行我自己的程序则直接在启动的时候报错,这个应该是OS配置不同的原因)!至此已经能够基本肯定是OS Builder出了问题。
相关文章推荐
- The Hellfire Road to Solve a Problem: IoException raise when Serials Port Open in WinCE-(2)
- How to solve problem caused when the CRT library and MFC libraries are linked in the wrong order
- Weblogic Server in the Chinese show how to solve the problem hash
- How to solve "one or more projects in the solution were not loaded correctly" problem?
- How to solve the problem witch is the system send many emails when cron have something wrong
- How to solve: when using tab in gnomeTerminal , the entire screen flash,
- Error:Unable to display this Web Part. To troubleshoot the problem, open this Web page in a Windows .....
- some encountered problem and the solve methods when install Matlab in Linux
- some encountered problem and the solve methods when install Matlab in Linux
- Attempt to load Oracle client libraries threw BadImageFormatException. This problem will occur when running in 64 bit mode with the 32 bit Oracle client components installed.
- how to solve the problem which is the imail software can not send email in wan,but can send email in lan.
- How to solve: when using tab in gnomeTerminal , the entire screen flash,
- how to solve the problem when you have chmod the directory to 777 but the apache still can not write file
- Get "Server Down" when retrieve the channel list in sopcast, how to solve it?
- How to solve the problem "A project with an Output Type of Class Library cannot be started directly "
- How to search a table in a store proc and open the store proc
- use noscript html tag when user disable the javascript in browser, guide user how to enable the js in different browser and retu
- How to solve the Candy problem?
- Three ways to solve the "Longest Palindromic Substring" problem
- Resolution to the record count increasing of the file exported from DB when ‘0A’ is included in it