Click here to Skip to main content
15,867,453 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hi to all know i was develop my program data read from comport and save out put in .txt file but i want command prompt do not opens up when calling (.exe) console application pls help me my code are
C#
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO.Ports;
using System.IO;
using System.Runtime.InteropServices;


namespace PortDataReceived
{
    class Program
    {
        static void Main(string[] args)
        {
            SerialPort mySerialPort = new SerialPort("COM1");
            if (mySerialPort.IsOpen == true) mySerialPort.Close();
            mySerialPort.BaudRate = 2400;
            mySerialPort.Parity = Parity.None;
            mySerialPort.StopBits = StopBits.One;
            mySerialPort.DataBits = 8;
            mySerialPort.Handshake = Handshake.None;
            mySerialPort.Open();
         // Console.WriteLine("Press any key to continue...");
           
            Console.ReadLine();
            
            mySerialPort.ReadTimeout = 100;


            string indata = mySerialPort.ReadExisting();
            Console.WriteLine(indata);
            
            if (string.IsNullOrEmpty(indata))
            {
                StringBuilder builder = new StringBuilder();
                StreamWriter sw = new StreamWriter(@"c:\arjun.txt", true);
                sw.WriteLine(indata);
                sw.Close();

            }
            else
            {
                StringBuilder builder = new StringBuilder();

                for (int i = 0; i < indata.Length-8; i += 8)
                {

                    string section = indata.Substring(i, 8);

                    //int ascii = 0;
                    string ascii = "";
                    try
                    {
                        //ascii = Convert.ToInt32(section, 2);
                        ascii = section;
                        StreamWriter sw = new StreamWriter(@"c:\arjun.txt", true);

                        foreach (char c in section)
                        {
                            if (Char.IsLetterOrDigit(c))
                            {
                                builder.Append(c);
                            }
                        }

                        sw.WriteLine(builder.ToString());
                        sw.Close();
                        break;
                    }
                    catch(Exception e)

                    {

                        throw e;
                        

                    }
                     // builder.Append((char)ascii);
                }

                
              //  Console.WriteLine(builder.ToString());
               // Console.WriteLine(indata);
                //Console.WriteLine("Data Received:");
                //Console.Write(indata);
               //  Console.ReadKey();
                mySerialPort.Close();

            }



        }
    }
}
Posted
Comments
Richard MacCutchan 18-Dec-12 7:05am    
You can only run a console application in a command prompt window. There may be some way to hide it but I doubt that it is worth the effort.

1 solution

 
Share this answer
 
Comments
Arjunwalmiki 18-Dec-12 7:08am    
can i follow the below step or can is this right trick.

http://cs.hubfs.net/topic/None/59579
Thomas Daniels 18-Dec-12 7:11am    
Yes, you can follow the step on the web page.
Arjunwalmiki 18-Dec-12 7:13am    
but it is my console application program can i have received same output those received in console program?
Thomas Daniels 18-Dec-12 7:16am    
If you follow the step on the web page, your program will run as it is a console application, but without the window.
Arjunwalmiki 18-Dec-12 7:25am    
sir i have already mention in above i am develop the program in console application not in web page so can it is work proper way when i was change property setting change the output type from Console to Windows app.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900