
07-27-2009, 09:45 AM
|
Neophyte
Join Date: Jul 2009
Posts: 1
|
|
Serial Com Terminal on Windows CE
Hello!>>
I�m writing an Application that I created in Visual C#. The application is
a Serial Com Terminal. I want this to run as a Windows CE Application in my device emulator. But it�s doesn�t really work. I don�t� have any error but I can�t send other received any message from the serial port.
Can anyone please help me out in this?
Thanks in advance
Chinco>>
> >
> >
using System.Data;>>
using System.Drawing;>>
using System.Text;>>
using System.Windows.Forms;>>
using System.Threading;>>
using System.IO;>>
using System.IO.Ports;>>
> >
namespace MyCETerminalChat>>
{>>
public partial class Form1 : Form>>
{>>
string name;>>
string message;>>
StringComparer stringComparer = StringComparer.OrdinalIgnoreCase;>>
>>
> >
> >
// Create a new SerialPort object with default settings.>>
SerialPort sp = new SerialPort();>>
public Form1()>>
{>>
InitializeComponent();>>
string[] ports = SerialPort.GetPortNames();>>
>>
foreach (string port in ports)>>
{>>
cboPort.Items.Add(port);>>
}>>
}>>
> >
private void cmdOpen_Click(object sender, EventArgs e)>>
{>>
try>>
{>>
sp = new SerialPort(cboPort.SelectedItem.ToString());>>
sp.BaudRate = int.Parse(cboBaud.SelectedItem.ToString());>>
// Set the read/write timeouts >>
sp.WriteTimeout = 500;>>
sp.ReadTimeout = 500;>>
sp.Parity = Parity.None;>>
sp.DataBits = 8;>>
sp.StopBits = StopBits.One;>>
sp.Handshake = Handshake.None;>>
sp.Open();>>
>>
>>
> >
> >
if (sp.IsOpen == true)>>
{>>
MessageBox.Show("Success");>>
cmdOpen.Enabled = false;>>
cmdClose.Enabled = true;>>
cmdSend.Enabled = true;>>
> >
> >
> >
> >
}>>
else>>
> >
MessageBox.Show("Port no Connect");>>
> >
}>>
catch (Exception ex)>>
{>>
MessageBox.Show(ex.Message);>>
}>>
}>>
> >
private void cmdSend_Click(object sender, EventArgs e)>>
{>>
> >
>>
string msg = txtSend.Text;>>
textBox1.Text += (msg);>>
sp.Write(msg);>>
>>
txtSend.Text = "";>>
>>
> >
> >
}>>
> >
private void cmdClose_Click(object sender, EventArgs e)>>
{>>
sp.Close();>>
cmdOpen.Enabled = true;>>
cmdClose.Enabled = false;>>
cmdSend.Enabled = false;>>
}>>
> >
> >
> >
delegate void ChangeTxtReciveTextDelegate(string newText);>>
> >
private void ChangeTxtReciveText(string newText)>>
{>>
if (textBox1.InvokeRequired) >>
textBox1.Invoke(new ChangeTxtReciveTextDelegate(ChangeTxtReciveText), newText);>>
else >>
textBox1.Text = newText;>>
}>>
> >
public void Read()>>
{>>
> >
> >
try>>
{>>
string message = sp.ReadExisting();>>
MessageBox.Show("Selected Item Text: " + message);>>
> >
ChangeTxtReciveText(message);>>
}>>
catch (TimeoutException) { }>>
}>>
> >
}>>
}>>
> >
> >
> >
> >
> >
> >
|
|
|
|
|
|
|
|