[英]Sending data from Arduino to Java Program via Bluetooth
I am working on a project where I am trying to get information from an Arduino Pro Mini to a Java Program on my computer via Bluetooth. 我正在一个项目中尝试通过蓝牙将Arduino Pro Mini的信息获取到计算机上的Java程序。
I have the Arduino end working, and I am able to connect to the bluetooth module on the Arduino with my computer and get the data to be printed out with CoolTerm. 我的Arduino端正常工作,并且可以使用计算机连接到Arduino上的蓝牙模块,并使用CoolTerm将数据打印出来。
My problem is getting the Java Program to read from the bluetooth connection that my computer has with the bluetooth module on the Arduino Pro Mini. 我的问题是让Java程序从我的计算机与Arduino Pro Mini上的蓝牙模块之间的蓝牙连接读取。
I have only been able to find solutions when developing an Android App. 开发Android应用程序时,我只能找到解决方案。 THIS IS NOT AN ANDROID PROJECT, I do not want android solutions.
这不是ANDROID项目,我不需要android解决方案。
Does anyone have an example of how to utilize a bluetooth connection on your computer with a Java Program (not android) so that I can read the information, the Arduino Pro Mini is sending to my computer, through my java program? 有没有人举过一个例子,说明如何通过Java程序(不是android)在计算机上利用蓝牙连接,以便我可以通过Arduino Pro Mini通过我的java程序读取信息,从而可以读取信息?
I've used nrjavaserial in my code. 我在代码中使用了nrjavaserial 。 I'm running on Linux with a little USB Bluetooth adapter and it has worked well.
我在Linux上带有一个小型USB蓝牙适配器,并且运行良好。 In your code you'll do something like:
在您的代码中,您将执行以下操作:
NRSerialPort serial = new NRSerialPort("/dev/rfcomm0", 115200);
serial.connect();
DataInputStream ins = new DataInputStream(serial.getInputStream());
The hard part is the device name. 困难的部分是设备名称。 Ubuntu has a nice Bluetooth setup where I can pair and connect the device to a serial port.
Ubuntu有一个不错的蓝牙设置,我可以在其中配对设备并将其连接到串行端口。 I've not done this on other O/S's though.
我还没有在其他操作系统上执行此操作。
Note that nrjavaserial includes native libraries that use JNI under the covers. 请注意,nrjavaserial包括在幕后使用JNI的本机库。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.