/// <summary>
        ///
        /// </summary>
        /// <param name="cbb"></param>
        /// <param name="cComm"></param>
        /// <param name="msg"></param>
        private void Init(ComboBox cbb, CCommPort cComm, RichTextBox msg = null)
        {
            if (cComm != null)
            {
                this.cCommSerial.RemoveComboBoxMouseDownClick();
                this.cCommSerial.RemoveButtonClick();
                this.cCommSerial.RefreshCOMM(cbb);

                //---传递端口类型
                this.cCommSerial.mCCOMM            = cComm;
                this.cCommSerial.mCCommRichTextBox = msg;

                //---加载按钮事件
                this.cCommSerial.mButton.Click += new EventHandler(this.ParamShowDialog_Click);
                //---波特率
                this.cCommSerial.AnalyseBaudRate(cComm.mSerialPortParam.mBaudRate);
                //---数据位
                this.cCommSerial.AnalyseDataBits(cComm.mSerialPortParam.mDataBits);
                //---停止位
                this.cCommSerial.AnalyseStopBits(cComm.mSerialPortParam.mStopBits);
                //---校验位
                this.cCommSerial.AnalyseParity(cComm.mSerialPortParam.mParity);
            }
            else
            {
                this.DialogResult = DialogResult.None;
            }
        }
 /// <summary>
 ///
 /// </summary>
 /// <param name="cCommBase"></param>
 public CSerialPort(CCommPort cCommBase)
 {
     if (cCommBase != null)
     {
         //---参数的分析
         base.AnalyseParam(cCommBase.mCOMMPerPackageMaxSize, cCommBase.mSerialPortParam, cCommBase.mUSBPortParam, cCommBase.mCOMMChildAddr);
     }
 }
Beispiel #3
0
        /// <summary>
        /// 初始化
        /// </summary>
        /// <param name="ccomm"></param>
        public virtual void Init(CCommPort ccomm = null, RichTextBox msg = null)
        {
            if (ccomm != null)
            {
                if (this.defaultCCOMM == null)
                {
                    this.defaultCCOMM = new CCommPort();
                }
                this.defaultCCOMM = ccomm;

                this.defaultCCOMM.Init(this.comboBox_COMM, msg);
            }
        }
 /// <summary>
 ///
 /// </summary>
 /// <param name="cComm"></param>
 private void Init(int perPackageSize, CCommPort cComm)
 {
     if (cComm != null)
     {
         this.cCommSerial.RemoveComboBoxMouseDownClick();
         this.cCommSerial.RemoveButtonClick();
         this.cCommSerial.mPerPackageMaxSize = perPackageSize;
         //---加载按钮事件
         this.cCommSerial.mButton.Click += new EventHandler(this.ParamShowDialog_Click);
     }
     else
     {
         this.DialogResult = DialogResult.None;
     }
 }
        /// <summary>
        /// 构造函数
        /// </summary>
        /// <param name="text"></param>
        /// <param name="isLimitedSize"></param>
        public CSerialPortFullForm(int perPackageSize, CCommPort cComm, string text = null, bool isLimitedSize = false)
        {
            InitializeComponent();

            if ((!string.IsNullOrEmpty(text)))
            {
                this.cCommSerial.mButton.Text = text;
            }

            //---判断是否限定最小尺寸
            if (isLimitedSize)
            {
                //---限制窗体的大小
                this.MinimumSize = this.Size;
                this.MaximumSize = this.Size;
            }
            this.Init(perPackageSize, cComm);
        }
        /// <summary>
        ///
        /// </summary>
        /// <param name="cbb"></param>
        /// <param name="cComm"></param>
        /// <param name="msg"></param>
        /// <param name="text"></param>
        /// <param name="isLimitedSize"></param>
        public CSerialPortPlusForm(ComboBox cbb, CCommPort cComm, RichTextBox msg = null, string text = null, bool isLimitedSize = false)
        {
            InitializeComponent();

            if (!string.IsNullOrEmpty(text))
            {
                this.cCommSerial.mButton.Text = text;
            }

            //---判断是否限定最小尺寸
            if (isLimitedSize)
            {
                //---限制窗体的大小
                this.MinimumSize = this.Size;
                this.MaximumSize = this.Size;
            }
            this.Init(cbb, cComm, msg);
        }
Beispiel #7
0
        /// <summary>
        /// 启动初始化
        /// </summary>
        /// <param name="ccomm"></param>
        /// <param name="msg"></param>
        private void StartupInit(CCommPort ccomm = null, RichTextBox msg = null)
        {
            //---button 点击事件
            this.button_COMM.Click += new System.EventHandler(this.Button_Click);
            //---button 右击事件
            this.button_COMM.MouseDown += new System.Windows.Forms.MouseEventHandler(this.ButtonMouseDown_Click);

            //---端口状态刷新事件
            this.pictureBox_COMM.Click += new EventHandler(this.PictureBox_Click);

            //---增加鼠标移动事件
            this.comboBox_COMM.MouseDown += new System.Windows.Forms.MouseEventHandler(this.ComboBoxMouseDown_Click);

            if (ccomm != null)
            {
                if (this.defaultCCOMM == null)
                {
                    this.defaultCCOMM = new CCommPort();
                }
                this.defaultCCOMM = ccomm;
                this.defaultCCOMM.Init(this.comboBox_COMM, msg);
            }
        }
        /// <summary>
        ///
        /// </summary>
        /// <param name="cbb"></param>
        /// <param name="cComm"></param>
        /// <param name="msg"></param>
        private void Init(int perPackageSize, ComboBox cbb, CCommPort cComm, RichTextBox msg = null)
        {
            if (cComm != null)
            {
                this.cCommSerial.RemoveComboBoxMouseDownClick();
                this.cCommSerial.RemoveButtonClick();
                this.cCommSerial.RefreshCOMM(cbb);
                this.cCommSerial.mPerPackageMaxSize = perPackageSize;

                //---传递端口类型
                this.cCommSerial.mCCOMM            = cComm;
                this.cCommSerial.mCCommRichTextBox = msg;

                //---加载按钮事件
                this.cCommSerial.mButton.Click += new EventHandler(this.ParamShowDialog_Click);
                //---波特率
                this.cCommSerial.AnalyseBaudRate(cComm.mSerialPortParam.mBaudRate);
                //---数据位
                this.cCommSerial.AnalyseDataBits(cComm.mSerialPortParam.mDataBits);
                //---停止位
                this.cCommSerial.AnalyseStopBits(cComm.mSerialPortParam.mStopBits);
                //---校验位
                this.cCommSerial.AnalyseParity(cComm.mSerialPortParam.mParity);
                //---设备地址
                this.cCommSerial.AnalyseAddrID(cComm.mSerialPortParam.mAddrID.ToString());
                //---包大小
                this.cCommSerial.AnalysePerPackageMaxSize(perPackageSize);
                //---数据发送校验方式
                this.cCommSerial.AnalyseTxCRC((int)cComm.mSendData.mCRCMode);
                //---数据接收校验方式
                this.cCommSerial.AnalyseRxCRC((int)cComm.mReceData.mCRCMode);
            }
            else
            {
                this.DialogResult = DialogResult.None;
            }
        }
Beispiel #9
0
 /// <summary>
 /// 配置通讯方式
 /// </summary>
 private void ConfigCCOMMType(bool isLockFrame = false)
 {
     if (this.defaultCCOMM != null)
     {
         CCommPortTypeForm p = new CCommPortTypeForm(this.defaultCCOMM.mCOMMType, true);
         if (p != null)
         {
             //---计算位置偏移,避免超出可见区域
             int offset = 0;
             if (this.Location.X > this.button_COMM.Size.Width)
             {
                 offset = -24;
             }
             if (p.ShowDialog(this.button_COMM, offset, this.button_COMM.Height + 4) == System.Windows.Forms.DialogResult.OK)
             {
                 if (this.defaultCCOMM.mCOMMType != p.mCCommType)
                 {
                     //if (p.mCCommType == CCOMM_TYPE.COMM_SERIAL)
                     if ((p.mCCommType == CCOMM_TYPE.COMM_SERIAL) && (this.defaultCCOMM.GetType() == typeof(CUSBPort)))
                     {
                         this.defaultCCOMM = new CSerialPort(this.comboBox_COMM, this.defaultCCOMM.mCCommRichTextBox);
                     }
                     //else if (p.mCCommType == CCOMM_TYPE.COMM_USB)
                     else if ((p.mCCommType == CCOMM_TYPE.COMM_USB) && (this.defaultCCOMM.GetType() == typeof(CSerialPort)))
                     {
                         this.defaultCCOMM = new CUSBPort(this.comboBox_COMM, this.defaultCCOMM.mCCommRichTextBox);
                     }
                     else
                     {
                         MessageBox.Show("不支持的通讯端口,端口类型未发生更改!");
                         //this.defaultCCOMM = null;
                     }
                     //---切换端口的状态为初始值
                     if (this.button_COMM.InvokeRequired)
                     {
                         this.BeginInvoke((EventHandler)
                                          (delegate
                         {
                             this.button_COMM.Text = "打开设备";
                         }
                                          )
                                          );
                     }
                     else
                     {
                         this.button_COMM.Text = "打开设备";
                     }
                     //---注销资源
                     this.defaultCCOMM.Dispose();
                     this.pictureBox_COMM.Image = Properties.Resources.lost;
                     this.defaultShowCommParam  = true;
                 }
                 //---执行设备的同步事件
                 this.EventHandlerCCommSynchronized?.Invoke();
             }
             //---释放资源
             p.FreeResource();
             GC.SuppressFinalize(p);
         }
     }
 }
Beispiel #10
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="ccomm"></param>
 public CCommPortControl(CCommPort ccomm, RichTextBox msg = null)
 {
     InitializeComponent();
     this.StartupInit(ccomm, msg);
 }