@PostConstruct
public void connect() throws TooManyListenersException, NoSuchPortException {
log.info("Connection PostConstruct callback: connecting ...");
serial = new NRSerialPort(serialPortProperties.getPortName(), serialPortProperties.getBaudRate());
serial.connect();
if (serial.isConnected()) {
log.info("Connection opened!");
} else {
throw new RuntimeException("Is not possible to open connection in " + serialPortProperties.getPortName() + " port");
}
serial.addEventListener(this);
serial.notifyOnDataAvailable(true);
input = new BufferedReader(new InputStreamReader(serial.getInputStream()));
}
java类gnu.io.NRSerialPort的实例源码
AbstractSpringSerialPortConnector.java 文件源码
项目:spring-serial-port-connector
阅读 22
收藏 0
点赞 0
评论 0
LgTvSerialHandler.java 文件源码
项目:openhab2-addons
阅读 21
收藏 0
点赞 0
评论 0
@Override
public void initialize() {
portName = (String) getThing().getConfiguration().get("port");
if (portName != null) {
serialPort = new NRSerialPort(portName, BAUD);
if (serialPort.connect()) {
updateStatus(ThingStatus.ONLINE);
output = new OutputStreamWriter(serialPort.getOutputStream());
} else {
updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.COMMUNICATION_ERROR,
"Failed to connect to serial port " + portName);
logger.debug("Failed to connect to serial port {}", portName);
}
} else {
updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.CONFIGURATION_ERROR, "Serial port name not configured");
logger.debug("Serial port name not configured");
}
}
SerialAvrConnection.java 文件源码
项目:openhab2-addons
阅读 22
收藏 0
点赞 0
评论 0
@Override
protected void openConnection() throws IOException {
if (isPortNameExist(portName)) {
serialPort = new NRSerialPort(portName, LINK_SPEED);
boolean isConnected = serialPort.connect();
if (!isConnected) {
throw new IOException("Failed to connect on port " + portName);
}
logger.debug("Connected to {}", getConnectionName());
} else {
throw new IOException("Serial port with name " + portName + " does not exist. Available port names: "
+ NRSerialPort.getAvailableSerialPorts());
}
}
BenqProjectorSerialTransport.java 文件源码
项目:openhab1-addons
阅读 22
收藏 0
点赞 0
评论 0
private boolean serialConnect() {
logger.debug("Running connection setup");
try {
logger.debug("Setting up socket connection to " + this.serialDevice);
this.serialPort = new NRSerialPort(this.serialDevice, this.serialSpeed);
this.serialPort.connect();
this.projectorReader = new BufferedReader(new InputStreamReader(this.serialPort.getInputStream()));
this.projectorWriter = new PrintWriter(this.serialPort.getOutputStream(), true);
logger.debug("Serial connection setup successfully!");
return true;
} catch (Exception e) {
logger.error("Unable to connect to device: " + this.serialDevice, e);
}
return false;
}
SerialRegoConnection.java 文件源码
项目:openhab2-addons
阅读 23
收藏 0
点赞 0
评论 0
@Override
public void connect() throws IOException {
if (isPortNameExist(portName)) {
serialPort = new NRSerialPort(portName, baudRate);
if (serialPort.connect() == false) {
throw new IOException("Failed to connect on port " + portName);
}
logger.debug("Connected to {}", portName);
} else {
throw new IOException("Serial port with name " + portName + " does not exist. Available port names: "
+ NRSerialPort.getAvailableSerialPorts());
}
}
SerialPortGateway.java 文件源码
项目:openhab-hdl
阅读 19
收藏 0
点赞 0
评论 0
private SerialPortGateway(String serialPortName) {
this.serialPort = new NRSerialPort(serialPortName, 9600);
this.serialPort.connect();
}
SerialPortByteProvider.java 文件源码
项目:openhab-hdl
阅读 20
收藏 0
点赞 0
评论 0
/**
* Create a new instance
*/
public static IByteProvider create(NRSerialPort serialPort) {
return new SerialPortByteProvider(serialPort);
}
SerialRegoConnection.java 文件源码
项目:openhab2-addons
阅读 20
收藏 0
点赞 0
评论 0
private boolean isPortNameExist(String portName) {
return NRSerialPort.getAvailableSerialPorts().contains(portName);
}
Uploader.java 文件源码
项目:j8051
阅读 25
收藏 0
点赞 0
评论 0
public static String[] getAvailableComPorts()
{
Set<String> set = NRSerialPort.getAvailableSerialPorts();
return set.toArray(new String[set.size()]);
}
SerialPortGateway.java 文件源码
项目:openhab1-addons
阅读 21
收藏 0
点赞 0
评论 0
private SerialPortGateway(String serialPortName) {
this.serialPort = new NRSerialPort(serialPortName, 9600);
this.serialPort.connect();
}
SerialPortByteProvider.java 文件源码
项目:openhab1-addons
阅读 22
收藏 0
点赞 0
评论 0
/**
* Create a new instance
*/
public static IByteProvider create(NRSerialPort serialPort) {
return new SerialPortByteProvider(serialPort);
}
SerialPortByteProvider.java 文件源码
项目:openhab-hdl
阅读 20
收藏 0
点赞 0
评论 0
/**
* Constructor
*
* @param serialPort
*/
private SerialPortByteProvider(NRSerialPort serialPort) {
this.serialPort = serialPort;
}
SerialAvrConnection.java 文件源码
项目:openhab2-addons
阅读 21
收藏 0
点赞 0
评论 0
/**
* Check if the Serial with the given name exist.
*
* @param portName
* @return
*/
private boolean isPortNameExist(String portName) {
return NRSerialPort.getAvailableSerialPorts().contains(portName);
}
SerialPortByteProvider.java 文件源码
项目:openhab1-addons
阅读 20
收藏 0
点赞 0
评论 0
/**
* Constructor
*
* @param serialPort
*/
private SerialPortByteProvider(NRSerialPort serialPort) {
this.serialPort = serialPort;
}