C#

Moderators: None (Apply to moderate this forum)
Number of threads: 2722
Number of posts: 5749

This Forum Only
Post New Thread
Single Post View       Linear View       Threaded View      f

Report
Windows Embeded CE 6.0 Posted by drkidd22 on 4 Feb 2013 at 9:17 AM
Hello,

I'm new to programming for Windows CE. I have made a simple application that open up a COM port and it's supposed to receive commands. The port is setup as a loopback for testing right now. It runs fine in Windows 7 Machine, but when I try to run the .exe on the Windows CE platform it spits out a few errors when it tries to open up the com port.

I wrote the application with C# in Visual Studio Pro 2005. If someone can give me a hint I'll appreciate it. I build as a Windows CE 5.0 Device on the IDE.

Below is my code in C#:

using System;
using System.IO.Ports;

namespace COMTest
{
    public class Program
    {
        static bool _continue;
        static SerialPort _sPort;

        public static void Main(string[] args)
        {
            string _portList;
            
            //Configure the COM Port
            _sPort = new SerialPort();
            _sPort.PortName = "COM2";
            _sPort.BaudRate = int.Parse("9600");
            _sPort.Parity = (Parity.None);
            _sPort.DataBits = int.Parse("8");
            _sPort.StopBits = (StopBits.One);

            _sPort.ReadTimeout = 500;
            _sPort.WriteTimeout = 500;

            _portList = SetPortName("COM2"); //Check for availaable COM Ports and lists them.
            
            _sPort.Open();
            _continue = true;

            //tesString = Console.ReadLine();
            _sPort.WriteLine("COM PORT TEST");
            _sPort.WriteLine("Type String to LoopBack");

            Read();
            _sPort.Close();
        }

        public static void Read()
        {
            while (_continue)
            {
                try
                {
                    string message = _sPort.ReadLine();
                    Console.WriteLine(message);
                }
                catch (TimeoutException) { }
            }
        }

        public static string SetPortName(string defaultPortName)
        {
            string portName;

            Console.WriteLine("Available Ports:");
            foreach (string s in SerialPort.GetPortNames())
            {
                Console.WriteLine("   {0}", s);
            }

            Console.Write("COM port({0}): ", defaultPortName);
            portName = Console.ReadLine();

            if (portName == "")
            {
                portName = defaultPortName;
            }
            return portName;
        }
    }
}





 

Recent Jobs

Official Programmer's Heaven Blogs
Web Hosting | Browser and Social Games | Gadgets

Popular resources on Programmersheaven.com
Assembly | Basic | C | C# | C++ | Delphi | Flash | Java | JavaScript | Pascal | Perl | PHP | Python | Ruby | Visual Basic
© Copyright 2011 Programmersheaven.com - All rights reserved.
Reproduction in whole or in part, in any form or medium without express written permission is prohibited.
Violators of this policy may be subject to legal action. Please read our Terms Of Use and Privacy Statement for more information.
Operated by CommunityHeaven, a BootstrapLabs company.