Ejemplo n.º 1
0
 public bool Connect(int port, int number, int rate)
 {
     //if (password.HasValue)
     //{
     //	_czkem.SetCommPassword(password.Value);
     //}
     return(_czkem.Connect_Com(port, number, rate));
 }
Ejemplo n.º 2
0
        public void ConnectViaUsb(List <string> messages)
        {
            try
            {
                if (Convert.ToInt32(Settings.Default._deviceId) < 0 ||
                    Convert.ToInt32(Settings.Default._deviceId) > 256)
                {
                    messages.Add(WriteLog(Resources.LABEL_ILLEGAL_DEVICE));
                    return;
                }
            }
            catch (FormatException)
            {
                messages.Add(WriteLog(Resources.LABEL_ILLEGAL_DEVICE));
                return;
            }

            var idwErrorCode = 0;
            var iPort        = 0;
            var iBaudrate    = 115200;
            var iDeviceId    = Convert.ToInt32(Settings.Default._deviceId);
            var iCommkey     = Convert.ToInt32(Settings.Default._commKey);
            var sCom         = Settings.Default._usbDevice;

            for (iPort = 1; iPort < 10; iPort++)
            {
                if (sCom.IndexOf(iPort.ToString(), StringComparison.Ordinal) > -1)
                {
                    break;
                }
            }

            _czkem.SetCommPassword(iCommkey);
            if (Settings.Default._connected)
            {
                _czkem.Disconnect();
                // UnRegisterEvents();
                SetConnected(false);
                messages.Add(WriteLog(Resources.LABEL_DISCONNECT_WITH_DEVICE));
            }

            if (_czkem.Connect_Com(iPort, iDeviceId, iBaudrate))
            {
                //  RegisterEvents(messages);
                SetConnected(true);
                messages.Add(WriteLog(Resources.LABEL_DEVICE_CONNECTED));
            }
            else
            {
                _czkem.GetLastError(ref idwErrorCode);
                messages.Add(WriteLog(Resources.LABEL_UNABLE_TO_CONNECT_VIA_USB + idwErrorCode));
            }
        }