System.IO.ports.SerialPort IOException on WINCE6.0 RRS feed

  • Question

  • I  stocked with this issue 2 weeks long, I am totally depressed :-(

    I am trying to open GPS port (it is a Wayteq x960bt and the GPS is on COM1 with 4800 baud) with System.IO.ports.SerialPort, but on wince I get IOException on port open, seems like something is already using this port. But any GPS navigation software (c++ ones) can work with COM1 and the GPS here.

    (moreover my program is working fine on Window Mobile 5.x and 6.x)

    I have found such issues on google, but with not real solution, maybe the root cause was different too..

    Thank you your help in advance,

    regards> truebaba

    Thursday, January 17, 2013 2:24 PM


  • okey, after some more days, I could solve this issue by dropping .netcf serial class out from my project.

    I will never use this buggy thing again.

    I am marking it I have answered the issue, thx

    • Marked as answer by truebaba Tuesday, January 22, 2013 2:45 PM
    • Edited by truebaba Tuesday, January 22, 2013 2:46 PM
    Tuesday, January 22, 2013 2:45 PM

All replies

  • forgot to write it is  .NETCF 3.5  c#
    Thursday, January 17, 2013 2:34 PM
    • Edited by Prabu[MCTS] Thursday, January 17, 2013 5:25 PM
    Thursday, January 17, 2013 5:20 PM
  • Hi,  I see there "kernel32" dllimports, I dont think it is good for .NETCF at all..

    I have read issues on DEBUG port and others on using FTD2XX_NET.FTDI  to reset device, no luck at all

    Thursday, January 17, 2013 7:36 PM
  • this is 2013, new year, I am a programmer from the beginning of my 13th year of my life, I am 39 now.

    I don't think so it is a big thing to OPEN a serial port from c# on WINCE (this is my first time on WINVE anyway)

    I could open it anytime in my entire life from any languages on any platforms..

    why I cannot open it from C# on Wayteq x960BT HD ?

    I really don't understand what happening around me... seems my life has broken.

    Thursday, January 17, 2013 7:41 PM
  • So what happens when you try to open it? Basic debugging: observe, hypothesize, test, fix. If you're getting INVALID_HANDLE_VALUE, check GetLastError() and follow the error code where it leads you. Maybe some other application has the port open (best guess). If not, maybe you're wrong about which port it is; Windows CE assigns port names, COM1, COM2, etc. based on registry entries NOT I/O addresses as on a normal PC (guess #2). If not, publish your code to open the serial port. Maybe you've done something wrong that we can spot (guess #3).

    Paul T.

    Thursday, January 17, 2013 9:00 PM
  • Or I should say, check the Exception fired on open and the InnerException field of the exception looking for more-detailed information on the actual failure.

    Paul T.

    Thursday, January 17, 2013 9:02 PM
  • Yes,This code is for .NET only,but you can convert the same to .NETCF,by importing the APIs from coredll.dll.But in this problem description he has mentioned this workaround works for WinCE as well.
    Prabu [eMVP]
    Friday, January 18, 2013 5:22 AM
  • I did some research:

    The innerException is null in this case,
    StackTrace: at System.IO.Ports.SerialStream.WinIOError(Int32 errorCode, String str) at System.IO.Ports.SerialStream..ctor(String portName, Int32 baudRate, Parity parity, Int32 dataBits, StopBits stopBits, Int32 readTimeout, Int32 writeTimeout, Handshake handshake, Boolean dtrEnable, Boolean rtsEnable, Boolean discardNull, Byte parityReplace) at System.IO.Ports.SerialPort.Open() at SmartDeviceProject1.loggerForm..ctor() at SmartDeviceProject1.Program.Main()

    There is a small gps scan program called "GPSScan_Debug.exe" what shows GPS found on COM1, 4800 baud, NMEA

    with task manager I can see these program are running in background ()
    udevice.exe (4 times)

    it is described the same on HKEY_LOCAL_MACHINE/init


    I find record from "Serial0" to "Serial5"
    Serial0 and Serial1 friendly name is "Serial Cable on UART0/1 Atlas debugging Board"

    so it seems it is really a debugging port!

    in HKEY_LOCAL_MACHINE\Drivers\Active I can see the next:

    COM7 points to Drivers\BuiltIn\GPS
    COM1 points to Drivers\BuiltIn\YFCommux
    URT8 points Serial0 (Atlas.dll)

    So seems COM7 is the GPS port by the registry

    but using COM7 also drops IOException ...

    Friday, January 18, 2013 9:26 AM
  • there is a .NET TerminalCE program (  ) what also cannot open COM1

    BUT there is a c++  GPS tracker program what can ( )

    it seems for me there is problem only with .NET port handling..

    Friday, January 18, 2013 11:49 AM
  • Paul, this is my code

    SerialPort port2 = new SerialPort("COM1", 4800, Parity.None, 8, StopBits.One);

    Friday, January 18, 2013 12:59 PM
  • Prabul:

    "you can convert the same to .NETCF,by importing the APIs from coredll.dll"

    not so easy. I have started to convert it, found more problems.. For example I must use openNetCF now.

    but there are still problems in compiling..

    Reviewing the code, I really don't think this will solve my issue.

    Friday, January 18, 2013 9:46 PM
  • Prabul, the serialportFixer did not solve my problem, after callling it  SerialPortFixer.Execute("COM1"); I still got IOException on System.IO.Ports.SerialPort.Open()

    BUT there is a little succes  => with pinvoke I can open the port in c# too

    [DllImport("coredll.dll", CharSet = CharSet.Auto, SetLastError = true)]
    private static extern IntPtr CreateFile(string lpFileName, int dwDesiredAccess, int dwShareMode,
                                            IntPtr securityAttrs, int dwCreationDisposition,
                                            int dwFlagsAndAttributes, IntPtr hTemplateFile);

    IntPtr hFile =  CreateFile("COM1:",GENERIC_READ | GENERIC_WRITE,0, IntPtr.Zero,OPEN_EXISTING,0,IntPtr.Zero);

    So, the root problem is why System.IO.Ports.SerialPort cannot open the COM1 on WINCE only.

    (when I set project target to Windows Mobile, the serialport works pretty well)

    • Edited by truebaba Saturday, January 19, 2013 10:15 PM
    Saturday, January 19, 2013 9:12 PM
  • okey, after some more days, I could solve this issue by dropping .netcf serial class out from my project.

    I will never use this buggy thing again.

    I am marking it I have answered the issue, thx

    • Marked as answer by truebaba Tuesday, January 22, 2013 2:45 PM
    • Edited by truebaba Tuesday, January 22, 2013 2:46 PM
    Tuesday, January 22, 2013 2:45 PM
  • The Serial class is quite reliable, but if you've fixed the problem another way your direct control of the port can be an advantage. I presume you tried opening both "COM1" and "COM1:" via SerialPort, yes?

    The exception information is great; you just need to get the actual Win32 error code from the outer exception thrown. This should tell you in more detail the source of the problem.

    Paul T.

    Tuesday, January 22, 2013 4:15 PM
  • Paul,

    the problem is with the .NETCF serial class straightly.

    I should have rewritten my whole project  to use pinvoking.

    This is the second time with a serious problem with .netcf, first time I should have

    rewritten my webrequest/ webresponse .netcf classes to low level socket solution...

    Actually, I am very sad to not start with c++ right away (because I was a delphi man) and started c# and netcf

    "The exception information is great; you just need to get the actual Win32" -> man, this is CF, a reduced, abandoned stuff... buggly buggily..

    Tuesday, January 22, 2013 6:54 PM
  • It's easy to dismiss a problem as "that class library is responsible". I've got thousands of lines using SerialPort and none of it suffers from the problem you describe so I'm inclined to blame you rather than SerialPort. It may be a quirk of the documentation causing your understanding to mismatch the actual call meaning or something like that. It may be how you're creating or using the Serial Port object. It may be how your platform works, what port numbers are assigned to what physical ports, etc. 

    I used to work with a guy who always attributed any intermittent behavior to "a memory problem". You really shouldn't take the easy way out. You may be missing a flaw that will cause your customers problems later. I'm glad you've got it working.

    Paul T.

    Monday, January 28, 2013 7:58 PM
  • Hi Paul,

    "I've got thousands of lines using SerialPort"  Do you have these thousands lines running on Windows CE 6.0 ? (on Windows mobile the serialPort is fine for me too)

    • Proposed as answer by azope Wednesday, April 30, 2014 8:10 PM
    Friday, March 15, 2013 9:13 AM
  • Hi truebaba,

    I am also facing the same problem working with .NETCF in winCE 6. The specifications of the problem and the COM ports of my device are exactly the same as yours. I am a newbie to Wince. . Would u care to xplain a bit more on the solution you found to open the serial port in c#?

     Thanx. .

    Thursday, March 28, 2013 6:34 AM
  • Hi Truebaba!

    Did you find solution wayteq gps handling? I have a same problem. I try to program wayteq gps port with c# over com ports. 

    do you have solution, or other way for gps handling on wayteq.

    thanks for your reply.

    azope77 at g

    Wednesday, April 30, 2014 8:13 PM