예제 #1
0
        private void btnConnectRs232_Click(object sender, EventArgs e)
        {
            // Procesando lector de conexión de puerto serie
            string strException = string.Empty;
            string strComPort   = cmbComPort.Text;
            int    nBaudrate    = Convert.ToInt32(cmbBaudrate.Text);

            int nRet = reader.OpenCom(strComPort, nBaudrate, out strException);

            if (nRet != 0)
            {
                string strLog = "No se pudo conectar con el lector, el motivo del error: " + strException;


                return;
            }
            else
            {
                string strLog = "Lector de conexión " + strComPort + "@" + nBaudrate.ToString();
                MessageBox.Show("lector conectado");
            }

            //处理界面元素是否有效
            SetFormEnable(true);


            btnConnectRs232.Enabled    = false;
            btnDisconnectRs232.Enabled = true;

            //设置按钮字体颜色
            btnConnectRs232.ForeColor    = Color.Black;
            btnDisconnectRs232.ForeColor = Color.Indigo;
        }
        private void auto_connect()
        {
            try                                                  // Await the task in a try block
            {
                string strException = string.Empty;              //
                string strComPort   = portname;
                int    nBaudrate    = Convert.ToInt32(baudrate); ////Convert.ToInt32(BaudBox.Text);

                int nRet = reader.OpenCom(strComPort, nBaudrate, out strException);

                ////string strLog = "Connection readers" + strComPort + "@" + nBaudrate.ToString();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
예제 #3
0
        //init inventory params
        private bool initReader()
        {
            //初始化访问读写器实例
            reader = new Reader.ReaderMethod();

            //回调函数
            reader.AnalyCallback = AnalyData;
            reader.ReceiveCallback = ReceiveData;
            reader.SendCallback = SendData;

            //connect to reader
            string strException = string.Empty;
            string strComPort = conf.ReaderPort;
            //int nBaudrate = Convert.ToInt32(cmbBaudrate.Text);
            int nBaudrate = 115200;

            int nRet = reader.OpenCom(strComPort, nBaudrate, out strException);
            if (nRet != 0)
            {
                string strLog = "连接读写器失败,失败原因: " + strException;
                WriteLog(logRichText, strLog, 1);
                writeLog(strLog);
                m_readerIsNormal = true;
                //buttonInv.Enabled = false;
                return false;
            }
            else
            {
                string strLog = "连接读写器设备 " + strComPort + "@" + nBaudrate.ToString();
                WriteLog(logRichText, strLog, 0);
                writeLog(strLog);
            }

            //output power init
            //Thread.Sleep(2000);

            return true;
        }