private void openConection(string portCOM) { string strException = string.Empty; string strComPort = portCOM; //cmbComPort.Text; //Coge el BaudRate en cmbBaudRate en modo numérico(critico) Int32 nBaudrate = 115200; //Convert.ToInt32(cmbBaudrate.Text); // Comprueba si existe y conecta al puerto COM int nRet = reader.OpenCom(strComPort, nBaudrate, out strException); if (button3.Text == "CONNECT") { if (nRet != 0) { string strLog = "Connect reader failed, due to: " + strException; this.Text = "Preparador de pedidos - Doctor PRO - " + strLog; } else { string strLog = "Reader connected " + strComPort + "@" + nBaudrate.ToString(); button3.Text = "DISCONNECT"; this.Text = "hola"; btnSave.Enabled = true; this.Text = "Preparador de pedidos - Doctor PRO - " + strLog; } } else { reader.CloseCom(); button3.Text = "CONNECT"; btnSave.Enabled = false; this.Text = "Preparador de pedidos - Doctor PRO - Desconectado"; } }
private static void Connect() { string strException = string.Empty; string strComPort = _Com_Port; int nBaudrate = Convert.ToInt32(_Boud_Rate); int nRet = reader.OpenCom(strComPort, nBaudrate, out strException); if (nRet != 0) { string strLog = "Connection failed, failure cause: " + strException; Logger(strLog); throw new Exception(strLog); } else { #region Set Function Default htxtSendData = "A0 04 FF A0 00"; CalculateCheckSumCommand(null, EventArgs.Empty); string SendCommandStr = htxtSendData + htxtCheckData; string[] reslut = CCommondMethod.StringToStringArray(SendCommandStr.ToUpper(), 2); byte[] btArySendData = CCommondMethod.StringArrayToByteArray(reslut, reslut.Length); reader.SendMessage(btArySendData); #endregion Set Function Default string strLog = "Connect" + strComPort + "@" + nBaudrate.ToString(); Logger(strLog); if (_Start_Read == "Start") { try { strLog = "Started to read tags"; Logger(strLog); m_curInventoryBuffer.ClearInventoryPar(); m_curInventoryBuffer.btRepeat = Convert.ToByte(repeatCommand); m_curInventoryBuffer.bLoopCustomizedSession = false; m_curInventoryBuffer.lAntenna.Add(0x00); m_curInventoryBuffer.lAntenna.Add(0x01); m_curInventoryBuffer.lAntenna.Add(0x02); m_curInventoryBuffer.lAntenna.Add(0x03); if (m_curInventoryBuffer.lAntenna.Count == 0) { Logger("One antenna must be selected"); } m_bInventory = true; m_curInventoryBuffer.bLoopInventory = true; m_curInventoryBuffer.bLoopInventoryReal = true; m_nTotal = 0; byte btWorkAntenna = m_curInventoryBuffer.lAntenna[m_curInventoryBuffer.nIndexAntenna]; reader.SetWorkAntenna(m_curSetting.btReadId, btWorkAntenna); m_curSetting.btWorkAntenna = btWorkAntenna; timerInventory.Enabled = true; timerInventory.Enabled = true; } catch (Exception ex) { Logger(ex.Message); } } } }