我正在寻找一种邮资秤,它已经为我正在开发的运输系统提供了 linux 支持(驱动程序等)。我打算使用 Ubuntu 9.04,但我愿意切换发行版以获得兼容性。
有人知道目前有效的秤吗?是否有一个开源项目正在开发规模驱动程序或类似项目?
谢谢!
我使用 5 磅的 stamps.com 秤。如果您在他们那里注册一个帐户然后取消它,您可以花 10 美元购买它。
要在 linux 中读取它,请获取此脚本: http: //gist.github.com/503896
编辑脚本文件以设置正确的 hidraw 设备路径。插入刻度后,您可以通过运行找到路径dmesg
。您将看到类似“/dev/hidraw2”的内容。
在脚本中设置好hidraw路径后,添加执行权限,然后以root身份运行:
chmod +x usbscale.pl
须藤 ./usbscale.pl
将一个物体放在秤上,它会打印重量。
更新:
我创建了 mattismyname 链接的早期脚本的更新版本。它是用 C 编写的,你可以在https://github.com/erjiang/usbscale找到它
要使用它,只需下载源代码并运行(在其目录中):
sudo aptitude install libusb-1.0-0-dev
make
./usbscale
如果遇到权限错误,您可能需要将 复制50-usb-scales.rules
到您的/etc/udev/rules.d
(或运行为,哈哈)。root
指数值作为有符号整数传递,权重以小端字节顺序传递。其他答案没有正确考虑这些因素。在此处查看更全面的示例。
<?php
$binary = fread(fopen('/dev/hidraw3', 'r'), 7);
$data = (object) unpack('Creport/Cstatus/Cunit/cexponent/vweight', $binary);
if ($data->report == 0x03 && $data->status == 0x04) {
$data->weight = $data->weight * pow(10, $data->exponent);
if ($data->unit == 0x0B) {
// convert ounces to grams
$data->weight *= 28.349523125;
// and unit to grams
$data->unit = 0x02;
}
if ($data->unit == 0x02) {
echo "{$data->weight} g\n";
} else {
echo "{$data->weight} in other unit\n";
}
}