2

いくつかのビットをコンピューターに送信する回路を構築したいと考えています。data+ と data- ケーブルを使用して USB ポートを使用してビットをコンピューターに送信することを考えていましたが、これらのビットをキャプチャする方法がわかりません。ドライバーを作成せずに、C# でこれらのビットをキャプチャするにはどうすればよいですか?

USBからの読み取りに関する以前の投稿をたくさん読みましたが、私の質問に答えたものはありませんでした。

4

2 に答える 2

1

I/O 信号を USB ポートが理解できる信号に変換するデバイスが必要な最も簡単なソリューションです。

私は過去にU421を使用しました.P / Invokeを使用してDLLをロードするだけのライブラリがあり、チップのピンに信号を送信できます。次に、読み取りたいものをすべてチップに配線する必要があります (正しくは、スタック オーバーフローの範囲外です。 Electronics.StackExchange.comを試してください)。サンプル コードと配線図については、USBMicro Web サイトU4x1 Application Notesのセクションを参照してください 。

ウェブサイトのコード例:

⁄⁄ needed to import the .dll
using System.Runtime.InteropServices;

    public class USBm
        {
        public static byte BitA0 = 0x00;
        public static byte BitA1 = 0x01;
        public static byte BitA2 = 0x02;
        public static byte BitA3 = 0x03;
        public static byte BitA4 = 0x04;
        public static byte BitA5 = 0x05;
        public static byte BitA6 = 0x06;
        public static byte BitA7 = 0x07;
        public static byte BitB0 = 0x08;
        public static byte BitB1 = 0x09;
        public static byte BitB2 = 0x0A;
        public static byte BitB3 = 0x0B;
        public static byte BitB4 = 0x0C;
        public static byte BitB5 = 0x0D;
        public static byte BitB6 = 0x0E;
        public static byte BitB7 = 0x0F;

⁄⁄  USBm.dll - C# pInvoke examples
⁄⁄  "Commands"
⁄⁄      [DllImport("USBm.dll", EntryPoint = "USBm_FindDevices", CharSet = CharSet.Auto)]
        [DllImport("USBm.dll")]
        public static extern bool USBm_FindDevices();
        [DllImport("USBm.dll")]
        public static extern int USBm_NumberOfDevices();
        [DllImport("USBm.dll")]
        public static extern bool USBm_DeviceValid(int Device);
        [DllImport("USBm.dll")]
        public static extern bool USBm_About(StringBuilder About);
        [DllImport("USBm.dll")]
        public static extern bool USBm_Version(StringBuilder Version);
        [DllImport("USBm.dll")]
        public static extern bool USBm_Copyright(StringBuilder Copyright);
        [DllImport("USBm.dll")]
        public static extern bool USBm_DeviceMfr(int Device, StringBuilder Mfr);
        [DllImport("USBm.dll")]
        public static extern bool USBm_DeviceProd(int Device, StringBuilder Prod);
        [DllImport("USBm.dll")]
        public static extern int USBm_DeviceFirmwareVer(int Device);
        [DllImport("USBm.dll")]
        public static extern bool USBm_DeviceSer(int Device, StringBuilder dSer);
        [DllImport("USBm.dll")]
        public static extern int USBm_DeviceDID(int Device);
        [DllImport("USBm.dll")]
        public static extern int USBm_DevicePID(int Device);
        [DllImport("USBm.dll")]
        public static extern int USBm_DeviceVID(int Device);
        [DllImport("USBm.dll")]
        public static extern bool USBm_DebugString(StringBuilder DBug);
        [DllImport("USBm.dll")]
        public static extern bool USBm_RecentError(StringBuilder rError);
        [DllImport("USBm.dll")]
        public static extern bool USBm_ClearRecentError();
        [DllImport("USBm.dll")]
        public static extern bool USBm_SetReadTimeout(uint TimeOut);
        [DllImport("USBm.dll")]
        public static extern bool USBm_ReadDevice(int Device, byte[] inBuf);
        [DllImport("USBm.dll")]
        public static extern bool USBm_WriteDevice(int Device, byte[] outBuf);
        [DllImport("USBm.dll")]
        public static extern bool USBm_CloseDevice(int Device);
        }

関数呼び出しの例

⁄⁄ Test USBm device attached

if ( !USBm.USBm_FindDevices() )
    { 
    MessageBox.Show( string.Format("No Device Present"), "USBm Devices", MessageBoxButtons.OK, MessageBoxIcon.Information );
    return;
    }  ⁄⁄ implied else

⁄⁄Walk the USBm.dll functions

⁄⁄ some containers
StringBuilder sb = new StringBuilder( 200 );
bool result = false;  ⁄⁄ return values

⁄⁄ .DLL FindDevices  returns the number of devices
result = USBm.USBm_FindDevices();

⁄⁄ return the number of devices
int TotalDevices = USBm.USBm_NumberOfDevices();
int Device = TotalDevices -1;  ⁄⁄ only One device is ever attached so ...

⁄⁄ .DLL About info
result = USBm.USBm_About( sb );

⁄⁄ .DLL Version info
result = USBm.USBm_Version( sb );

⁄⁄ .DLL Copyright info
result = USBm.USBm_Copyright( sb );

⁄⁄ Device Valid
result = USBm.USBm_DeviceValid( Device );

⁄⁄ Device Manufacturer
result = USBm.USBm_DeviceMfr( Device, sb );

⁄⁄ Device Product String
result = USBm.USBm_DeviceProd( Device, sb );

⁄⁄ Device Firmware Version
int FirmVer = USBm.USBm_DeviceFirmwareVer(Device);

⁄⁄ Device SerialNumber [ ]
result = USBm.USBm_DeviceSer(Device, sb);

⁄⁄ Device DiD
int DID = USBm.USBm_DeviceDID(Device);

⁄⁄ Device PiD
int PID = USBm.USBm_DevicePID(Device);

⁄⁄ Device ViD
int VID = USBm.USBm_DeviceVID(Device);

⁄⁄ Device Debug String
result = USBm.USBm_DebugString(sb);

⁄⁄ Device Recent Error - always returns true
result = USBm.USBm_RecentError(sb);

⁄⁄ Device Clear Recent Error
result = USBm.USBm_ClearRecentError();

⁄⁄ Device SetReadTimeout [ sixteen-bit millisecond value]
uint tOUT = 3000;
result = USBm.USBm_SetReadTimeout(tOUT);

⁄⁄ Device WriteDevice [ 8 byte to write (device raw commands)]
byte[] OutBuf = { 0, 21, 3, 65, 8, 17, 60, 0 };
result = USBm.USBm_WriteDevice(Device, OutBuf);

⁄⁄ Device ReadDevice [ ]
byte[] InBuf = { 0, 0, 0, 0, 0, 0, 0, 0 };
result = USBm.USBm_ReadDevice(Device, InBuf);

// Device CloseDevice [ ]
result = USBm.USBm_CloseDevice(Device);
于 2012-08-19T18:41:43.160 に答える
0

もう 1 つのオプションは、既製のカスタム ドライバーを使用することです。これはlibusb-win32の例です。上部フィルター デバイス ドライバーをインストールし、標準/文書化されたコマンド、またはカスタム コマンドを USB に送信できるようにします。

PS 「リンク」セクションまで下にスクロールして、C#/VB.NET のダウンロードとコード例のリンクを見つけます。

于 2012-08-20T07:07:10.623 に答える