Comments (3)
By default jSSC use TIOCEXCL for exclusive access to serial port resource, in
this case you can't open same port twice (except root, or you can disable
TIOCEXCL by setting JSSC_NO_TIOCEXCL JVM property). But it's really bad
practice, you can not get the same data from one serial port by using 2 new
SerialPort objects. If one object read data from serial port buffer readed data
is purged from buffer.
You should create some serial port provider for reading data, and providing it
to any ViewPart you need.
Original comment by [email protected]
on 30 Aug 2013 at 4:49
from java-simple-serial-connector.
Hi Alexey,
Thanks for confirming that. Below is the initial draft of the potential
provider that it might help others with similar case scenario.
Thanks again for such wonderful API!
----------------------------------
import java.util.ArrayList;
import java.util.List;
import jssc.SerialPort;
import jssc.SerialPortEvent;
import jssc.SerialPortEventListener;
import jssc.SerialPortException;
public class SerialConnectionProvider {
private static final SerialConnectionProvider INSTANCE = new SerialConnectionProvider();
private static List<SerialPortEventListener> consumerListeners;
private static SerialPort serialPort;
private SerialConnectionProvider() {
consumerListeners = new ArrayList<SerialPortEventListener>();
}
public static SerialConnectionProvider getInstance(String port, SerialPortEventListener consumerListener) throws SerialPortException {
if (serialPort == null) {
serialPort = new SerialPort(port);
serialPort.openPort();
serialPort.setParams(SerialPort.BAUDRATE_9600, SerialPort.DATABITS_8, SerialPort.STOPBITS_1, SerialPort.PARITY_NONE);
serialPort.setEventsMask(SerialPort.MASK_RXCHAR);
serialPort.addEventListener(new SerialPortListener());
}
consumerListeners.add(consumerListener);
return SerialConnectionProvider.INSTANCE;
}
static class SerialPortListener implements SerialPortEventListener {
public void serialEvent(SerialPortEvent event) {
if (event.isRXCHAR() && event.getEventValue() > 10) {
for (SerialPortEventListener listener : consumerListeners) {
listener.serialEvent(event);
}
}
}
}
public synchronized boolean disconnect(SerialPortEventListener listener) throws SerialPortException {
boolean result = true;
if (serialPort.isOpened() && consumerListeners.size() == 1) {
result = serialPort.closePort();
}
consumerListeners.remove(listener);
return result;
}
public SerialPort getSerialPort() {
return serialPort;
}
}
Original comment by [email protected]
on 30 Aug 2013 at 5:18
from java-simple-serial-connector.
Original comment by [email protected]
on 12 Sep 2014 at 2:31
- Changed state: Done
from java-simple-serial-connector.
Related Issues (20)
- From 2nd time onwards weight reading not working in linux
- Hundreds of wakeups per second wastes lots of power on small host system even with idle port (no datat flow)
- SerialPort should allow for method that return Inpu/Outputstream HOT 1
- Raspberry Pi serial over usb adapter reads data only once (Watchport/H sensor) using jssc 2.8.0.0
- Two java application is opening the same port
- Always port busy on 32 bit system
- EventThread is never terminated
- Ubuntu return an empty serial list HOT 2
- readBytes() wrong when get second message
- jssc stops working after a while on windows 7 HOT 1
- Driver won't work with real COM1 port
- High CPU load using jssc HOT 1
- SerialPortTimeoutException trown while result shows it returned correct value and amount of bytes HOT 1
- Unable to load on Minibian, Raspberry Pi 1 B HOT 3
- JVM terminates with signal 6 (abort) after several hours of use
- Stuck on waitEvents() method forever when no data is available
- Set Timeout and Port disconnect throw exception HOT 1
- Trouble getting reader to return text using readByte() HOT 1
- SerialPortEventListener returns invalid type
- In Windows 10 SOMETIMES (casually 2 or 3 times on 5) receive signal is NOT raised
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from java-simple-serial-connector.