read string sent from java from serial port in arduino
hi, i'm trying send string code in java. know works cause monitorized virtual serial port , says writes bytes send. use port com5 1 im using in arduino.
the code in arduino this. try print see if works , receiving correctly, doesn't enter in if because doesn't detect data received (sorry english, hope understandable).
i put delay can see com monitor in arduino in time, because have have closed while run java app.
hope can cause i'm stuck in this. thank you
code: [select]
import java.io.*;
import java.util.*;
import gnu.io.*;
public class simplewrite {
static enumeration portlist;
static commportidentifier portid;
static string messagestring = "color ff00ffend";
static serialport serialport;
static outputstream outputstream;
public static void main(string[] args) {
portlist = commportidentifier.getportidentifiers();
while (portlist.hasmoreelements()) {
portid = (commportidentifier) portlist.nextelement();
if (portid.getporttype() == commportidentifier.port_serial) {
if (portid.getname().equals("com5")) {
try {
serialport = (serialport)
portid.open("simplewriteapp", 2000);
} catch (portinuseexception e) {system.out.println("err");}
try {
serialport.setserialportparams(9600,
serialport.databits_8,
serialport.stopbits_1,
serialport.parity_none);
serialport.setflowcontrolmode(
serialport.flowcontrol_none);
} catch (unsupportedcommoperationexception e) {system.out.println("err2");}
try {
outputstream = serialport.getoutputstream();
} catch (ioexception e) {system.out.println("err1");}
try {
outputstream.write(messagestring.getbytes());
system.out.println(messagestring);
//outputstream.close();
//serialport.close();
} catch (ioexception e) {system.out.println("err3");}
}
}
}
}
}
the code in arduino this. try print see if works , receiving correctly, doesn't enter in if because doesn't detect data received (sorry english, hope understandable).
i put delay can see com monitor in arduino in time, because have have closed while run java app.
code: [select]
void setup() {
rb.init();
// initialize digital pin output.
serial.begin(9600);
}
// loop routine runs on , on again forever:
void loop() {
while (true)
{
if (serial.available() > 0) {
serial.readbytes(inputbuffer, serial.available());
delay(15000);
serial.print("i got ->");
serial.print(inputbuffer);
serial.println("<-");
}
}
}
hope can cause i'm stuck in this. thank you
please post code.
all of it.
all of it.
Arduino Forum > Using Arduino > Programming Questions > read string sent from java from serial port in arduino
arduino
Comments
Post a Comment