制作 USB 设备,用 Java 控制它
我正在考虑制作一个带有旋钮、按钮和 LED 的物理控制器(设备?)。我想使用 Java 与其交互(响应旋钮、点亮 LED 等)。我提到 Java 有两个原因:首先,我很了解 Java1。其次,我已经用 Java 编写了需要交互的程序的其余部分(尽管有多种方法可以从另一种语言与 Java 程序进行交互)。
我希望该设备通过 USB 连接并且独立于(计算机)平台。
除了开始阅读 Arduino 网站之外,我完全不知道从哪里开始。 这是我最好/唯一的选择吗?是否有更适合与 Java 通信的东西?
注意:我知道 Arduino 与 Java 有关(不确定是什么),但似乎代码必须用 C 的子集编写。
我将如何继续讨论这个主题?
1 - 请不要笑。
I'm thinking about making a physical controller (device?) with knobs, buttons, and LEDs. I'd like to interact with it using Java (respond to the knobs, light up LEDs, etc). The reason I mention Java is two-fold: first, I know Java well1. Second, I've written the rest of the program I need to interface with in Java (though there are ways to talk to the Java program from another language).
I would like the device to connect via USB and be (computer-)platform independent.
I haven't the slightest idea of where to start, except to start reading the Arduino website. Is this my best/only option? Is there something better suited for communicating with Java?
Note: I know that Arduino has something to do with Java (not sure what), but it seems like code must be written in a subset of C.
How would I get moving on this topic?
1 - No laughter, please.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(6)
Arduino开发环境是用Java编写的。
但为 Arduino 平台编写程序的标准语言实际上是 C++。
Arduino 平台基于 Atmel AVR 芯片。至少有一个用于 AVR 芯片的 Java VM。 AVR 还有其他语言可用,例如 Forth 和 BASIC(虽然我只能找到商业版本,所以我如果您想找到它们,请搜索“AVR BASIC”)。
Arduino 使用虚拟 COM 端口在主机和它之间进行通信。虚拟 COM 端口模拟旧式串行线路,但通过 USB 完成。您可以使用 Java 通信 API 让运行在主机上的 Java 程序与您的物理设备。
The Arduino development environment is written in Java.
But the standard language you write a program for the Arduino platform is effectively C++.
The Arduino platform is based on an Atmel AVR chip. There is at least one Java VM for AVR chips. There are other languages available for the AVR such as Forth and BASIC (although I could only find commercial versions, so I'll if you want to find them, search for "AVR BASIC").
The Arduino uses a virtual COM port to communicate between the host computer and it. A virtual COM port emulates an old style serial line but is done with USB. You can use the Java communication API to then have a Java program running on the host computer communicate with your physical device.
对于某些编码器和按钮,您可能想要实现 USB HID 设备。如果您要生产多于几个,您将需要制作定制板。查看 V-USB,这是一个用于制作 USB HID 设备的开源库使用 Atmel 微控制器。他们有很多使用这个库的项目示例。
您可以使其看起来像一个 HID 操纵杆,使用编码器生成 X/Y 轴信息并使按钮像按钮一样工作。您可以使用标准 Java 游戏 API 来读取操纵杆值。
For some encoders and buttons, you probably want to implement a USB HID device. If you're going to produce more than a couple of them, you'll want to do a custom board. Check out V-USB, an open-source library for making USB HID devices using Atmel microcontrollers. They have a bunch of examples of projects that use this library.
You could probably make this look like a HID joystick, using the encoders to produce X/Y axis information and having the buttons act like buttons. They you could use standard Java gaming APIs to read the joystick values.
您可以扩展您对定制设备的需求吗?在我看来,设计硬件的进入门槛相当高,我能想到的大多数应用程序都可以通过重新利用现有的游戏控制器硬件来更好地解决。如果您确实需要新硬件,那么我建议您首先搜索“USB 开发套件”或
“USB 开发板”将为您提供诸如 此、此和这个。
至于从 Java 使用 USB 硬件,我已经尝试了一下 JUSB 库,它看起来很有前途,但似乎仅限于 Linux,因为该库的本机库一半的 Windows 版本尚未编写。可以通过谷歌搜索“HID java”找到替代方案。
Can you expand on your need for a custom device? It seems to me that designing hardware has a pretty high barrier to entry and that most applications I can think of would be better resolved by repurposing an existing piece of game controller hardware. If you really need new hardware, then i suggest you start by googling 'USB development kit' or
'USB development board' which will get you links like this, this and this.
As for working with USB hardware from Java, I've played around with the JUSB library a bit and it looks promising, but appears to be limited to Linux only because the Windows version of the native library half of the library hasn't been written. Alternatives can by found by googling 'HID java'.
好的,独立于计算机平台吗?您的目标平台是什么?这取决于该平台的驱动程序和支持,USB 设备有什么作用?它是大容量存储设备吗...您可能需要环顾四周,看看是否可以找到可以与设备通信的设备驱动程序...
希望这有帮助,
此致,
汤姆.
Ok, computer-platform independant? What platforms are you targetting? That would depend on the driver and support for that said platform, what does the usb device do? Is it a mass storage device...You may have to look around and see if you can find a device driver that can talk to the device...
Hope this helps,
Best regards,
Tom.
我知道对于串行端口,存在与其交互的库(rs232 库)。谷歌搜索 java 和 USB 返回了几个答案(第一个称为 jUSB)。这将是我要寻找的第一类东西。
I know for the serial port there were libraries that existed for interacting with it (rs232 library). Googling for java and USB returned several answers (the first was called jUSB). That would be the first type of thing I would be looking for.
java usb 连接到飞思卡尔微控制器的示例:
http://javausbapi.blogspot.com/
sample for java usb connection to freescale microcontroller:
http://javausbapi.blogspot.com/