8ピンPICでUSB -16FUSBの移植-
8ピンPICでUSB
Emanuel Paz様の16FUSBを8ピンのPIC12F1822に実装しました。他の8ピンPICにも移植可能です。
Emanuel Paz様の16FUSBのページ
16FUSB - A USB 1.1 implementation for PIC16F628/628A
http://www.lendlocus.com/?q=16fusb#firmware
このページで紹介されているDirect I/O HIDでは8ピンの良さを生かしきれないので、
シリアルインターフェースを用いた双方向通信機能(擬似CDC)を実装しました。
概要
壱 )HIDレポートでキャラクタをやり取りします。エンドポイント1(IN/OUT)を使用
弐 )バルク転送できません
参 )工夫すれば通信条件をホスト側から変更できますが、現時点では対応してません
(現在の通信条件 9600bps 8bit ノーパリティ ストップ1bit フロー制御なし)

<シリアルホストプログラムでのループバックテスト>

<ファームウエア>
16FUSBのページのFirmware以下にある
16FUSB-dio_hid-src-1.2.tar.gz
を展開してPIC12F1822用に書き換え、再コンパイル。
<HEXファイル PIC12F1822>(2013年2月24日 改定)
:020000040000FA
:0800000010308B0025290000DF
:08000800F000030EF1000810E6
:1000100088100C1908280C1D0B280408F2000C1D70
:100020000B282030840080010C1900148C1D4328FB
:100030000C1980148C1D43280C1900158C1D4328A5
:100040000C1980158C1D43280C1900168C1D432893
:100050000C1980168C1D43280C1900178C1D432881
:100060000C198017840A80010C1900148C1D432878
:100070000C1980148C1D43280C1900158C1D432865
:100080000C1980152428A0187B28201C7328201AFE
:100090006F287311210DA106A11F7315731D592817
:1000A000F31E6228F3123D3084004C08D0004B0848
:1000B0006528731F622873132D3084003C08D0001C
:1000C0003B0865285A30FD207328AC20731973282B
:1000D0007608F500F31D7328F40A731473282008BA
:1000E000CF002108D00072088400710E8300F00E4A
:1000F000700E8B1009007F3050057506031D7328A4
:10010000731C87284F1D08005A30FD207328D230F9
:10011000FD2020300402CE00DA004E08033A031915
:1001200073287314F314F3134F19F3177311500D4D
:10013000D006D01F73152030CF005B30D0004F08A1
:1001400084000008CD00500884004D088000CF0ACC
:10015000D00ACE0B9F287328033ECF000C1608143C
:10016000EB308C0508100730CD000310CF0DCF0DFC
:100170004F0D083E5007FF3C950000000000303056
:100180008B001430C328C4288C06CD0BC428C82883
:10019000C928001C8C060B19F028801C8C060B1932
:1001A000F028001D8C060B19F028801D8C060B19F9
:1001B000F028001E8C060B19F028801E8C060B19E7
:1001C000F028001F8C060B19F028801F8C06840A6B
:1001D0000000001C8C060B19F028801C8C06D1280E
:1001E000EB308C058B12F4281030F62800008C06BA
:1001F000081414308C0408100800CE000C160814E3
:10020000EB308C0508100730CD0014308C06CD0B78
:1002100006290A290B294E1C8C060E29CE1C8C0699
:1002200011294E1D8C061429CE1D8C0617294E1E31
:100230008C061A29CE1E8C061D294E1F8C062029DD
:06024000CE1F8C06F02821
:04024600003400344C
:06024A0096230814881041
:10025000C13095001C308C0408108810F3012A303E
:10026000F500F600C330BD008B178C1DD821AA23E2
:1002700008108810731C3529F3184721F31F96299D
:10028000C223F3183D29731073193529CC2908109E
:1002900088105A03EC005C30EA00F7015230EB00A2
:1002A0000130E90006305B1B0430EF0068100830B5
:1002B000EE006A0884000008DB006B088400083048
:1002C000ED00681C682968105B08E900DB0CED0391
:1002D0005B08E906E909691C7429EF0B7629DB0C38
:1002E000ED0B74296814ED0A0630EF00E90C800C60
:1002F0005B08E900EE0B8729F70A77085A02033AF0
:1003000003198D29EB0A6B0884000830EE00DB0C22
:10031000ED0B6829EA0AEC0B5929F310F31B0800CE
:10032000F401C330AD005808D10008006030520518
:10033000DB00D21FBC29A222DB080319A129552307
:10034000B5295308063A031DAA295508223A03196C
:100350005623B522D308031949235308083A031931
:100360004C2353080A3A03194F230810881003013D
:10037000F02103011A22D529DB080319C1295523CD
:10038000C5295308053A0319512308108810D108CC
:100390000319CE2973103529081088104B30AD0091
:1003A000AE01AF01BB01BC01F31173107317352906
:1003B000081088100330EC008C190800EC0BDC29C5
:1003C0002A30F500F600080008108810C330BD1D63
:1003D0004B30BD000130F02101301A22F316080025
:1003E000003A0319F7293E3084004B08FA292E30D1
:1003F00084003B08EB00FF30E900EA0000080B2214
:10040000840AEB0BFE29E90969088000840AEA09DD
:100410006A0880000800E9060830ED00EA0CEA13DB
:10042000E90C031C172AA030EA060130E906ED0B9F
:100430000E2A0800EF00003A0319232A3D308400F9
:10044000CC014B08272A2D308400BC013B08033E19
:10045000EB000430EE000008E9000830EC00013049
:100460006905013C031D362AEE03382A0630EE00EA
:10047000E90C03016E0203194322EC0B2F2A840AB4
:10048000EB0B2B2A08006F08031D482ABC0A492AD7
:10049000CC0A6B08ED00ED0A0408E8000008EA0049
:1004A000800D840AED0B502A680884000930E800AA
:1004B0006C08E80200106A180014E80B602A8A2A07
:1004C0008010EA188014E80B662A8C2A00116A1939
:1004D0000015E80B6C2A8E2A8011EA198015E80BAA
:1004E000722A902A00126A1A0016E80B782A922AB9
:1004F0008012EA1A8016E80B7E2A942A00136A1BDF
:100500000017E80B842A962A8013EA1B8017E80B51
:100510008A2A982A80109B2A00119B2A80119B2AE4
:1005200000129B2A80129B2A00139B2A80139B2A6D
:10053000840A001084030630EE0001306C02031DB3
:10054000EC03080008305102031CAD2AD10008302A
:10055000BB000319AF2AF315B02A5108BB00F311F1
:0A056000C330AD1D4B30AD000800A4
:06056A005508013A0319D7
:10057000BE2A5508023A0319E82A08007408013A0D
:100580000319D52A7408023A0319E42A1230AE007E
:100590000130AF001030B0000130B100FF30B200C8
:1005A000B301B4010830B5000800D830AE00043003
:1005B000AF002830B0000630B1000030B20001308A
:1005C000B300B401B5010800AE010130AF0008006E
:1005D0007408013A03190A2B7408023A0319182BFC
:1005E0007408053A0319462B7408043A0319352B8D
:1005F0007408033A0319252B0930AE000230AF000E
:100600002930B000B1010130B200B300B401803034
:10061000B50008003230AE000930AF000430B00041
:10062000B101B2010230B3000330B400B5010800DB
:10063000AE01AF010930B0002130B1001030B2007E
:100640000130B300B401B50008002230AE0019300B
:10065000AF00B0010730B1000530B2008130B30007
:100660000330B4000830B50008000030AE00083098
:10067000AF000730B0000530B1000130B2000330E8
:10068000B3000830B4000030B50008000830AE00F8
:100690000800AE01AF0108000130AE000800AE0155
:0A06A00008005E08F600F6130800DB
:0606AA0008007408013A8B
:1006B0000319732B7408023A0319822B7408033A46
:1006C0000319932B0630AE00A030AF00FF30B0000E
:1006D0000930B1000130B200A130B3000130B400E4
:1006E0000930B50008000330AE001530AF00B0018E
:1006F0002630B100FF30B200B3017530B4000830CD
:10070000B50008009530AE000130AF008130B00078
:100710000230B1000930B2000430B3009130B400AF
:0C0720000230B5000800C030AE00080038
:04072C000814881411
:100730008C0124309E0008309F0070309B000230F6
:100740009C0090309D008810FE308C0008108C01B9
:1007500098110800911E0800081488141D19BA2B5E
:100760009D18BD2B190808108810BE000130CB0061
:10077000E421080019089D1CBF2B1D121D1608102E
:0407800088100800D5
:0C078400731D08005208081488149E1C05
:0A079000C72B9A000810881008001B
:020000040001F9
:02000E00A7C980
:02001000FFDC13
:00000001FF
コンパイルにはatlstr.h互換ライブラリTString.h(JEX様作)を使用しています。
ダウンロード先
http://victreal.com/Junk/_T/index.html
コンパイル環境 Microsoft Visual Studio 10.0
16FUSBのページのDirect I/O HID Sample Application (win32)以下にある
16FUSB_dio_hid_sample_application_win32-src-1.0.zip
を展開、TString.hを追加し、Form1.hを書き換えて、再コンパイル。
プロジェクトファイルはそのまま使用。
<Form1.hのソース>
#pragma once
#include "stdio.h"
#include <wtypes.h>
#include <string>
#include "Usb.h"
#include <iostream>
#include <stdlib.h>
#include "TString.h"
namespace My16FUSB_HID_DioSampleAPP {
using namespace System;
using namespace System::ComponentModel;
using namespace System::Collections;
using namespace System::Windows::Forms;
using namespace System::Data;
using namespace std;
using namespace System::Drawing;
using namespace System::Threading;
/// <summary>
/// Summary for Form1
/// </summary>
public ref class Form1 : public System::Windows::Forms::Form
{
delegate void SetCheckDelegate();
public:
Form1(void)
{
InitializeComponent();
usb = gcnew Usb();
usb->VendorID = 0x04D8;
usb->ProductID = 0x0628;
if(usb->findDevice()) {
this->toolStripStatuslabel1->Text = "Device Connected";
usb->openReadHandle();
bgWorker = gcnew System::ComponentModel::BackgroundWorker();
bgWorker->DoWork += gcnew DoWorkEventHandler( this, &Form1::inputThread );
bgWorker->RunWorkerAsync();
usb->openWriteHandle();
} else {
System::Windows::Forms::MessageBox::Show( L"Device not found!", L"16FUSB",
System::Windows::Forms::MessageBoxButtons::OK);
}
}
protected:
/// <summary>
/// Clean up any resources being used.
/// </summary>
~Form1()
{
if (components)
{
delete components;
}
}
private: System::Windows::Forms::GroupBox^ groupBox1;
private: System::Windows::Forms::GroupBox^ groupBox2;
private: System::Windows::Forms::TextBox^ textBox1;
private: System::Windows::Forms::TextBox^ textBox2;
private: System::ComponentModel::IContainer^ components;
protected:
private:
/// <summary>
/// Required designer variable.
/// </summary>
private: System::Windows::Forms::StatusStrip^ statusStrip1;
private: System::Windows::Forms::ToolStripStatusLabel^ toolStripStatuslabel1;
System::ComponentModel::BackgroundWorker^ bgWorker;
Usb^ usb;
#pragma region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
void InitializeComponent(void)
{
this->groupBox1 = (gcnew System::Windows::Forms::GroupBox());
this->groupBox2 = (gcnew System::Windows::Forms::GroupBox());
this->textBox1 = (gcnew System::Windows::Forms::TextBox());
this->textBox2 = (gcnew System::Windows::Forms::TextBox());
this->statusStrip1 = (gcnew System::Windows::Forms::StatusStrip());
this->toolStripStatuslabel1 = (gcnew System::Windows::Forms::ToolStripStatusLabel());
this->groupBox1->SuspendLayout();
this->groupBox2->SuspendLayout();
this->statusStrip1->SuspendLayout();
this->SuspendLayout();
//
// groupBox1
//
this->groupBox1->Controls->Add(this->textBox1);
this->groupBox1->Location = System::Drawing::Point(30, 93);
this->groupBox1->Name = L"groupBox1";
this->groupBox1->Size = System::Drawing::Size(256, 73);
this->groupBox1->TabIndex = 1;
this->groupBox1->TabStop = false;
this->groupBox1->Text = L"Send to Serial";
//
// groupBox2
//
this->groupBox2->Controls->Add(this->textBox2);
this->groupBox2->Location = System::Drawing::Point(30, 13);
this->groupBox2->Name = L"groupBox2";
this->groupBox2->Size = System::Drawing::Size(256, 73);
this->groupBox2->TabIndex = 2;
this->groupBox2->TabStop = false;
this->groupBox2->Text = L"Recive from Serial";
//
// textBox1
//
this->textBox1->Location = System::Drawing::Point(18, 33);
this->textBox1->Multiline = true;
this->textBox1->Name = L"textBox1";
this->textBox1->Size = System::Drawing::Size(200, 30);
this->textBox1->TabIndex = 0;
this->textBox1->KeyPress += gcnew KeyPressEventHandler(this, &Form1::textBox1_KeyPress);
//
// textBox2
//
this->textBox2->Location = System::Drawing::Point(18, 33);
this->textBox2->Multiline = true;
this->textBox2->Name = L"textBox2";
this->textBox2->Size = System::Drawing::Size(200, 30);
this->textBox2->TabIndex = 0;
this->textBox2->ReadOnly = true;
//
// statusStrip1
//
this->statusStrip1->Items->AddRange(gcnew cli::array< System::Windows::Forms::ToolStripItem^ >(1) {this->toolStripStatuslabel1});
this->statusStrip1->Location = System::Drawing::Point(0, 197);
this->statusStrip1->Name = L"statusStrip1";
this->statusStrip1->Size = System::Drawing::Size(319, 22);
this->statusStrip1->TabIndex = 4;
this->statusStrip1->Text = L"statusStrip1";
//
// toolStripStatuslabel1
//
this->toolStripStatuslabel1->Name = L"toolStripStatuslabel1";
this->toolStripStatuslabel1->Size = System::Drawing::Size(0, 17);
//
// Form1
//
this->AutoScaleDimensions = System::Drawing::SizeF(6, 13);
this->AutoScaleMode = System::Windows::Forms::AutoScaleMode::Font;
this->ClientSize = System::Drawing::Size(319, 219);
this->Controls->Add(this->statusStrip1);
this->Controls->Add(this->groupBox2);
this->Controls->Add(this->groupBox1);
this->Name = L"Form1";
this->Text = L"16FUSB Serial HID Sample App";
this->Load += gcnew System::EventHandler(this, &Form1::Form1_Load);
this->groupBox1->ResumeLayout(false);
this->groupBox1->PerformLayout();
this->groupBox2->ResumeLayout(false);
this->groupBox2->PerformLayout();
this->statusStrip1->ResumeLayout(false);
this->statusStrip1->PerformLayout();
this->ResumeLayout(false);
this->PerformLayout();
}
#pragma endregion
private: System::Void Form1_Load(System::Object^ sender, System::EventArgs^ e) {
if(this->toolStripStatuslabel1->Text == "") {
Application::Exit();
}
}
private: System::Void inputThread( Object^ sender, DoWorkEventArgs^ e ) {
unsigned char *inputReport;
while(true) {
char buf[] = "1";
char* orig = buf;
cout << orig << "(char *)" << endl;
inputReport = usb->readReport();
signed char temp = (signed char)inputReport[1];
buf[0] = temp;
String^ systemstring = gcnew String(orig);
Console::WriteLine("{0}", systemstring);
delete systemstring;
textBox2->AppendText(systemstring);
}
}
private: System::Void textBox1_KeyPress(Object^ sender, KeyPressEventArgs^ e) {
unsigned char outputReport[2];
outputReport[0] = 0;
outputReport[1] = Convert::ToInt32(e->KeyChar);
usb->writeReport(outputReport);
}
};
}
Emanuel Paz様の16FUSBを8ピンのPIC12F1822に実装しました。他の8ピンPICにも移植可能です。
Emanuel Paz様の16FUSBのページ
16FUSB - A USB 1.1 implementation for PIC16F628/628A
http://www.lendlocus.com/?q=16fusb#firmware
このページで紹介されているDirect I/O HIDでは8ピンの良さを生かしきれないので、
シリアルインターフェースを用いた双方向通信機能(擬似CDC)を実装しました。
概要
壱 )HIDレポートでキャラクタをやり取りします。エンドポイント1(IN/OUT)を使用
弐 )バルク転送できません
参 )工夫すれば通信条件をホスト側から変更できますが、現時点では対応してません
(現在の通信条件 9600bps 8bit ノーパリティ ストップ1bit フロー制御なし)
PICのRAMはバンク0 ($20~$7F) のみ使用
オリジナルのDirect I/O HIDは$A0 も使用


<シリアルホストプログラムでのループバックテスト>

下段に入力した文字をHIDレポートでPICに送信、
PICはこのデータをシリアル送信。
PICがシリアル受信すると、受信した文字をHIDレポートでホストに送信、上段に表示。
<ファームウエア>
16FUSBのページのFirmware以下にある
16FUSB-dio_hid-src-1.2.tar.gz
を展開してPIC12F1822用に書き換え、再コンパイル。
<HEXファイル PIC12F1822>(2013年2月24日 改定)
:020000040000FA
:0800000010308B0025290000DF
:08000800F000030EF1000810E6
:1000100088100C1908280C1D0B280408F2000C1D70
:100020000B282030840080010C1900148C1D4328FB
:100030000C1980148C1D43280C1900158C1D4328A5
:100040000C1980158C1D43280C1900168C1D432893
:100050000C1980168C1D43280C1900178C1D432881
:100060000C198017840A80010C1900148C1D432878
:100070000C1980148C1D43280C1900158C1D432865
:100080000C1980152428A0187B28201C7328201AFE
:100090006F287311210DA106A11F7315731D592817
:1000A000F31E6228F3123D3084004C08D0004B0848
:1000B0006528731F622873132D3084003C08D0001C
:1000C0003B0865285A30FD207328AC20731973282B
:1000D0007608F500F31D7328F40A731473282008BA
:1000E000CF002108D00072088400710E8300F00E4A
:1000F000700E8B1009007F3050057506031D7328A4
:10010000731C87284F1D08005A30FD207328D230F9
:10011000FD2020300402CE00DA004E08033A031915
:1001200073287314F314F3134F19F3177311500D4D
:10013000D006D01F73152030CF005B30D0004F08A1
:1001400084000008CD00500884004D088000CF0ACC
:10015000D00ACE0B9F287328033ECF000C1608143C
:10016000EB308C0508100730CD000310CF0DCF0DFC
:100170004F0D083E5007FF3C950000000000303056
:100180008B001430C328C4288C06CD0BC428C82883
:10019000C928001C8C060B19F028801C8C060B1932
:1001A000F028001D8C060B19F028801D8C060B19F9
:1001B000F028001E8C060B19F028801E8C060B19E7
:1001C000F028001F8C060B19F028801F8C06840A6B
:1001D0000000001C8C060B19F028801C8C06D1280E
:1001E000EB308C058B12F4281030F62800008C06BA
:1001F000081414308C0408100800CE000C160814E3
:10020000EB308C0508100730CD0014308C06CD0B78
:1002100006290A290B294E1C8C060E29CE1C8C0699
:1002200011294E1D8C061429CE1D8C0617294E1E31
:100230008C061A29CE1E8C061D294E1F8C062029DD
:06024000CE1F8C06F02821
:04024600003400344C
:06024A0096230814881041
:10025000C13095001C308C0408108810F3012A303E
:10026000F500F600C330BD008B178C1DD821AA23E2
:1002700008108810731C3529F3184721F31F96299D
:10028000C223F3183D29731073193529CC2908109E
:1002900088105A03EC005C30EA00F7015230EB00A2
:1002A0000130E90006305B1B0430EF0068100830B5
:1002B000EE006A0884000008DB006B088400083048
:1002C000ED00681C682968105B08E900DB0CED0391
:1002D0005B08E906E909691C7429EF0B7629DB0C38
:1002E000ED0B74296814ED0A0630EF00E90C800C60
:1002F0005B08E900EE0B8729F70A77085A02033AF0
:1003000003198D29EB0A6B0884000830EE00DB0C22
:10031000ED0B6829EA0AEC0B5929F310F31B0800CE
:10032000F401C330AD005808D10008006030520518
:10033000DB00D21FBC29A222DB080319A129552307
:10034000B5295308063A031DAA295508223A03196C
:100350005623B522D308031949235308083A031931
:100360004C2353080A3A03194F230810881003013D
:10037000F02103011A22D529DB080319C1295523CD
:10038000C5295308053A0319512308108810D108CC
:100390000319CE2973103529081088104B30AD0091
:1003A000AE01AF01BB01BC01F31173107317352906
:1003B000081088100330EC008C190800EC0BDC29C5
:1003C0002A30F500F600080008108810C330BD1D63
:1003D0004B30BD000130F02101301A22F316080025
:1003E000003A0319F7293E3084004B08FA292E30D1
:1003F00084003B08EB00FF30E900EA0000080B2214
:10040000840AEB0BFE29E90969088000840AEA09DD
:100410006A0880000800E9060830ED00EA0CEA13DB
:10042000E90C031C172AA030EA060130E906ED0B9F
:100430000E2A0800EF00003A0319232A3D308400F9
:10044000CC014B08272A2D308400BC013B08033E19
:10045000EB000430EE000008E9000830EC00013049
:100460006905013C031D362AEE03382A0630EE00EA
:10047000E90C03016E0203194322EC0B2F2A840AB4
:10048000EB0B2B2A08006F08031D482ABC0A492AD7
:10049000CC0A6B08ED00ED0A0408E8000008EA0049
:1004A000800D840AED0B502A680884000930E800AA
:1004B0006C08E80200106A180014E80B602A8A2A07
:1004C0008010EA188014E80B662A8C2A00116A1939
:1004D0000015E80B6C2A8E2A8011EA198015E80BAA
:1004E000722A902A00126A1A0016E80B782A922AB9
:1004F0008012EA1A8016E80B7E2A942A00136A1BDF
:100500000017E80B842A962A8013EA1B8017E80B51
:100510008A2A982A80109B2A00119B2A80119B2AE4
:1005200000129B2A80129B2A00139B2A80139B2A6D
:10053000840A001084030630EE0001306C02031DB3
:10054000EC03080008305102031CAD2AD10008302A
:10055000BB000319AF2AF315B02A5108BB00F311F1
:0A056000C330AD1D4B30AD000800A4
:06056A005508013A0319D7
:10057000BE2A5508023A0319E82A08007408013A0D
:100580000319D52A7408023A0319E42A1230AE007E
:100590000130AF001030B0000130B100FF30B200C8
:1005A000B301B4010830B5000800D830AE00043003
:1005B000AF002830B0000630B1000030B20001308A
:1005C000B300B401B5010800AE010130AF0008006E
:1005D0007408013A03190A2B7408023A0319182BFC
:1005E0007408053A0319462B7408043A0319352B8D
:1005F0007408033A0319252B0930AE000230AF000E
:100600002930B000B1010130B200B300B401803034
:10061000B50008003230AE000930AF000430B00041
:10062000B101B2010230B3000330B400B5010800DB
:10063000AE01AF010930B0002130B1001030B2007E
:100640000130B300B401B50008002230AE0019300B
:10065000AF00B0010730B1000530B2008130B30007
:100660000330B4000830B50008000030AE00083098
:10067000AF000730B0000530B1000130B2000330E8
:10068000B3000830B4000030B50008000830AE00F8
:100690000800AE01AF0108000130AE000800AE0155
:0A06A00008005E08F600F6130800DB
:0606AA0008007408013A8B
:1006B0000319732B7408023A0319822B7408033A46
:1006C0000319932B0630AE00A030AF00FF30B0000E
:1006D0000930B1000130B200A130B3000130B400E4
:1006E0000930B50008000330AE001530AF00B0018E
:1006F0002630B100FF30B200B3017530B4000830CD
:10070000B50008009530AE000130AF008130B00078
:100710000230B1000930B2000430B3009130B400AF
:0C0720000230B5000800C030AE00080038
:04072C000814881411
:100730008C0124309E0008309F0070309B000230F6
:100740009C0090309D008810FE308C0008108C01B9
:1007500098110800911E0800081488141D19BA2B5E
:100760009D18BD2B190808108810BE000130CB0061
:10077000E421080019089D1CBF2B1D121D1608102E
:0407800088100800D5
:0C078400731D08005208081488149E1C05
:0A079000C72B9A000810881008001B
:020000040001F9
:02000E00A7C980
:02001000FFDC13
:00000001FF
コンパイルにはatlstr.h互換ライブラリTString.h(JEX様作)を使用しています。
ダウンロード先
http://victreal.com/Junk/_T/index.html
コンパイル環境 Microsoft Visual Studio 10.0
16FUSBのページのDirect I/O HID Sample Application (win32)以下にある
16FUSB_dio_hid_sample_application_win32-src-1.0.zip
を展開、TString.hを追加し、Form1.hを書き換えて、再コンパイル。
プロジェクトファイルはそのまま使用。
<Form1.hのソース>
#pragma once
#include "stdio.h"
#include <wtypes.h>
#include <string>
#include "Usb.h"
#include <iostream>
#include <stdlib.h>
#include "TString.h"
namespace My16FUSB_HID_DioSampleAPP {
using namespace System;
using namespace System::ComponentModel;
using namespace System::Collections;
using namespace System::Windows::Forms;
using namespace System::Data;
using namespace std;
using namespace System::Drawing;
using namespace System::Threading;
/// <summary>
/// Summary for Form1
/// </summary>
public ref class Form1 : public System::Windows::Forms::Form
{
delegate void SetCheckDelegate();
public:
Form1(void)
{
InitializeComponent();
usb = gcnew Usb();
usb->VendorID = 0x04D8;
usb->ProductID = 0x0628;
if(usb->findDevice()) {
this->toolStripStatuslabel1->Text = "Device Connected";
usb->openReadHandle();
bgWorker = gcnew System::ComponentModel::BackgroundWorker();
bgWorker->DoWork += gcnew DoWorkEventHandler( this, &Form1::inputThread );
bgWorker->RunWorkerAsync();
usb->openWriteHandle();
} else {
System::Windows::Forms::MessageBox::Show( L"Device not found!", L"16FUSB",
System::Windows::Forms::MessageBoxButtons::OK);
}
}
protected:
/// <summary>
/// Clean up any resources being used.
/// </summary>
~Form1()
{
if (components)
{
delete components;
}
}
private: System::Windows::Forms::GroupBox^ groupBox1;
private: System::Windows::Forms::GroupBox^ groupBox2;
private: System::Windows::Forms::TextBox^ textBox1;
private: System::Windows::Forms::TextBox^ textBox2;
private: System::ComponentModel::IContainer^ components;
protected:
private:
/// <summary>
/// Required designer variable.
/// </summary>
private: System::Windows::Forms::StatusStrip^ statusStrip1;
private: System::Windows::Forms::ToolStripStatusLabel^ toolStripStatuslabel1;
System::ComponentModel::BackgroundWorker^ bgWorker;
Usb^ usb;
#pragma region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
void InitializeComponent(void)
{
this->groupBox1 = (gcnew System::Windows::Forms::GroupBox());
this->groupBox2 = (gcnew System::Windows::Forms::GroupBox());
this->textBox1 = (gcnew System::Windows::Forms::TextBox());
this->textBox2 = (gcnew System::Windows::Forms::TextBox());
this->statusStrip1 = (gcnew System::Windows::Forms::StatusStrip());
this->toolStripStatuslabel1 = (gcnew System::Windows::Forms::ToolStripStatusLabel());
this->groupBox1->SuspendLayout();
this->groupBox2->SuspendLayout();
this->statusStrip1->SuspendLayout();
this->SuspendLayout();
//
// groupBox1
//
this->groupBox1->Controls->Add(this->textBox1);
this->groupBox1->Location = System::Drawing::Point(30, 93);
this->groupBox1->Name = L"groupBox1";
this->groupBox1->Size = System::Drawing::Size(256, 73);
this->groupBox1->TabIndex = 1;
this->groupBox1->TabStop = false;
this->groupBox1->Text = L"Send to Serial";
//
// groupBox2
//
this->groupBox2->Controls->Add(this->textBox2);
this->groupBox2->Location = System::Drawing::Point(30, 13);
this->groupBox2->Name = L"groupBox2";
this->groupBox2->Size = System::Drawing::Size(256, 73);
this->groupBox2->TabIndex = 2;
this->groupBox2->TabStop = false;
this->groupBox2->Text = L"Recive from Serial";
//
// textBox1
//
this->textBox1->Location = System::Drawing::Point(18, 33);
this->textBox1->Multiline = true;
this->textBox1->Name = L"textBox1";
this->textBox1->Size = System::Drawing::Size(200, 30);
this->textBox1->TabIndex = 0;
this->textBox1->KeyPress += gcnew KeyPressEventHandler(this, &Form1::textBox1_KeyPress);
//
// textBox2
//
this->textBox2->Location = System::Drawing::Point(18, 33);
this->textBox2->Multiline = true;
this->textBox2->Name = L"textBox2";
this->textBox2->Size = System::Drawing::Size(200, 30);
this->textBox2->TabIndex = 0;
this->textBox2->ReadOnly = true;
//
// statusStrip1
//
this->statusStrip1->Items->AddRange(gcnew cli::array< System::Windows::Forms::ToolStripItem^ >(1) {this->toolStripStatuslabel1});
this->statusStrip1->Location = System::Drawing::Point(0, 197);
this->statusStrip1->Name = L"statusStrip1";
this->statusStrip1->Size = System::Drawing::Size(319, 22);
this->statusStrip1->TabIndex = 4;
this->statusStrip1->Text = L"statusStrip1";
//
// toolStripStatuslabel1
//
this->toolStripStatuslabel1->Name = L"toolStripStatuslabel1";
this->toolStripStatuslabel1->Size = System::Drawing::Size(0, 17);
//
// Form1
//
this->AutoScaleDimensions = System::Drawing::SizeF(6, 13);
this->AutoScaleMode = System::Windows::Forms::AutoScaleMode::Font;
this->ClientSize = System::Drawing::Size(319, 219);
this->Controls->Add(this->statusStrip1);
this->Controls->Add(this->groupBox2);
this->Controls->Add(this->groupBox1);
this->Name = L"Form1";
this->Text = L"16FUSB Serial HID Sample App";
this->Load += gcnew System::EventHandler(this, &Form1::Form1_Load);
this->groupBox1->ResumeLayout(false);
this->groupBox1->PerformLayout();
this->groupBox2->ResumeLayout(false);
this->groupBox2->PerformLayout();
this->statusStrip1->ResumeLayout(false);
this->statusStrip1->PerformLayout();
this->ResumeLayout(false);
this->PerformLayout();
}
#pragma endregion
private: System::Void Form1_Load(System::Object^ sender, System::EventArgs^ e) {
if(this->toolStripStatuslabel1->Text == "") {
Application::Exit();
}
}
private: System::Void inputThread( Object^ sender, DoWorkEventArgs^ e ) {
unsigned char *inputReport;
while(true) {
char buf[] = "1";
char* orig = buf;
cout << orig << "(char *)" << endl;
inputReport = usb->readReport();
signed char temp = (signed char)inputReport[1];
buf[0] = temp;
String^ systemstring = gcnew String(orig);
Console::WriteLine("{0}", systemstring);
delete systemstring;
textBox2->AppendText(systemstring);
}
}
private: System::Void textBox1_KeyPress(Object^ sender, KeyPressEventArgs^ e) {
unsigned char outputReport[2];
outputReport[0] = 0;
outputReport[1] = Convert::ToInt32(e->KeyChar);
usb->writeReport(outputReport);
}
};
}
.
- ご質問などはこちらからどうぞ
- ページ更新情報
- 最近嬉しかったこと
- 1kワードのTINYBASIC STM32L010F4
- やってくれたな!!店長よ
- 東大版TINYBASIC (STM32)
- 1kワードのTINYBASIC STM32版 その2
- 1kワードのTINYBASIC STM32版 その1
- 1kワードのTINYBASIC その8
- 1kワードのTINYBASIC その7
- 1kワードのTINYBASIC その6
- 1kワードのTINYBASIC その5
- 1kワードのTINYBASIC その4
- 1kワードのTINYBASIC その3
- 1kワードのTINYBASIC その2
- 1kワードのTINYBASIC その1
- 電大版TINYBASIC for PIC ミニマムお試し版5
- 電大版TINYBASIC for PIC ミニマムお試し版4
- 電大版TINYBASIC for PIC ミニマムお試し版3
- 電大版TINYBASIC for PIC ミニマムお試し版2
- 電大版TINYBASIC for PIC ミニマムお試し版
- PICで電大版TINYBASIC 実装編その5
- PICで電大版TINYBASIC 実装編その4
- PICで電大版TINYBASIC 実装編その3
- PICで電大版TINYBASIC 実装編その2
- PICで電大版TINYBASIC 実装編その1
- PICで電大版TINYBASIC 準備編その2
- PICで電大版TINYBASIC 準備編その1
- PIC18F24K42をPICKIT2で焼くTIPS その2
- PIC18F24K42をPICKIT2で焼くTIPS
- PIC16F18313ブートローダー書き込み器の製作
- PIC16F18857をPICKIT2で焼くその2
- PIC16F18857をPICKIT2で焼く
- PIC16F18313をPICKIT2で焼くその2
- PIC16F18313をPICKIT2で焼く
- PIC16F5XX USBIO
- HVT-BT200の予約制御
- 再考 PIC16F57 USBIO
- PIC16F5X USBIO
- 続12 8ピンPICでUSB PIC16F18313 HID-シリアルアダプター
- ucontrol.com.arに接続できない
- 続続 LPC1114 USBブートローダー
- 続PIC10F200 電子サイコロ
- PIC10F200 電子サイコロ
- LPC1114 8ch簡易ロジックアナライザー USB版
- 続 LPC1114 USBブートローダー
- LPC1114 8ch簡易ロジックアナライザー
- LPC1114 USBブートローダー
- LPC1114でUSB
- 続LPC810でUSB
- LPC810でUSB
- USB_NCO
- USB出力の周波数カウンター
- HIDアダプターについてのまとめ その2
- HIDアダプターについてのまとめ
- 極小ブートローダー まとめ
- 極小ブートローダー ATTiny 其の2
- 極小ブートローダー PIC10F322 其の6
- 極小ブートローダー PIC10F322 其の5
- 極小ブートローダー PIC10F322 其の4
- 極小ブートローダー PIC10F322 其の3
- 極小ブートローダー ATTiny13A
- 極小ブートローダー PIC10F322 其の2
- 極小ブートローダー PIC10F322
- 続11 8ピンPICでUSB PIC16F57_USBIO (その3)
- 続10 8ピンPICでUSB PIC16F505_USBIO (その2)
- 続9 8ピンPICでUSB PIC16F57_USBIO (その2)
- 続8 8ピンPICでUSB PIC16F505_USBIO
- 続7 8ピンPICでUSB PIC16F57_USBIO
- 続6 8ピンPICでUSB PIC16F570_USBIO
- 続5 8ピンPICでUSB PIC12F615_USBIO
- 続4 8ピンPICでUSB 16FUSBの改良版
- 続続続8ピンPICでUSB -30MHz+ソフトシリアル-
- 続続8ピンPICでUSB -16FUSBを30MHzで動かす-
- 続8ピンPICでUSB -ターミナルソフトからの操作-
- 8ピンPICでUSB -16FUSBの移植-
- 番外 MSP430 タイニーブートローダー
- 番外 C8051 タイニーブートローダー
- 続続続 Tiny AVR/PIC Bootloader+
- 続続 Tiny AVR/PIC Bootloader+
- 続 Tiny AVR/PIC Bootloader+
- Tiny AVR/PIC Bootloader+
- 番外 続ATTINY13A OSCCAL の簡易校正
- 番外 ATTINY13A OSCCAL の簡易校正
- 番外 続ATTINY13A ソフトシリアル
- 番外 ATTINY13A ソフトシリアル
- 番外 続Arduinoからタイニーブートローダーを使用する
- 番外 Arduinoからタイニーブートローダーを使用する
- 番外 LPC1114FN28/102 アセンブラサンプル
- 番外 LPC810 タイニーブートローダーの自己書き換え
- 番外 LPC810 EEPROM エミュレーション
- 番外 LPC810 タイニーブートローダー
- 番外 LPC810でアセンブラ
- 続続続PIC10F322 ソフトシリアル一考察
- 続続PIC10F322 ソフトシリアル一考察
- 続PIC10F322 ソフトシリアル一考察
- PIC10F322 ソフトシリアル一考察
- 84ワードのPICブートローダー
- 続PIC10F322 Ring-DDS
- Tinybldの自己更新プログラム
- プログラム領域をROMのように使う
- PIC10F322 256ビットプログラム発振器
- PIC18F EEPROM エミュレーション Jタイプ
- PIC18F EEPROM エミュレーション
- PIC16F EEPROM エミュレーション
- PIC10F322専用 周波数カウンター
- PIC18F Jタイプ ブートローダー
- PICの制約を取り除く
- 番外 ATTINY2313A用ブートローダー
- 続番外 ATTINY13A用ブートローダー
- 番外 ATTINY13A用ブートローダー
- 続PIC10F322 フラッシュメモリの操作
- PIC10F322 フラッシュメモリの操作
- PIC10F322 PIC_WAIT
- ビット列の並び替え その2
- ビット列の並び替え その1
- 故障した温水便座を使えるようにする
- PIC10F322 RA3を出力ポートとして使用
- PIC10F322 周波数カウンタ Part2
- PIC10F322 AN592準拠 周波数カウンタ
- PIC10F322 Ring-DDS
- microchipのAN592に関する一考察
- PIC10F322 3-ch リモコンライン切り替え器
- PIC10F322 4-SW リモコン送信器
- PIC10F322 二相発振器
- PIC_DELAY
- 続PIC_WAIT
- PIC_WAIT
- ご質問などはこちらからどうぞ
- ページ更新情報
- 最近嬉しかったこと
- 1kワードのTINYBASIC STM32L010F4
- やってくれたな!!店長よ
- 東大版TINYBASIC (STM32)
- 1kワードのTINYBASIC STM32版 その2
- 1kワードのTINYBASIC STM32版 その1
- 1kワードのTINYBASIC その8
- 1kワードのTINYBASIC その7
- 1kワードのTINYBASIC その6
- 1kワードのTINYBASIC その5
- 1kワードのTINYBASIC その4
- 1kワードのTINYBASIC その3
- 1kワードのTINYBASIC その2
- 1kワードのTINYBASIC その1
- 電大版TINYBASIC for PIC ミニマムお試し版5
- 電大版TINYBASIC for PIC ミニマムお試し版4
- 電大版TINYBASIC for PIC ミニマムお試し版3
- 電大版TINYBASIC for PIC ミニマムお試し版2
- 電大版TINYBASIC for PIC ミニマムお試し版
- PICで電大版TINYBASIC 実装編その5
- PICで電大版TINYBASIC 実装編その4
- PICで電大版TINYBASIC 実装編その3
- PICで電大版TINYBASIC 実装編その2
- PICで電大版TINYBASIC 実装編その1
- PICで電大版TINYBASIC 準備編その2
- PICで電大版TINYBASIC 準備編その1
- PIC18F24K42をPICKIT2で焼くTIPS その2
- PIC18F24K42をPICKIT2で焼くTIPS
- PIC16F18313ブートローダー書き込み器の製作
- PIC16F18857をPICKIT2で焼くその2
- PIC16F18857をPICKIT2で焼く
- PIC16F18313をPICKIT2で焼くその2
- PIC16F18313をPICKIT2で焼く
- PIC16F5XX USBIO
- HVT-BT200の予約制御
- 再考 PIC16F57 USBIO
- PIC16F5X USBIO
- 続12 8ピンPICでUSB PIC16F18313 HID-シリアルアダプター
- ucontrol.com.arに接続できない
- 続続 LPC1114 USBブートローダー
- 続PIC10F200 電子サイコロ
- PIC10F200 電子サイコロ
- LPC1114 8ch簡易ロジックアナライザー USB版
- 続 LPC1114 USBブートローダー
- LPC1114 8ch簡易ロジックアナライザー
- LPC1114 USBブートローダー
- LPC1114でUSB
- 続LPC810でUSB
- LPC810でUSB
- USB_NCO
- USB出力の周波数カウンター
- HIDアダプターについてのまとめ その2
- HIDアダプターについてのまとめ
- 極小ブートローダー まとめ
- 極小ブートローダー ATTiny 其の2
- 極小ブートローダー PIC10F322 其の6
- 極小ブートローダー PIC10F322 其の5
- 極小ブートローダー PIC10F322 其の4
- 極小ブートローダー PIC10F322 其の3
- 極小ブートローダー ATTiny13A
- 極小ブートローダー PIC10F322 其の2
- 極小ブートローダー PIC10F322
- 続11 8ピンPICでUSB PIC16F57_USBIO (その3)
- 続10 8ピンPICでUSB PIC16F505_USBIO (その2)
- 続9 8ピンPICでUSB PIC16F57_USBIO (その2)
- 続8 8ピンPICでUSB PIC16F505_USBIO
- 続7 8ピンPICでUSB PIC16F57_USBIO
- 続6 8ピンPICでUSB PIC16F570_USBIO
- 続5 8ピンPICでUSB PIC12F615_USBIO
- 続4 8ピンPICでUSB 16FUSBの改良版
- 続続続8ピンPICでUSB -30MHz+ソフトシリアル-
- 続続8ピンPICでUSB -16FUSBを30MHzで動かす-
- 続8ピンPICでUSB -ターミナルソフトからの操作-
- 8ピンPICでUSB -16FUSBの移植-
- 番外 MSP430 タイニーブートローダー
- 番外 C8051 タイニーブートローダー
- 続続続 Tiny AVR/PIC Bootloader+
- 続続 Tiny AVR/PIC Bootloader+
- 続 Tiny AVR/PIC Bootloader+
- Tiny AVR/PIC Bootloader+
- 番外 続ATTINY13A OSCCAL の簡易校正
- 番外 ATTINY13A OSCCAL の簡易校正
- 番外 続ATTINY13A ソフトシリアル
- 番外 ATTINY13A ソフトシリアル
- 番外 続Arduinoからタイニーブートローダーを使用する
- 番外 Arduinoからタイニーブートローダーを使用する
- 番外 LPC1114FN28/102 アセンブラサンプル
- 番外 LPC810 タイニーブートローダーの自己書き換え
- 番外 LPC810 EEPROM エミュレーション
- 番外 LPC810 タイニーブートローダー
- 番外 LPC810でアセンブラ
- 続続続PIC10F322 ソフトシリアル一考察
- 続続PIC10F322 ソフトシリアル一考察
- 続PIC10F322 ソフトシリアル一考察
- PIC10F322 ソフトシリアル一考察
- 84ワードのPICブートローダー
- 続PIC10F322 Ring-DDS
- Tinybldの自己更新プログラム
- プログラム領域をROMのように使う
- PIC10F322 256ビットプログラム発振器
- PIC18F EEPROM エミュレーション Jタイプ
- PIC18F EEPROM エミュレーション
- PIC16F EEPROM エミュレーション
- PIC10F322専用 周波数カウンター
- PIC18F Jタイプ ブートローダー
- PICの制約を取り除く
- 番外 ATTINY2313A用ブートローダー
- 続番外 ATTINY13A用ブートローダー
- 番外 ATTINY13A用ブートローダー
- 続PIC10F322 フラッシュメモリの操作
- PIC10F322 フラッシュメモリの操作
- PIC10F322 PIC_WAIT
- ビット列の並び替え その2
- ビット列の並び替え その1
- 故障した温水便座を使えるようにする
- PIC10F322 RA3を出力ポートとして使用
- PIC10F322 周波数カウンタ Part2
- PIC10F322 AN592準拠 周波数カウンタ
- PIC10F322 Ring-DDS
- microchipのAN592に関する一考察
- PIC10F322 3-ch リモコンライン切り替え器
- PIC10F322 4-SW リモコン送信器
- PIC10F322 二相発振器
- PIC_DELAY
- 続PIC_WAIT
- PIC_WAIT