LoginSignup
0
0

More than 1 year has passed since last update.

cscの作法 その291

Last updated at Posted at 2023-01-22

概要

cscの作法、調べてみた。
HidApiAdapter.dll使ってみた。

コンパイル手順

>set PATH=C:\Windows\Microsoft.NET\Framework\v4.0.30319;%PATH%

>csc /r:HidApiAdapter.dll usb0.cs

サンプルコード

using System;
using System.Linq;
using HidApiAdapter;

namespace DevicesViewer
{
	class Program {
		private static void ShowDevices() {
			var deviceManager = HidDeviceManager.GetManager();
			var devices = deviceManager.SearchDevices(0, 0);
			if (devices.Any())
			{
				foreach(var device in devices)
				{
					device.Connect();
					ShowDeviceInfo(device);
					device.Disconnect();
				}
			}
			else
			{
				Console.WriteLine("no devices found");
			}
		}
		private static void ShowDeviceInfo(HidDevice device) {
			Console.WriteLine(String.Format("device: {0}", device.Path()));
			Console.WriteLine(String.Format("manufacturer: {0}", device.Manufacturer()));
			Console.WriteLine(String.Format("product: {0}", device.Product()));
			Console.WriteLine(String.Format("serial number: {0}", device.SerialNumber()));
			Console.WriteLine("");
		}
		static void Main(string[] args) {
			ShowDevices();
		}
	}
}

実行結果

>usb0
device: \\?\hid#atk4002#3&2f32b022&0&0000#{4d1e55b2-f16f-11cf-88cb-001111000030}
manufacturer:
product:
serial number:

device: \\?\hid#elan1200&col03#5&150f7c31&0&0002#{4d1e55b2-f16f-11cf-88cb-001111000030}
manufacturer: Microsoft
product: HIDI2C Device
serial number: 9999


以上。

0
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
0
0