Send data to arduino from PC in java over Serial (RXTXlib)


hi everyone,
i intending parse excel file in pc , send data arduino.
as  a beginning i'm trying send 1 character "1" , when arduino receives "1" turns on led 13.
my problem java program sends data arduino , can see rx tx leds blinking led 13 doesn't turn on told arduino. suppose arduino receives char "1" doesn't understand it. there format/type problem.
here java part sends char s string converted bytes sent arduino :
code: [select]
public static void main(string[] args) throws ioexception, portinuseexception, nosuchportexception{
       serialporthandler serial = new serialporthandler();
       serial.connect("com2");
       outputstream serialout = serial.getserialoutputstream();
       string s = "1";
       serialout.write(s.getbytes());
serialout.flush();
serial.disconnect();
}

and here arduino code works fine on serial monitor.
code: [select]

char byteread;
int led = 13 ;
void setup() {
     serial.begin(9600);
     pinmode(led, output);          
}
void loop() {
    if (serial.available()) {
           delay(100);
           while (serial.available()){
               byteread = serial.read();
               if (byteread == '1'){
                  digitalwrite(led, high);
               }
            }
         }
        delay(1000);
}

i tried data in int , used serial.parseint , nothing worked.
help please  :~

it's idea find out if happening before using if tests depend on data.

can add java program (or write short new program) can act serial monitor show data received arduino? arduino program echo every character receives. way can see communication doing.

i don't java use jruby on linux pc. wrote program communicate between pc , arduino in this thread. main example in python in 1 of posts included jruby code - written before python code.

as far can see rxtx seems have disappeared web , jssc current equivalent.

...r


Arduino Forum > Using Arduino > Interfacing w/ Software on the Computer > Send data to arduino from PC in java over Serial (RXTXlib)


arduino

Comments

Popular posts from this blog

opencv3, tbb and rasp pi 2 - Raspberry Pi Forums

small ethernet problem - Raspberry Pi Forums

Multithumb configuration params not working? - Joomla! Forum - community, help and support