예제 #1
0
        public bool WriteTagHEX(string hexString)
        {
            if (!FeHexConvert.isHexString(hexString))
            {
                Console.WriteLine($"{hexString} is not a HEX value");
                return(false);
            }

            var tagsInventory = _reader.TagInventory(true, 0x10, Settings.Instance.AntennaByte);

            int status = -1;

            if (tagsInventory.Count == 1)
            {
                FedmIscTagHandler_EPC_Class1_Gen2 tag = tagsInventory.Values.First() as FedmIscTagHandler_EPC_Class1_Gen2;

                if (tag != null)
                {
                    Console.WriteLine($"Writing: {hexString}");
                    status = tag.WriteEPC(hexString, "");
                }
            }

            if (status == 0)
            {
                return(true);
            }

            return(false);
        }
예제 #2
0
        public void InitUsb()
        {
            UsbPort = new FeUsb();

            UsbPort.AddEventListener(0, this, FeUsbListenerConst.FEUSB_CONNECT_EVENT);
            UsbPort.AddEventListener(0, this, FeUsbListenerConst.FEUSB_DISCONNECT_EVENT);

            try
            {
                UsbPort.ScanAndOpen(FeUsbScanSearch.SCAN_ALL, null);
            }
            catch (Exception e)
            {
                Console.Error.WriteLine(e);
            }

            for (var i = 0; i < UsbPort.ScanListSize; i++)
            {
                AddDevice(FeHexConvert.HexStringToInteger(UsbPort.GetScanListPara(i, "Device-ID")));
            }

            Interval           = new Timer();
            Interval.Interval  = 1000;
            Interval.Elapsed  += (s, e) => { ReadDevices(); };
            Interval.AutoReset = false;

            ReadDevices();
        }
예제 #3
0
        //Init usbport  with Events(connect/disconect)
        public void USBInit()
        {
            long   nDeviceID = 0;
            String sDeviceID;

            UsbPort = new FeUsb();

            UsbPort.AddEventListener(0, (FeUsbListener)this, FeUsbListenerConst.FEUSB_CONNECT_EVENT);
            UsbPort.AddEventListener(0, (FeUsbListener)this, FeUsbListenerConst.FEUSB_DISCONNECT_EVENT);

            try
            {
                UsbPort.ScanAndOpen(FeUsbScanSearch.SCAN_ALL, null);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString());
            }


            for (int i = 0; i < UsbPort.ScanListSize; i++)
            {
                sDeviceID = UsbPort.GetScanListPara(i, "Device-ID");
                if (sDeviceID.Length % 2 != 0)
                {
                    sDeviceID = "0" + sDeviceID;
                }
                nDeviceID = FeHexConvert.HexStringToLong(sDeviceID);
                AddDevice(nDeviceID);
            }
        }
        /************************************Interface(FeIscListener) Methods*****************************/
        #region FedmTaskListener Member

        public void OnNewApduResponse(int iError)
        {
            byte[] APDURespData;
            string sRespProtocol = " ";

            if (iError == 0)
            {
                APDURespData  = APDU_Prot.GetLastResponseData();
                sRespProtocol = FeHexConvert.ByteArrayToHexString(APDURespData);
            }

            IAsyncResult          result;
            DelegateOnReceiveAPDU ReceiveAPDUMethod = new DelegateOnReceiveAPDU(DisplayReceivedAPDU);

            result = (IAsyncResult)Invoke(ReceiveAPDUMethod, sRespProtocol);
        }
예제 #5
0
        public void  DisplayReceiveProtocol(byte[] receiveProtocol)
        {
            string data = "";

            if (this.comboAscii.SelectedIndex == 1)
            {
                for (int i = 0; i < receiveProtocol.Length; i++)
                {
                    data += (char)receiveProtocol[i];
                }
            }
            else
            {
                data  = FeHexConvert.ByteArrayToHexStringWithSpaces(receiveProtocol);
                data += "\r\n";
            }
            this.dataWindow.AppendText(data);
        }
        private void OnButtonClick_SendAPDU(object sender, EventArgs e)
        {
            // Example: GetVersion(1)  -> APDUSendData = 60
            // >>  02 00 0B FF B2 BE 83 00 60 16 59
            // <<  02 00 13 00 B2 00 02 00 00 AF 04 01 01 01 00 1A 05 83 6B   OK

            // Variables
            byte[] APDUSendData;
            string cProtocol;

            cProtocol = this.maskedTextBox_APDU.Text;
            if (cProtocol.Length == 0)
            {
                this.textBox_status_out.Clear();
                this.textBox_status_out.AppendText("No or to less data in Protocol! -> use data format: 112233....");
                return;
            }

            if (cProtocol.Length % 2 != 0)
            {
                this.textBox_status_out.Clear();
                this.textBox_status_out.AppendText("Wrong protocol format or protocol length - Length must be even\nUse data format: 112233....)!)");
                return;
            }

            APDUSendData = new byte[cProtocol.Length / 2];

            APDUSendData = FeHexConvert.HexStringToByteArray(cProtocol);

            try
            {
                // Set APDU data
                APDU_Prot.SetApdu(APDUSendData);
                // send APDU
                fedm.SendTclApdu(APDU_Prot);
            }
            catch (Exception ex)
            {
                MessageBox.Show(this, ex.ToString(), "Error");
            }
        }
예제 #7
0
        /************************************************ENDE******************************/

        /*********************************************Delegate Methods***********************************************/
        public void DisplayRecSets(int recSets,
                                   byte[] type,
                                   string[] serialNumber,
                                   string[] dataBlock,
                                   string[] time,
                                   string[] date,
                                   byte[] antennaNr,
                                   Dictionary <byte, FedmIscRssiItem>[] dicRSSI,
                                   byte[] input,
                                   byte[] state)
        {
            int    i;
            string d;
            string dr = "";

            Dictionary <byte, FedmIscRssiItem> RSSIval;
            FedmIscRssiItem RSSIitem;
            bool            bcheck;
            byte            antNo;

            FedmBrmTableItem[] brmItems;
            brmItems = (FedmBrmTableItem[])reader.GetTable(FedmIscReaderConst.BRM_TABLE);

            dr   += "-----------------------------------------------------------------" + "\r\n";
            dr   += "DATE/TIME: " + Time.ToString() + "\r\n";
            dr   += "-----------------------------------------------------------------" + "\r\n";
            count = 1;
            for (i = 0; i < recSets; i++)
            {
                dr   += (count).ToString().Trim() + "." + "   TRANSPONDER" + "\r\n";
                count = count + 1;
                if (type[i] >= 0)
                {
                    //just the two last bit
                    d   = "0x" + FeHexConvert.IntegerToHexString(type[i]).Substring(FeHexConvert.IntegerToHexString(type[i]).Length - 2, 2);
                    dr += "TR-TYPE:" + "\t" + d.ToString() + "\r\n";
                }

                // Output SeriaNo.
                if (brmItems[i].IsDataValid(FedmIscReaderConst.DATA_SNR))
                {
                    if (serialNumber[i] != null)
                    {
                        dr += "SNR:" + "\t\t" + serialNumber[i].ToString() + "\r\n";
                    }
                }

                // Output Data Blocks
                if (brmItems[i].IsDataValid(FedmIscReaderConst.DATA_RxDB))
                {
                    if (dataBlock[i] != null)
                    {
                        dr += "DB:" + "\t\t" + dataBlock[i].ToString() + "\r\n";
                    }
                }

                // Output Time
                if (brmItems[i].IsDataValid(FedmIscReaderConst.DATA_TIMER))
                {
                    if (time[i] != null)
                    {
                        dr += "READER TIME:" + "\t" + time[i].ToString() + "\r\n";
                    }
                }

                // Output Date
                if (brmItems[i].IsDataValid(FedmIscReaderConst.DATA_DATE))
                {
                    if (date[i] != null)
                    {
                        dr += "READER DATE:" + "\t" + date[i].ToString() + "\r\n";
                    }
                }

                // It is possible either to output the ANT_NR or the RSSI value (this is also important for the reader config!)
                // Output ANT_NR
                if (brmItems[i].IsDataValid(FedmIscReaderConst.DATA_ANT_NR))
                {
                    dr += "ANT. NR:" + "\t\t" + (antennaNr[i].ToString()).Trim() + "\r\n";
                }

                // It is possible either to output the ANT_NR or the RSSI value (this is also important for the reader config!)
                // Output RSSI
                if (dicRSSI.Length > 0)
                {
                    if (dicRSSI[i] != null)
                    {
                        RSSIval = dicRSSI[i];
                        for (antNo = 1; antNo < FedmBrmTableItem.TABLE_MAX_ANTENNA; antNo++)
                        {
                            bcheck = RSSIval.TryGetValue(antNo, out RSSIitem);
                            if (!bcheck)
                            {
                                continue;
                            }

                            dr += "RSSI of AntNr. " + "\t" + antNo.ToString() + " is " + "-" + RSSIitem.RSSI.ToString() + "dBm" + "\r\n";
                        }
                    }
                }

                // Output INPUT
                if (brmItems[i].IsDataValid(FedmIscReaderConst.DATA_INPUT))
                {
                    dr += "INPUT:" + "\t\t" + (input[i].ToString()).Trim() + "\r\n";
                    dr += "STATE:" + "\t\t" + (state[i].ToString()).Trim() + "\r\n";
                }

                dr += "" + "\r\n";
                dr += "" + "\r\n";
            }
            this.textBoxData.AppendText(dr);
            dr = "";
        }
        private void WriteSequentialHEXFormattedDecimal()
        {
            Display.WriteLine();
            Display.WriteLine("Beging Writing HEX Formatted Decimal");
            Console.Write("Prefix (HEX)");

            string prefix = Console.ReadLine();

            if (!FeHexConvert.isHexString(prefix))
            {
                Display.WriteError($"{prefix} is not a hex string, must contain 0-9 or A-F");
                return;
            }

            Console.Write("Start ID (DEC)");

            string input = Console.ReadLine();

            int padding = input.Length;

            if (!Int32.TryParse(input, out int startID))
            {
                Console.WriteLine($"{input} is not a number");
                return;
            }

            string startingUID = prefix + startID.ToString().PadLeft(padding, '0');

            Display.WriteLine($"Starting at {startingUID} (HEX)");
            Display.WriteLine("Press Enter Key to Write Tag, Escape to Cancel");

            if (!_controller.IsConnected)
            {
                Display.WriteError("Reader not connected");
                return;
            }

            ConsoleKey inputKey = ConsoleKey.Escape;

            do
            {
                bool   error   = false;
                string nextUID = String.Empty;

                inputKey = Console.ReadKey().Key;

                switch (inputKey)
                {
                case ConsoleKey.Enter:
                    nextUID = prefix + startID.ToString().PadLeft(padding, '0');
                    error   = !WriteTagHEX(nextUID);
                    break;
                }

                if (error)
                {
                    Display.WriteError("Error Writing to Tag");
                }
                else
                {
                    startID++;
                }
            } while (inputKey != ConsoleKey.Escape);
        }
예제 #9
0
        private static void WriteHEXFormattedDecimal()
        {
            Console.WriteLine();
            Console.WriteLine("Begin Tag Writing (ASCII)");
            Console.Write("Prefix (HEX): ");

            string prefix = Console.ReadLine();

            if (!FeHexConvert.isHexString(prefix))
            {
                Console.WriteLine($"{prefix} is not a Hex String");
                return;
            }

            Console.Write("Start ID (DEC): ");

            string input = Console.ReadLine();

            int padding = input.Length;

            if (!Int32.TryParse(input, out int startid))
            {
                Console.WriteLine($"{input} is not a number");
                return;
            }

            string startingUID = prefix + startid.ToString().PadLeft(padding, '0');

            Console.WriteLine($"Starting at {startingUID} (HEX)");
            Console.WriteLine($"Press Enter Key to Write Tag, Escape to Cancel");

            ConsoleKey keyInput = ConsoleKey.Escape;

            if (_controller.IsConnected) //Start loop if reader is connected
            {
                do
                {
                    bool   error   = false;
                    string nextUID = String.Empty;

                    keyInput = Console.ReadKey().Key;

                    switch (keyInput)
                    {
                    case ConsoleKey.Enter:
                        nextUID = prefix + startid.ToString().PadLeft(padding, '0');
                        //error = _controller.WriteTagHEX(nextUID);
                        break;
                    }

                    if (error)
                    {
                        Console.WriteLine($"Unknown Error Occured");
                    }
                    else
                    {
                        startid++;
                    }
                } while (keyInput != ConsoleKey.Escape);
            }
            else
            {
                Console.WriteLine($"No Reader Found");
            }
        }