Example #1
0
        /// <summary>
        /// 打开端口,读取设备信息
        /// </summary>
        /// <returns></returns>
        public Boolean OpenPort()
        {
            int     ret;
            Boolean Openport = false;

            ret = sio_open(ExGlobal.Port);
            if (ret != ExGlobal.SIO_OK)
            {
                MxTool.MxShowError("sio_open", ret);
                return(Openport);
            }
            if (PortSet() == false)
            {
                sio_close(ExGlobal.Port);
                return(Openport);
            }
            getCommData.GetCommData(ExGlobal.iPort, ExGlobal.ibaudrate, ExGlobal.iparity, ExGlobal.ibytesize, ExGlobal.istopbits);
            ExGlobal.GhExit         = false;
            ExGlobal.GbOpen         = true;
            StatusConnect.Text      = "Online";
            StatusConnect.BackColor = Color.LimeGreen;
            SwitchMenu();
            this.Text = ExGlobal.ShowStatus();
            Openport  = true;
            Request_Ver();
            thReadMeas = new Thread(new ThreadStart(ReadThreadExecute))
            {
                IsBackground = true
            };
            thReadMeas.Start();
            delRead = new Mydel(ShowData);
            return(Openport);
        }
Example #2
0
 /// <summary>
 /// 关闭端口
 /// </summary>
 public void ClosePort()
 {
     ExGlobal.GhExit = true;
     sio_close(ExGlobal.Port);
     ExGlobal.GbOpen         = false;
     StatusConnect.Text      = "Offline";
     StatusConnect.BackColor = Color.Empty;
     SwitchMenu();
     this.Text = ExGlobal.ShowStatus();
 }
Example #3
0
        private void FrmMain_Load(object sender, EventArgs e)
        {
            ExGlobal.GszAppName = "MM370-Tools";
            ExGlobal.GbOpen     = false;
            ExGlobal.GbRead     = false;

            //获取并显示系统时间
            timer1.Interval = 1000;
            timer1.Start();

            //Port开关使能
            SwitchMenu();

            //Form状态显示
            this.Text = ExGlobal.ShowStatus();
        }
Example #4
0
        /// <summary>
        /// 端口设置
        /// </summary>
        /// <returns></returns>
        public Boolean PortSet()
        {
            int     port, mode, hw, sw, ret, tout;
            Boolean PortSet = false;

            port = ExGlobal.Port;
            mode = ExGlobal.ByteSize | ExGlobal.StopBits | ExGlobal.Parity;

            if (ExGlobal.Hw)
            {
                hw = 3;
            }
            else
            {
                hw = 0;
            }
            if (ExGlobal.Sw)
            {
                sw = 12;
            }
            else
            {
                sw = 0;
            }
            ret = sio_ioctl(port, ExGlobal.BaudRate, mode);
            if (ret != ExGlobal.SIO_OK)
            {
                MxTool.MxShowError("sio_ioctl", ret);
                return(PortSet);
            }
            ret = sio_flowctrl(port, hw | sw);
            if (ret != ExGlobal.SIO_OK)
            {
                MxTool.MxShowError("sio_flowctrl", ret);
                return(PortSet);
            }
            tout = 512 * 1000 / sio_getbaud(ExGlobal.Port) * 3;    //ms /byte
            ret  = sio_SetWriteTimeouts(ExGlobal.Port, tout);
            if (ret != ExGlobal.SIO_OK)
            {
                MxTool.MxShowError("sio_SetWriteTimeouts", ret);
                return(PortSet);
            }
            this.Text = ExGlobal.ShowStatus();
            PortSet   = true;
            return(PortSet);
        }
Example #5
0
 private void CmSetting_Click(object sender, EventArgs e)
 {
     cfgForm.DialogResult = cfgForm.ShowDialog();
     if (cfgForm.DialogResult == DialogResult.Cancel)
     {
         return;
     }
     if (ExGlobal.GbOpen)
     {
         if (PortSet() == false)
         {
             ExGlobal.iPort     = getCommData.cPort;
             ExGlobal.ibaudrate = getCommData.cBaudRate;
             ExGlobal.iparity   = getCommData.cParity;
             ExGlobal.ibytesize = getCommData.cByteSize;
             ExGlobal.istopbits = getCommData.cStopBits;
             return;
         }
     }
     this.Text = ExGlobal.ShowStatus();
 }