MyException - 我的异常网
当前位置:我的异常网» C# » 新手:关于委托与事件的有关问题

新手:关于委托与事件的有关问题(5)

www.MyException.Cn  网友分享于:2013-02-20  浏览:11次

            {
                Application.DoEvents();
            }
            return;
        }

        private void Config_Resize(object sender, EventArgs e)
        {
           this.FormBorderStyle =System.Windows.Forms.FormBorderStyle.None;
        }
    }

Comm.cs文件代码:

using System.Text;
using System;
using System.Threading;
using System.IO;
using System.IO.Ports;
using System.Windows.Forms;

public class Comm
{
    private SerialPort port;
    private byte[] readcache;
    private int idx;
    public string SendOK;
    public string s2;
    public string s3;

    public delegate void DataEventHandler(string RevCmd, string RevData);
    public event DataEventHandler HaveDataReady;

    public Comm(string spName, int spBaudRate, Parity spParity, int spDataBits, StopBits spStopBits, Handshake spHandShake)
    {
        port = new SerialPort(spName, spBaudRate, spParity, spDataBits, spStopBits);
        port.Handshake = spHandShake;
        port.ReadTimeout = 500;
        port.WriteTimeout = 500;
        port.ReadBufferSize = 1024;
        port.ReceivedBytesThreshold = 1;

        port.DataReceived += new SerialDataReceivedEventHandler(portDataReceived);
        readcache = new byte[256];
        idx = 0;
    }

    public bool IsOpen()
    {
        return port.IsOpen;
    }
    public void Open()
    {
        port.Open();
    }
    public void Close()
    {
        port.Close();
    }

    public void portDataReceived(object sender, SerialDataReceivedEventArgs e)
    {
        try
        {
            byte inputData = 0;
            while ((port.BytesToRead > 0))
            {

文章评论

软件开发程序错误异常ExceptionCopyright © 2009-2015 MyException 版权所有