Windows Phone Thoughts - Daily News, Views, Rants and Raves

Check out the hottest Windows Mobile devices at our Expansys store!


Digital Home Thoughts

Loading feed...

Laptop Thoughts

Loading feed...

Android Thoughts

Loading feed...




Go Back   Thoughts Media Forums > WINDOWS PHONE THOUGHTS > Windows Phone Developer

 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
  #1  
Old 07-27-2009, 09:45 AM
chindji
Neophyte
Join Date: Jul 2009
Posts: 1
Default 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) { }>>
}>>
> >
}>>
}>>
> >

> >
> >
> >
> >
> >
 
Reply With Quote
 


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 11:35 PM.