Problem with Smart Device/Pocket PC connect with Serial Port

Please support our C# advertiser: $4.95 a Month - ASP.NET Web Hosting – Click Here!
Reply

Join Date: Dec 2006
Posts: 3
Reputation: usagimys is an unknown quantity at this point 
Solved Threads: 0
usagimys usagimys is offline Offline
Newbie Poster

Problem with Smart Device/Pocket PC connect with Serial Port

 
0
  #1
Dec 22nd, 2006
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..
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the C# Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC