コード例 #1
0
        public bool DisconnectComPort()
        {
            StopScanning();
            _commandReturnCode = DllInteropBridge.CloseSpecComPort(_comNumber);

            if (_commandReturnCode != 0)
            {
                ConnectionState = ConnectionState.Error;
                return(false);
            }

            return(true);
        }
コード例 #2
0
        public bool ConnectComPort(int comNumber)
        {
            OnRfidArrived?.Invoke("Коннекчусь пытаюсь");
            OnRfidArrived2?.Invoke(this, "Коннекчусь по второму методу");

            _comNumber  = comNumber;
            _comAddress = 255;
            int frmPortIndex = 0;

            DisconnectComPort();
            _commandReturnCode = DllInteropBridge.OpenComPort(_comNumber, ref _comAddress, 0, ref frmPortIndex);

            if (_commandReturnCode != 0)
            {
                return(false);
            }

            ConnectionState = ConnectionState.Successful;
            return(true);
        }
コード例 #3
0
        /// <summary>
        /// Поверхностный рефакторинг китайского кода.
        /// В основном оставил без изменений.
        /// </summary>
        /// <returns></returns>
        private void RunScanning()
        {
            byte scanTime = 10;
            byte qValue   = 0;
            byte session  = 0;
            byte tidFlag  = 0; // !_rbEpc.Checked в примере от китайцев
            byte target   = 0;

            byte[] epc     = new byte[50000];
            byte   maskMem = 0;

            byte[] maskAdr = new byte[2];
            byte   maskLen = 0;

            byte[] maskData = new byte[100];
            byte   maskFlag = 0;
            byte   adrTID   = 0;
            byte   lenTID   = 6;

            byte inAnt    = 0x80;
            byte fastFlag = 1;

            byte ant      = 0;
            int  totalLen = 0;
            int  cardNum  = 0;

            _commandReturnCode = DllInteropBridge.Inventory_G2(
                ref _comAddress,
                qValue,
                session,
                maskMem,
                maskAdr,
                maskLen,
                maskData,
                maskFlag,
                adrTID,
                lenTID,
                tidFlag,
                target,
                inAnt,
                scanTime,
                fastFlag,
                epc,
                ref ant,
                ref totalLen,
                ref cardNum,
                _comNumber
                );

            if ((_commandReturnCode == 1) | (_commandReturnCode == 2) | (_commandReturnCode == 3) | (_commandReturnCode == 4))
            {
                byte[] daw = new byte[totalLen];
                Array.Copy(epc, daw, totalLen);
                var temps = daw.ToHexString();
                var m     = 0;

                for (int cardIndex = 0; cardIndex < cardNum; cardIndex++)
                {
                    var epcLen = daw[m] + 1;
                    var temp   = temps.Substring(m * 2 + 2, epcLen * 2);
                    var sEPC   = temp.Substring(0, temp.Length - 2);
                    var RSSI   = Convert.ToInt32(temp.Substring(temp.Length - 2, 2), 16);

                    m += epcLen + 1;

                    if (sEPC.Length != (epcLen - 1) * 2)
                    {
                        // todo сделать ошибку отдельным событием.
                        throw new Exception("Не знаю пока что такое");
                    }

                    OnRfidArrived?.Invoke(sEPC);
                    OnRfidArrived2?.Invoke(this, sEPC);
                }
            }
        }