command prompt do not opens up when calling (.exe) console application
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();
}
}
}
}

Arjun DhilodPosted Dec 20, 2012, 1:20 PM
system.Treading.Thread.sleep(200);
Arjun DhilodPosted Dec 20, 2012, 12:33 AM
VulpesPosted Dec 19, 2012, 10:58 AM
1. Starts a console application.
2. Hides it's console window.
3. Starts another process called myfile.exe
4. Waits 50 seconds.
5. Starts the default browser and navigates to myweb.com.
6. Terminates.
I don't really see what any of this has to do with your original question so perhaps you could clarify.
Arjun DhilodPosted Dec 19, 2012, 2:03 AM
using System.Windows.Forms;
using System.Runtime.InteropServices;
using System.Drawing;
using System.IO;
using System.Diagnostics;
namespace nms
{
public class cls
{
[DllImport("user32.dll")]
private static extern int ShowWindow(int Handle, int showState);
[DllImport("kernel32.dll")]
public static extern int GetConsoleWindow();
static void Main(string[] args)
{
int win = GetConsoleWindow();
ShowWindow(win,0);
Process.Start("myfile.exe");
System.Threading.Thread.Sleep(50000);
Process.Start("http://myweb.com");
}
}
}
Arjun DhilodPosted Dec 19, 2012, 12:15 AM
VulpesPosted Dec 18, 2012, 9:29 AM
Perhaps this is what you were doing in the first place?
To get the console to show up, the output type needs to be set to the (default) of console application.
Whilst testing a serial port application, I'd certainly use a longer read time out than 100 ms. 500 ms should be a reasonable default value for most purposes.
Arjun DhilodPosted Dec 18, 2012, 7:03 AM
i will
Right-click on your project, select properties, Application tab, change the output type from Console to Windows app. This should make the app run without console window.
can it is work
or
Increase the time out
from
mySerialPort.ReadTimeout = 100;
to mySerialPort.ReadTimeout = 500;
VulpesPosted Dec 18, 2012, 6:23 AM
What I usually do is to place this line at the end of the Main() method:
Console.ReadKey();
The console should then remain open until you press a key.
Another possibility with this particular program is that nothing is being read from the serial port within the timeout of 100 ms and so there is no console output to read.
Arjun DhilodPosted Dec 18, 2012, 6:11 AM
VulpesPosted Dec 18, 2012, 6:05 AM
Console.ReadLine();
until you press the Enter key.
Are you saying that this is not in fact happening?