Pocket PC Thoughts - Daily News, Views, Rants and Raves

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





Go Back   Thoughts Media Forums > POCKET PC THOUGHTS > Pocket PC Developer

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 07-27-2009, 09:45 AM
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
  #2 (permalink)  
Old 07-27-2009, 03:57 PM
Executive Editor
Jason Dunn's Avatar
Join Date: Aug 2006
Posts: 24,845

I've moved your post to the developer forum, where it belongs, but you can see how what a disaster it is to copy/paste from Word...
__________________
Want to contact me personally? Use this. Want to read my personal blog? Check it out. Want to follow me on Twitter? Here you go.
 
Reply With Quote
Reply


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 On
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT +1. The time now is 08:01 PM.



Search Engine Friendly URLs by vBSEO 3.2.0 RC7