usagimys 0 Newbie Poster

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:

private SerialPort 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.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..;)