如何将微控制器连接到USB [英] How do I interface a microcontroller to USB

查看:96
本文介绍了如何将微控制器连接到USB的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述





我想用另一个微控制器或USB接口卡通过USB将微控制器连接到电脑。我还想在PC上创建一个GUI,以便用户能够通过单击GUI上的按钮进行读/写。如果可能的话,我还想将读取的数据存储在一个文件中以便以后读取。



我是编程新手,我只有编程Microchip的经验微控制器在使用IDE之前提供。这是我第一次使用Visual Studio。



我尝试过:



我尝试过使用Visual Studio,并创建了一个CLR空项目来创建一个Windows窗体应用程序。我可以选择使用Velleman K8055与USB接口,但是当我尝试添加.dll作为引用时,Visual Studio不允许这样做。

Hi,

I want to interface a microcontroller to a computer via USB using another microcontroller or USB interface card. I would also like to create a GUI on the PC for the user to be able to read/write with a button click on the GUI. If possible, I also want to store the read data in a file to be readable at a later time.

I am new to programming, I only had experience programming Microchip microcontroller before using the IDE provided. And this is my first time using Visual Studio.

What I have tried:

I have tried using Visual Studio, and created a CLR empty project to create a windows form application. I had an option to use the Velleman K8055 to interface with USB, however when I tried to add in its .dll as the references, The Visual Studio does not allow that.

推荐答案

引用:

我可以选择使用Velleman K8055与USB接口,但是当我尝试将其.dll添加为Visual Studio不允许这样做。

I had an option to use the Velleman K8055 to interface with USB, however when I tried to add in its .dll as the references, The Visual Studio does not allow that.

这可能是因为它不是.NET程序集 - 并非所有的DLL文件都有,有​​些是Native Code,这意味着你可以直接使用它们,你必须使用它们DLL导入并使用它们包含的函数。这变得很复杂 - 我不能说多么复杂,我不知道DLL是如何工作的或它预期的 - 但是对于初学者来说,他们是一个痛苦的世界!



我们无法告诉您如何连接它 - 我们不知道链接的另一端希望您发送什么,或者它将回复什么(大多数系统不仅发送数据 - 他们希望来自USB主机PC的命令可以询问他们是否有任何东西)这样就会让你失望。

我从一些简单的东西开始并使用Hyperterminal或类似的确定在我开始编码之前我可以可靠地与设备通信,否则你就是在追逐可能是硬件,驱动程序或软件的问题,而不知道它们的来源。一旦有效,我会尝试使用 SerialPort类(System.IO.Ports) [ ^ ]尝试建立我的应用程序和设备之间的基本通信,然后才真正介绍外部DLL到等式。



如果您想使用外部DLL并且Valleman看起来像您需要的,请查看它们是否包含.NET版本,或者至少可以帮助您构建(和使用)您需要的DllImport语句访问它。如果没有,找到另一个兼容.NET的东西,因为它会让你的生活变得更轻松!

That's probably because it's not a .NET Assembly - not all DLL files are, some are Native Code which means that you can;t use them directly, you have to use DLL Import and work with the functions they contain that way. That gets complex - how complex I can't say, I have no idea how the DLL works or what it expects - but the chances are that for a beginner they are a world of pain!

We can't tell you how to interface it - we have no idea what the other end of the link expects you to send, or what it will reply with (most systems don't "just send" data - they expect a command from the USB host PC to ask them if they have anything) so that bit is going to be down to you.
I'd start with something simple and use Hyperterminal or similar to establish that I could talk to the device reliably before I even began to code anything as otherwise you are you chasing problems that may be hardware, driver, or your software, with no idea of where they originate. Once that's working, I'd try using the SerialPort Class (System.IO.Ports)[^] to try and establish basic communicatiosn between my app and the device before I really though about introdiucing external DLLs to the equation.

If you want to use an external DLL and Valleman looks like what you need, see if they include a .NET version, or at least can help you build (and use) the DllImport statements you need to access it. If not, find another that is .NET compatible as it will make your life a whole lot easier!


这篇关于如何将微控制器连接到USB的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆