1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

WebUSBからPIC18Fをつついてみる(仮)

Last updated at Posted at 2017-09-19

うっほあー、USB関連勉強した後だとめっちゃ簡単、というか、libusbそのまんまやんこれ
ベンダーIDも変更してみるか
Microsoft OS 2.0 Descriptorが自動認識の鍵になっているのはわかった。Win8.1以降から使えるらしい。

webusb.htm
<html>
Hello<br>
<script src="webusb.js"></script>
<input type="button" onClick="connectbutton()" value="接続">
</html>
webusb.js
function connectbutton()
{
	var device;
	var buf = new ArrayBuffer(1);
	var dat = new Uint8Array(buf, 0, buf.length);
	dat[0] = 0x81;
		
	navigator.usb.requestDevice({ filters: [{ vendorId: 0x04D8 , productId: 0x0053}] })
	.then(selectedDevice => {
	   device = selectedDevice;
	   return device.open(); // Begin a session.
	 })
//	.then(() => device.selectConfiguration(0)) // Select configuration #1 for the device.
	.then(() => device.claimInterface(0)) // Request exclusive control over interface #2.
	.then(() => device.transferOut(1, dat)) // Waiting for 64 bytes of data from endpoint #5.
	.then(() => device.transferIn(1, 64)) // Waiting for 64 bytes of data from endpoint #5.
	.then(result => {
		for(i=0;i<result.data.byteLength;i++)
		{
			console.log('Received: ' + result.data.getInt8(i));
		}
	})
	.catch(error => { console.log(error); });
}

#動作サンプル
もうちょっとマシなやつを実際に動く形で置いてみました.
Chromeの最新版をお使いの場合は、以下のページのWebUSBで確認ができます.
https://sabowl.sakura.ne.jp/gpsnmeajp/webusb/webusb.htm

#参考文献
Access USB Devices on the Web
https://developers.google.com/web/updates/2016/03/access-usb-devices-on-the-web

1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?