+ Reply to Thread
Results 1 to 1 of 1

Thread: Serial Port Close Problem in Pocket PC

  1. #1
    Newbie HosseinSadeghi is an unknown quantity at this point
    Join Date
    Jul 2007
    Posts
    1

    Serial Port Close Problem in Pocket PC

    Hello,

    This is a code about serial port connection in POCKET PC. This code uses serial port Data_Recive Event. When data enter the input buffer it is read and shown in logTextBox.

    Problem: When I want to close the port, the system freezes completely.
    I am using .net compact framework 2.0 Sp2 and visual studio.net 2005 and
    C# language.

    Thanks,
    Sadeghi

    Code:
    public partial class MainForm : Form
        {
            private Delegate UpdateHandler;      
    private void DoUpdate(Object s, EventArgs e)
            {
                logTextBox.Text += ReadLineBuffer;
            }
    private void serialPort_DataReceived(object sender, System.IO.Ports.SerialDataReceivedEventArgs e)
            {
                ReadLineBuffer = serialPort.ReadLine();
                this.Invoke(UpdateHandler);
            }
    
          private void MainForm_Load(object sender, EventArgs e)
            {
                serialPort.Handshake = Handshake.None;
                UpdateHandler = new EventHandler(DoUpdate);
            }
      private void connectMenuItem_Click(object sender, EventArgs e)
            {
                if (serialPort.IsOpen == false)
                {
                    try
                    {
                        serialPort.Open();
                        this.serialPort.DataReceived += new System.IO.Ports.SerialDataReceivedEventHandler(this.serialPort_DataReceived);
                    }
                    catch(IOException Exeption)
                    {
                        MessageBox.Show(Exeption.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Hand,MessageBoxDefaultButton.Button1);
                    }
    
    
    }
    
        private void disconnectMenuItem_Click(object sender, EventArgs e)
            {
                if (serialPort.IsOpen == true)
                {
                    try
                    {
                        serialPort.DiscardInBuffer();
                        serialPort.DiscardOutBuffer();
                        this.serialPort.DataReceived -= new System.IO.Ports.SerialDataReceivedEventHandler(this.serialPort_DataReceived);
                        serialPort.Close(); //Error
                    }
                    catch (IOException Exeption)
                    {
                        MessageBox.Show(Exeption.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Hand, MessageBoxDefaultButton.Button1);
                    }
                }
            }
    Last edited by v0id; 07-14-2007 at 02:54 AM. Reason: Added code-tags.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

     

Similar Threads

  1. VB 6.0: Tutorial, Making a Port Scanner
    By TcM in forum VB Tutorials
    Replies: 119
    Last Post: 08-24-2009, 03:59 PM
  2. COM port problem!!
    By TcM in forum Computer Software/OS
    Replies: 2
    Last Post: 02-01-2007, 01:36 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts