1

我正在使用 USBHIDDRIVER 访问连接到我们本地工作站的秤。当我在 Visual Studio 2012 Debug 中运行 WCF 时,一切正常。但是一旦我尝试在 IIS 中运行该服务,它似乎就无法识别 USBHIDDRIVER。我在 WCF 中有一个测试服务,它工作正常,所以 WCF 正在工作。

有关如何解决此问题的任何信息都将非常有帮助。我的问题是 WCF 是在我部署到 IIS 服务器时编译的,所以我很难尝试进行故障排除。

以下是有关 USBHIDDRIVER 的其他信息:http: //www.florian-leitner.de/index.php/projects/usb-hid-driver-library/

namespace USBDevices
{    
    public class Service1 : IService1
    {
        public string GetWeight(string id)
        {
            USBHIDDRIVER.USBInterface usb = new USBHIDDRIVER.USBInterface("vid_0922","pid_8007"); 
            //string[] list = usb.getDeviceList();
            string result;
            string resultDesc;
            byte itemWeight;
            byte itemUOM;

            result = "";
            resultDesc = "";
            itemWeight = 0;
            itemUOM = 0;

            if (usb.Connect() == true)
            {
                usb.startRead();
                Thread.Sleep(100);
                for (int i = 0; i < 200; i++)
                {
                    var weight = USBHIDDRIVER.USBInterface.usbBuffer;
                    var cnt = weight.Count;
                    itemWeight = ((byte[])weight[cnt - 1])[4];
                    itemUOM = ((byte[])weight[cnt - 1])[2];
                }
                usb.stopRead();
                result = "Success";
                resultDesc = "Scale Found";
                Debug.WriteLine("Result: " + result + "-" + resultDesc + "  -  Item Weight: " + ((float)itemWeight / 10));
            }
            else
            {
                result = "Failed";
                resultDesc = "Scale Not Active";
                itemWeight = 0;
                itemUOM = 0;
                Debug.WriteLine("Result: " + result + "-" + resultDesc + "  -  Item Weight: " + ((float)itemWeight / 10));
            }

            return result + "|" + resultDesc + "|" + ((float)itemWeight / 10) + "|" + itemUOM;

        }

        public string XMLData(string id)
        {
            return "You requested product " + id;
        }

    }

    // Use a data contract as illustrated in the sample below to add composite types to service operations.
    [DataContract]
    public class CompositeType
    {
        bool boolValue = true;
        string stringValue = "Hello ";

        [DataMember]
        public bool BoolValue
        {
            get { return boolValue; }
            set { boolValue = value; }
        }

        [DataMember]
        public string StringValue
        {
            get { return stringValue; }
            set { stringValue = value; }
        }
    }
}
4

1 回答 1

0

为了解决这个问题,我不得不为网站打开“启用 32 位应用程序”。相信问题与使用的 DLL 有关,但 USBHIDDRIVER

于 2015-06-05T17:46:42.907 回答