944,131 Members | Top Members by Rank

Ad:
  • C# Discussion Thread
  • Unsolved
  • Views: 5950
  • C# RSS
Dec 22nd, 2006
0

Problem with Smart Device/Pocket PC connect with Serial Port

Expand Post »
Hi all,

Currently i'm doing a pocket pc in Visual Studio 2005 in C#, the program is actlly to communicate with a reader using Serial Port.And i run the program using the emulator. For the code,i'm using class Serial Port to establish the connection. After doing all the settings, it seem that the connection is already establish. It's because there is no exception fired after i open the port inside the Load method.
I realize that my problem is when i try to write byte to the serial port, after press button event fired. my emulator suddenly stuck freezing there.below is my code:

privateSerialPort sp;
private void Form1_Load(object sender, EventArgs e)
{
#region Serial Port Init
sp= new SerialPort();
sp = new SerialPort();
sp.PortName = "COM1";
sp.BaudRate = 115200;
sp.DataBits = 8;
sp.Parity = Parity.None;
sp.StopBits = StopBits.One;
try
{
sp.Open();
MessageBox.Show("Port Open!!");
}
catch (Exception ex)
{
MessageBox.Show(ex.ToString());
}
#endregion
}

private void startBtn_Click(object sender, EventArgs e)
{
timer1.Enabled = true;


}
private void timer1_Tick(object sender, EventArgs e)
{
if (sp.IsOpen == true)
{

sp.Write(new byte[] { 0xC0, 0x02, 0x01, 0xFF }, 0, 4); //(1)
string STRBFR = sp.ReadExisting();
toHexClass c1 = new toHexClass();
string inHex = c1.display(STRBFR);
string[] strReg = Regex.Split(inHex, "01 18");
for (int i = 1; i < strReg.Length; i++)
{
compAdd.Text = strReg[i].Substring(0, 15);
}

}
else
{
MessageBox.Show("PORT CLOSED!");
}
}


(1)-line that the problem start to happen.
For your information, i already tried the same code in window form, it's successfully running.
Please do advice me on this.. i really need help here....thanks..
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
usagimys is offline Offline
3 posts
since Dec 2006

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in C# Forum Timeline: plz help me
Next Thread in C# Forum Timeline: For Disappear





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC