クロムプラグイン/拡張機能経由でシリアル/ USBポートにアクセスしようとしています。私はそれは私も基本的にchrome.usb/chrome.serial未定義である、google chrome sampleからサンプルコードを試してみましたが、同じ問題を経験したchrome.serial/chrome.usb undefined
"Uncaught TypeError: Cannot read property 'getDevices' of undefined"
スロー私のプラグインを開始しchrome usb & & chrome serial、からドキュメントを以下のイム。
私に正しい方向を示すための提案はありがたいです。ありがとう!私のサンプルコード
popup.html
<!DOCTYPE html>
<html>
<body style="width: 300px">
Open <a href="http://stackoverflow.com" target="_blank">this page</a> and then
<button id="clickme">click me</button>
<script type="text/javascript" src="popup.js"></script>
</body>
</html>
popup.js
function readPorts() {
console.log("Reading ports . . . . . ")
chrome.usb.getDevices(function(devices) {
console.warn('chrome.usb.getDevices error: ' +
chrome.runtime.lastError.message);
for (var i = 0; i < devices.length; i++) {
console.log('Device : ' + devices[i].path + '"===' + devices[i].path + '=====');
}
});
}
document.getElementById('clickme').addEventListener('click', readPorts);
マニフェスト
を取り付けるイム
{
"manifest_version": 2,
"name": "Getting started example",
"description": "This extension will read the com ports from your machine",
"version": "1.0",
"browser_action": {
"default_icon": "icon.png",
"default_popup": "popup.html",
"default_title": "Read com ports!"
},
"content_scripts": [
{
"matches": ["http://*/*","https://*/*"],
"js": ["myscript.js"]
}
],
"permissions": [
"serial",
"usb"
]
}
上記のガイドラインは参考になり、私はbtwnアプリケーションと拡張機能の違いを理解しています。 – optimus