我有来自stamps.com的USB称重(型号510:http://www.stamps.com/postage-online/digital-postage-scales/)
我能够找到让它独立在线的驱动程序,但我的下一个问题是如何在我的经典ASP页面/ VBScript中读取对象的重量。
有没有人有我应该开始搜索的建议?
答案 0 :(得分:2)
我不确定这是否适用于您的特定型号,但是http://nicholas.piasecki.name/blog/2008/11/reading-a-stamps-com-usb-scale-from-c-sharp/上有一篇文章,其中作者编写了C#代码以从秤中读取,因为它符合基本的USB HID(人工输入设备)标准。作者使用了Mike OBrien的HID库https://github.com/mikeobrien/HidLibrary
他们开始获取原始字节:
HidDeviceData inData;
HidDevice[] hidDeviceList;
HidDevice scale;
hidDeviceList = HidDevices.Enumerate(0x1446, 0x6A73);
if (hidDeviceList.Length > 0)
{
int waitTries;
scale = hidDeviceList[0];
waitTries = 0;
scale.Open();
if (scale.IsConnected)
{
inData = scale.Read(250);
for (int i = 0; i < inData.Data.Length; ++i)
{
Console.WriteLine("Byte {0}: {1:X}", i, inData.Data[i]);
}
}
scale.Close();
scale.Dispose();
}
然后继续对有效载荷进行逆向工程并构建一个函数来获得以盎司为单位的权重:
private void GetStampsComModel2500iScaleWeight(out decimal? ounces, out bool? isStable)
{
HidDeviceData inData;
HidDevice[] hidDeviceList;
HidDevice scale;
isStable = null;
ounces = null;
hidDeviceList = HidDevices.Enumerate(0x1446, 0x6A73);
if (hidDeviceList.Length > 0)
{
int waitTries;
scale = hidDeviceList[0];
waitTries = 0;
scale.Open();
// For some reason, the scale isn't always immediately available
// after calling Open(). Let's wait for a few milliseconds before
// giving up.
while (!scale.IsConnected && waitTries < 10)
{
Thread.Sleep(50);
waitTries++;
}
if (scale.IsConnected)
{
inData = scale.Read(250);
ounces = (Convert.ToDecimal(inData.Data[4]) +
Convert.ToDecimal(inData.Data[5]) * 256) / 10;
isStable = inData.Data[1] == 0x4;
}
scale.Close();
scale.Dispose();
}
}
为了从经典的ASP页面/ VBScript读取权重(在服务器上,对吧?),最简单的解决方案就是将工作的C#类转换为COM组件。您可以按照教程创建C#COM组件并在服务器上注册它,然后您可以从VBScript中调用它,如:
Dim app
Set app = Server.CreateObject("MyScaleComponent")