java - Need assistance in SerialEvent() method -
this method , want variable info method utilize in one.
public synchronized void serialevent(serialportevent oevent) { if (oevent.geteventtype() == serialportevent.data_available) { seek { int available = input.available(); byte chunk[] = new byte[available]; input.read(chunk, 0, available); // displayed results codepage dependent info =new string(chunk); } grab (exception e) { system.err.println(e.tostring()); } } }
it depend on trying achieve, simplest way phone call other method (say name processdata ) straight serialevent , pass info received com port e.g. processdata(new string(chunk));
the problem approach if method processdata doing heavy block serialevent.
alternative approach have separate thread process data, can communicate implementation of concurrent.blockingqueue. within serialevent force info queue , go on without waiting processdata finish.
just search producer/consumer pattern blockingqueue , find plenty of code examples.
java methods serial-port
No comments:
Post a Comment