testusb hinzugefügt
This commit is contained in:
commit
872ecdcdcf
20
TestUsb.sln
Normal file
20
TestUsb.sln
Normal file
@ -0,0 +1,20 @@
|
||||
|
||||
Microsoft Visual Studio Solution File, Format Version 12.00
|
||||
# Visual Studio 2012
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TestUsb", "TestUsb\TestUsb.csproj", "{90E06CAE-E0B8-4033-8730-1C6506E59CD2}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
Debug|Any CPU = Debug|Any CPU
|
||||
Release|Any CPU = Release|Any CPU
|
||||
EndGlobalSection
|
||||
GlobalSection(ProjectConfigurationPlatforms) = postSolution
|
||||
{90E06CAE-E0B8-4033-8730-1C6506E59CD2}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{90E06CAE-E0B8-4033-8730-1C6506E59CD2}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{90E06CAE-E0B8-4033-8730-1C6506E59CD2}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{90E06CAE-E0B8-4033-8730-1C6506E59CD2}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
EndGlobalSection
|
||||
GlobalSection(SolutionProperties) = preSolution
|
||||
HideSolutionNode = FALSE
|
||||
EndGlobalSection
|
||||
EndGlobal
|
6
TestUsb/App.config
Normal file
6
TestUsb/App.config
Normal file
@ -0,0 +1,6 @@
|
||||
<?xml version="1.0" encoding="utf-8" ?>
|
||||
<configuration>
|
||||
<startup>
|
||||
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5" />
|
||||
</startup>
|
||||
</configuration>
|
105
TestUsb/Program.cs
Normal file
105
TestUsb/Program.cs
Normal file
@ -0,0 +1,105 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using LibUsbDotNet;
|
||||
using LibUsbDotNet.Main;
|
||||
|
||||
namespace TestUsb
|
||||
{
|
||||
class Program
|
||||
{
|
||||
public static UsbDeviceFinder MyUsbFinder = new UsbDeviceFinder(0xDEAD, 0xBEEE);
|
||||
public static UsbDevice MyUsbDevice;
|
||||
public static UsbEndpointReader reader;
|
||||
public static UsbEndpointWriter writer;
|
||||
|
||||
|
||||
static void Main(string[] args)
|
||||
{
|
||||
if (connect())
|
||||
{
|
||||
config();
|
||||
while (true)
|
||||
{
|
||||
read();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static String send = "";
|
||||
|
||||
private static void read()
|
||||
{
|
||||
ErrorCode ec = ErrorCode.None;
|
||||
|
||||
if (Console.KeyAvailable)
|
||||
{
|
||||
ConsoleKeyInfo k = Console.ReadKey(true);
|
||||
if (k.Key == ConsoleKey.Enter)
|
||||
{
|
||||
send += "\r\n";
|
||||
int bytesWritten;
|
||||
ec = writer.Write(Encoding.Default.GetBytes(send), 2000, out bytesWritten);
|
||||
Console.WriteLine("OUT: (" + bytesWritten + ") " + send);
|
||||
send = "";
|
||||
}
|
||||
else
|
||||
{
|
||||
send += k.KeyChar;
|
||||
}
|
||||
}
|
||||
|
||||
byte[] readBuffer = new byte[1024];
|
||||
int bytesRead;
|
||||
ec = reader.Read(readBuffer, 100, out bytesRead);
|
||||
|
||||
if (bytesRead != 0)
|
||||
{
|
||||
// Write that output to the console.
|
||||
Console.Write("IN: (" + bytesRead + ") "+Encoding.Default.GetString(readBuffer, 0, bytesRead));
|
||||
}
|
||||
if (ec != ErrorCode.None && ec != ErrorCode.IoTimedOut)
|
||||
{
|
||||
//throw new Exception(ec.ToString());
|
||||
if (connect())
|
||||
{
|
||||
config();
|
||||
}
|
||||
System.Threading.Thread.Sleep(1000);
|
||||
}
|
||||
}
|
||||
|
||||
private static void config()
|
||||
{
|
||||
IUsbDevice wholeUsbDevice = MyUsbDevice as IUsbDevice;
|
||||
if (!ReferenceEquals(wholeUsbDevice, null))
|
||||
{
|
||||
// This is a "whole" USB device. Before it can be used,
|
||||
// the desired configuration and interface must be selected.
|
||||
|
||||
// Select config #1
|
||||
wholeUsbDevice.SetConfiguration(1);
|
||||
|
||||
// Claim interface #0.
|
||||
wholeUsbDevice.ClaimInterface(0);
|
||||
}
|
||||
|
||||
// open read endpoint 1.
|
||||
reader = MyUsbDevice.OpenEndpointReader(ReadEndpointID.Ep02);
|
||||
|
||||
// open write endpoint 1.
|
||||
writer = MyUsbDevice.OpenEndpointWriter(WriteEndpointID.Ep01);
|
||||
|
||||
}
|
||||
|
||||
private static bool connect()
|
||||
{
|
||||
MyUsbDevice = UsbDevice.OpenUsbDevice(MyUsbFinder);
|
||||
if (MyUsbDevice == null)
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
36
TestUsb/Properties/AssemblyInfo.cs
Normal file
36
TestUsb/Properties/AssemblyInfo.cs
Normal file
@ -0,0 +1,36 @@
|
||||
using System.Reflection;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
// Allgemeine Informationen über eine Assembly werden über die folgenden
|
||||
// Attribute gesteuert. Ändern Sie diese Attributwerte, um die Informationen zu ändern,
|
||||
// die mit einer Assembly verknüpft sind.
|
||||
[assembly: AssemblyTitle("TestUsb")]
|
||||
[assembly: AssemblyDescription("")]
|
||||
[assembly: AssemblyConfiguration("")]
|
||||
[assembly: AssemblyCompany("")]
|
||||
[assembly: AssemblyProduct("TestUsb")]
|
||||
[assembly: AssemblyCopyright("Copyright © 2013")]
|
||||
[assembly: AssemblyTrademark("")]
|
||||
[assembly: AssemblyCulture("")]
|
||||
|
||||
// Durch Festlegen von ComVisible auf "false" werden die Typen in dieser Assembly unsichtbar
|
||||
// für COM-Komponenten. Wenn Sie auf einen Typ in dieser Assembly von
|
||||
// COM zugreifen müssen, legen Sie das ComVisible-Attribut für diesen Typ auf "true" fest.
|
||||
[assembly: ComVisible(false)]
|
||||
|
||||
// Die folgende GUID bestimmt die ID der Typbibliothek, wenn dieses Projekt für COM verfügbar gemacht wird
|
||||
[assembly: Guid("3203f19b-27cf-4084-923b-b5dd68ccbeae")]
|
||||
|
||||
// Versionsinformationen für eine Assembly bestehen aus den folgenden vier Werten:
|
||||
//
|
||||
// Hauptversion
|
||||
// Nebenversion
|
||||
// Buildnummer
|
||||
// Revision
|
||||
//
|
||||
// Sie können alle Werte angeben oder die standardmäßigen Build- und Revisionsnummern
|
||||
// übernehmen, indem Sie "*" eingeben:
|
||||
// [assembly: AssemblyVersion("1.0.*")]
|
||||
[assembly: AssemblyVersion("1.0.0.0")]
|
||||
[assembly: AssemblyFileVersion("1.0.0.0")]
|
61
TestUsb/TestUsb.csproj
Normal file
61
TestUsb/TestUsb.csproj
Normal file
@ -0,0 +1,61 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
|
||||
<PropertyGroup>
|
||||
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
|
||||
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
|
||||
<ProjectGuid>{90E06CAE-E0B8-4033-8730-1C6506E59CD2}</ProjectGuid>
|
||||
<OutputType>Exe</OutputType>
|
||||
<AppDesignerFolder>Properties</AppDesignerFolder>
|
||||
<RootNamespace>TestUsb</RootNamespace>
|
||||
<AssemblyName>TestUsb</AssemblyName>
|
||||
<TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
|
||||
<FileAlignment>512</FileAlignment>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
|
||||
<PlatformTarget>AnyCPU</PlatformTarget>
|
||||
<DebugSymbols>true</DebugSymbols>
|
||||
<DebugType>full</DebugType>
|
||||
<Optimize>false</Optimize>
|
||||
<OutputPath>bin\Debug\</OutputPath>
|
||||
<DefineConstants>DEBUG;TRACE</DefineConstants>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
|
||||
<PlatformTarget>AnyCPU</PlatformTarget>
|
||||
<DebugType>pdbonly</DebugType>
|
||||
<Optimize>true</Optimize>
|
||||
<OutputPath>bin\Release\</OutputPath>
|
||||
<DefineConstants>TRACE</DefineConstants>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<Reference Include="LibUsbDotNet">
|
||||
<HintPath>E:\Programme\LibUsbDotNet\LibUsbDotNet.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="System" />
|
||||
<Reference Include="System.Core" />
|
||||
<Reference Include="System.Xml.Linq" />
|
||||
<Reference Include="System.Data.DataSetExtensions" />
|
||||
<Reference Include="Microsoft.CSharp" />
|
||||
<Reference Include="System.Data" />
|
||||
<Reference Include="System.Xml" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="Program.cs" />
|
||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<None Include="App.config" />
|
||||
</ItemGroup>
|
||||
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
|
||||
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
|
||||
Other similar extension points exist, see Microsoft.Common.targets.
|
||||
<Target Name="BeforeBuild">
|
||||
</Target>
|
||||
<Target Name="AfterBuild">
|
||||
</Target>
|
||||
-->
|
||||
</Project>
|
Loading…
Reference in New Issue
Block a user