Lost Password?

Go Back   CodeCall Programming Forum > Software Development > C# Programming

Vote on your favorite hash algorithm here!

C# Programming C# (pronounced C-sharp) is a new object oriented language from Microsoft and is derived from C and C++. It also borrows a lot of concepts from Java too including garbage collection.

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 07-14-2007, 01:40 AM
HosseinSadeghi HosseinSadeghi is offline
Newbie
 
Join Date: Jul 2007
Posts: 1
Credits: 0
Rep Power: 0
HosseinSadeghi is on a distinguished road
Default 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 01:54 AM. Reason: Added code-tags.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote

Sponsored Links
Reply



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools Search this Thread
Search this Thread:

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

Similar Threads
Thread Thread Starter Forum Replies Last Post
VB 6.0: Tutorial, Making a Port Scanner TcM VB Tutorials 82 09-23-2008 03:10 PM
COM port problem!! TcM Computer Software/OS 2 02-01-2007 12:36 PM


All times are GMT -5. The time now is 11:11 AM.

Contest Stats

Xav ........ 1335.07
MeTh0Dz|Reb0rn ........ 1059.99
morefood2001 ........ 898.18
John ........ 887.37
marwex89 ........ 875.28
WingedPanther ........ 864.22
Brandon W ........ 764.23
chili5 ........ 312.39
Steve.L ........ 254.16
dcs ........ 231.11

Contest Rules

CodeCall Goal

Goal: 100,000 Posts
Complete: 83%

Ads