Thursday, July 19, 2012

Arduino talks to Java over Serial Interface



Arduino talks to Java over Serial Interface
  1. Install arduino as per normal
  2. Check that the *.dll exist in this path
    Drive:\folder\arduino-00VER\
    rxtxSerial.dll
    Check that the *.jar file exisit in this path
    Drive:\folder\arduino-0022\arduino-0022\lib\
    RXTXcomm.jar
  3. Create run.bat with the following data in this format, modify the parameters to suit your computer’s path.
    This will use javac to compile java and execute from CMD.

    @set path=%path%;C:\Program Files\Java\jdk1.6.0_25\bin
@D:\Users\s41764\Desktop\Documents\Downloads\arduino-0022\arduino-0022
setlocal
set PATH=%PATH%;D:\Users\s41764\Desktop\Documents\Downloads\arduino-0022\arduino-0022\
"C:\Program Files\Java\jdk1.6.0_25\bin\javac" -cp "D:\Users\s41764\Desktop\Documents\Downloads\arduino-0022\arduino-0022\lib\RXTXcomm.jar" SerialTest.java
"C:\Program Files\Java\jdk1.6.0_25\bin\java" -cp "D:\Users\s41764\Desktop\Documents\Downloads\arduino-0022\arduino-0022\lib\RXTXcomm.jar;." SerialTest

  1. Upon successful compilation by javac, the program will run and display the string send by arduino.
  2. To detect the specific character sequence and associated code handling in java, use api call String.compareTo(). Note that the serial receive is not fix number of bytes. Hence, a buffer is required to store the intended message from arduino, and then to do a string comparison.





Running the default code from
http://www.arduino.cc/playground/Interfacing/Java
Need to change port number in java code to reflect the arduino

check out the modified code here

1 comment:

Ashley Rosa said...

Is EOS listed in Binance? What is the role of EOS in Binance? Is EOS genuine? All such questions sometimes block the mind of users. To know the role and usage of EOS in Binance, you can call on Binance phone number and get in touch with the elite professionals for utmost assistance. The experts will guide each and every solution in plain-sailing manner so that you understand everything easily without any trouble. The well-skilled and talented experts will deliver quality-oriented solutions and guidance so that users don’t face any error in future.