DllNotFoundException:hid.dll C#Linux

时间:2017-10-03 10:02:47

标签: c# .net linux dll

我正在使用USB连接RFIDReader并尝试与之通信。它适用于Windows。但是这个程序应该在我的覆盆子pi上运行,其操作系统是raspbian的,它告诉我当程序尝试使用RFIDReader的API时,找不到一个名为hid.dll的dll。我猜是因为hid.dll特定于windows。由于Linux没有hid.dll,我还能做些什么来解决问题仍然让我的程序在Linux上运行?在Linux中是否有类似Hid.dll的东西?

我与读者打交道的代码如下。当它执行方法InitReader()时,将出现问题。希望有人能帮助我,非常感谢!

using SkyeTek.Devices;
using SkyeTek.Tags;
using SkyeTek.STPv3;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Timers;
using System.Threading;

namespace RFIDReader
{
    /// <summary>
    /// this class represents the RFID reader, used to set the reader, send commond to the reader and ask response from the reader
    /// </summary>
    public class RFIDReader : EventArgs
    {
        public Device rfidReader { get; set; }
        public String tagID;
        public String buffer;
        public static int count;
        Thread timer; //the thread responsible for counting the timeout
        public static bool tagRead = false; // determine if a person can pay for a product when a tag is detected
        public event EventHandler<RFIDReader> TagDetected; //Tag detected event, raised once a tag is detected by the reader

        /// <summary>
        /// initiate the reader, set it as auto scanning tags
        /// </summary>
        public void InitReader()
        {
            if (FindLinkedDevices())
            {
                Console.WriteLine("RFIDReader: Opening device:  " + rfidReader.ToString());
                rfidReader.Open();
                AutoScanTags();
                rfidReader.Close();
            }
        }

        /// <summary>
        /// scanning tags automatically
        /// </summary>
        public void AutoScanTags()
        {
            STPv3Request request;
            STPv3Response response;
            SkyeTek.Tags.Tag tag = new SkyeTek.Tags.Tag();
            tag.Type = TagType.AUTO_DETECT;

            // Build the SelectTag request
            request = new STPv3Request();
            request.Command = STPv3Commands.SELECT_TAG;
            request.Tag = tag;

            //set the reader's flag as loop mode and inventory mode. So The reader reads all the tags in the field and then continuously
            //scans for any tags that enter the field and reports back their tag IDs.
            request.Loop = true;
            request.Inventory = true;

            // Issue the request to the output device
            while (true)
            {
                request.Issue(rfidReader);
                response = request.GetResponse();

                if (response.ResponseCode == STPv3ResponseCode.SELECT_TAG_PASS)
                {
                    //paymentValid = false;
                    buffer = BitConverter.ToString(response.TID);
                    if (buffer.Length > 0 && !buffer.Equals(tagID)) //if the tagID is a new ID, rasie tagdetected event, send data to RFIDData instance and start the timer
                    {
                        if (timer != null && timer.IsAlive)
                        {
                            timer.Abort();
                        }
                        tagID = buffer;
                        OnTagDetected(tagID);
                        timer = new Thread(Timing);
                        timer.Start();
                    }
                    else
                    {
                        if (buffer.Length > 0 && count >= 5) // if the tagID is not a new ID, check the timeout. If time is over, rasie tagdetected event, send data to RFIDData instance and start the timer
                        {
                            tagID = buffer;
                            OnTagDetected(tagID);
                            timer = new Thread(Timing);
                            timer.Start();
                        }
                        /*else
                        {
                            if(buffer.Length >0 && count >= 3 && request.GetResponse() != null)
                            {
                                paymentValid = true;
                            }
                        }*/
                    }
                }
            }
        }

        /// <summary>
        /// Find the readers connected to the computer
        /// </summary>
        /// <returns></returns>
        public bool FindLinkedDevices()
        {
            Console.WriteLine("RFIDReader: Enumerating linked devices");
            Device[] LinkedDevices = USBDeviceFactory.Enumerate();
            //Identify the RFID reader
            if (LinkedDevices.Length == 0)
            {
                Console.WriteLine("RFIDReader: No USB devices found");
                return false;
            }
            else
            {
                foreach (Device i in LinkedDevices)
                {
                    Console.WriteLine("RFIDReader: USB devices found ---> " + i.ToString());
                    if (i.ToString().Equals("SkyeTek.Devices.USBDevice"))
                    {
                        rfidReader = i;
                    }
                }
                return true;
            }
        }

        /// <summary>
        /// Rasie an tagDetected event once the reader detects a tag
        /// </summary>
        /// <param name="TID"></param>
        protected virtual void OnTagDetected(String TID)
        {
            if (TagDetected != null)
            {
                TagDetected(this, new RFIDReader() { tagID = TID });
            }
        }

        /// <summary>
        /// timing method running on the timer thread
        /// </summary>
        public void Timing()
        {
            for (count = 0; count < 5; count++)
            {
                System.Threading.Thread.Sleep(1000);
            }
        }
    }
}

0 个答案:

没有答案