/**
* Creates an instance of this class.
* @param commPortIdentifier Must point to an serial port
* @param baudrate The baudrate of the communication. The baudrate must be
* setted with <code>AT+IPR=*baudrate*</code>. The default baudrate
* of an device is <code>115200</code>
* @param flowControlMode The flow control mode of the serial port
* @return An instance of <code>CommHandlerImpl</code>
* @throws PortInUseException The selected port is used by another application
* @throws IOException The communication to the device failed
* @throws IllegalArgumentException If parameter commPortIdentifier is
* <code>null</code> or the result of {@link CommPortIdentifier#open(java.lang.String, int) }
* is not an instance of {@link SerialPort}.
* @since 1.5
*/
public static final CommHandler createCommHandler(final CommPortIdentifier commPortIdentifier
, final int baudrate, final EnumSet<FlowControlMode> flowControlMode)
throws PortInUseException, IOException
{
final CommHandlerImpl commHandler = new CommHandlerImpl();
try
{
commHandler.init(commPortIdentifier, baudrate, flowControlMode);
return commHandler;
}
catch (final PortInUseException | IOException ex)
{
commHandler.close();
throw ex;
}
}
java类gnu.io.CommPortIdentifier的实例源码
CommHandlerImpl.java 文件源码
项目:jmoduleconnect
阅读 18
收藏 0
点赞 0
评论 0
SerialSketchUploader.java 文件源码
项目:arduino-remote-uploader
阅读 19
收藏 0
点赞 0
评论 0
public CommPortIdentifier findPort(String port) {
// parse ports and if the default port is found, initialized the reader
Enumeration portList = CommPortIdentifier.getPortIdentifiers();
while (portList.hasMoreElements()) {
CommPortIdentifier portId = (CommPortIdentifier) portList.nextElement();
if (portId.getPortType() == CommPortIdentifier.PORT_SERIAL) {
//System.out.println("Found port: " + portId.getName());
if (portId.getName().equals(port)) {
//System.out.println("Using Port: " + portId.getName());
return portId;
}
}
}
throw new RuntimeException("Port not found " + port);
}
SerialSketchUploader.java 文件源码
项目:arduino-remote-uploader
阅读 18
收藏 0
点赞 0
评论 0
public void openSerial(String serialPortName, int speed) throws PortInUseException, IOException, UnsupportedCommOperationException, TooManyListenersException {
CommPortIdentifier commPortIdentifier = findPort(serialPortName);
// initalize serial port
serialPort = (SerialPort) commPortIdentifier.open("Arduino", 2000);
inputStream = serialPort.getInputStream();
serialPort.addEventListener(this);
// activate the DATA_AVAILABLE notifier
serialPort.notifyOnDataAvailable(true);
serialPort.setSerialPortParams(speed, SerialPort.DATABITS_8,
SerialPort.STOPBITS_1, SerialPort.PARITY_NONE);
serialPort.setFlowControlMode(SerialPort.FLOWCONTROL_NONE);
}
VCDSerialPort.java 文件源码
项目:EasyVote
阅读 18
收藏 0
点赞 0
评论 0
/**
* Versucht den seriellen Port zu �ffnen. Klappt nur, wenn er noch nicht von einer anderen Anwendung benutzt wird. Der jeweilige
* Port wird mit �bergeben. UNter Windows ist die Schreibweise "COM8" zum Beispeil unter Linux "dev/tts0"
* @param portName
* @return
* @throws PortInUseException
* @throws IOException
* @throws UnsupportedCommOperationException
*/
public boolean oeffneSerialPort(String portName) throws PortInUseException, IOException, UnsupportedCommOperationException
{
Boolean foundPort = false;
if (serialPortGeoeffnet != false) {
System.out.println("Serialport bereits ge�ffnet");
schliesseSerialPort();
return false;
}
System.out.println("�ffne Serialport");
enumComm = CommPortIdentifier.getPortIdentifiers();
while(enumComm.hasMoreElements()) {
serialPortId = (CommPortIdentifier) enumComm.nextElement();
System.out.println("SerialportIDs:" + serialPortId.getName());
if (portName.contentEquals(serialPortId.getName())) {
foundPort = true;
break;
}
}
if (foundPort != true) {
System.out.println("Serialport nicht gefunden: " + portName);
return false;
}
serialPort = (SerialPort) serialPortId.open("�ffnen und Senden", 500);
outputStream = serialPort.getOutputStream();
inputStream = serialPort.getInputStream();
serialPort.notifyOnDataAvailable(true);
serialPort.setSerialPortParams(baudrate, dataBits, stopBits, parity);
serialPortGeoeffnet = true;
return true;
}
FlashExporter.java 文件源码
项目:Animator
阅读 19
收藏 0
点赞 0
评论 0
public String getPortTypeName(int portType) {
switch (portType) {
case CommPortIdentifier.PORT_I2C:
return "I2C";
case CommPortIdentifier.PORT_PARALLEL:
return "Parallel";
case CommPortIdentifier.PORT_RAW:
return "Raw";
case CommPortIdentifier.PORT_RS485:
return "RS485";
case CommPortIdentifier.PORT_SERIAL:
return "Serial";
default:
return "unknown type";
}
}
PlugwiseStickDiscoveryService.java 文件源码
项目:openhab2-addons
阅读 18
收藏 0
点赞 0
评论 0
protected void discoverSticks() {
if (discovering) {
logger.debug("Stick discovery not possible (already discovering)");
} else {
discovering = true;
@SuppressWarnings("unchecked")
Enumeration<CommPortIdentifier> portIdentifiers = CommPortIdentifier.getPortIdentifiers();
while (discovering && portIdentifiers.hasMoreElements()) {
CommPortIdentifier portIdentifier = portIdentifiers.nextElement();
if (portIdentifier.getPortType() == CommPortIdentifier.PORT_SERIAL
&& !portIdentifier.isCurrentlyOwned()) {
discoverStick(portIdentifier.getName());
}
}
discovering = false;
logger.debug("Finished discovering Sticks on serial ports");
}
}
PlugwiseCommunicationContext.java 文件源码
项目:openhab2-addons
阅读 15
收藏 0
点赞 0
评论 0
@SuppressWarnings("unchecked")
private CommPortIdentifier findSerialPortIdentifier() throws PlugwiseInitializationException {
Enumeration<CommPortIdentifier> portList = CommPortIdentifier.getPortIdentifiers();
while (portList.hasMoreElements()) {
CommPortIdentifier identifier = portList.nextElement();
if (identifier.getPortType() == CommPortIdentifier.PORT_SERIAL
&& identifier.getName().equals(configuration.getSerialPort())) {
logger.debug("Serial port '{}' has been found", configuration.getSerialPort());
return identifier;
}
}
// Build exception message when port not found
StringBuilder sb = new StringBuilder();
portList = CommPortIdentifier.getPortIdentifiers();
while (portList.hasMoreElements()) {
CommPortIdentifier id = portList.nextElement();
if (id.getPortType() == CommPortIdentifier.PORT_SERIAL) {
sb.append(String.format("%s%n", id.getName()));
}
}
throw new PlugwiseInitializationException(String.format(
"Serial port '%s' could not be found. Available ports are:%n%s", configuration.getSerialPort(), sb));
}
PortScanner.java 文件源码
项目:kkMulticopterFlashTool
阅读 15
收藏 0
点赞 0
评论 0
/**
* @return List all serial ports
*/
public static Vector<String> listSerialPorts()
{
Vector<String> ports = new Vector<String>();
if (KKMulticopterFlashTool.ENABLE_PORT_CHECK) {
java.util.Enumeration<CommPortIdentifier> portEnum = CommPortIdentifier.getPortIdentifiers();
while ( portEnum.hasMoreElements() )
{
CommPortIdentifier portIdentifier = portEnum.nextElement();
if (portIdentifier.getPortType()==CommPortIdentifier.PORT_SERIAL){
if (System.getProperty("os.name").toLowerCase().contains("mac")) {
if (portIdentifier.getName().contains("cu")){
ports.add(portIdentifier.getName());
}
} else {
ports.add(portIdentifier.getName());
}
}
}
}
return ports;
}
SerialReader.java 文件源码
项目:kkMulticopterFlashTool
阅读 24
收藏 0
点赞 0
评论 0
private void openPort() throws Exception{
CommPortIdentifier portIdentifier = CommPortIdentifier.getPortIdentifier(port);
CommPort commPort = portIdentifier.open("LightController",2000);
if ( commPort instanceof SerialPort )
{
serialPort = (SerialPort) commPort;
serialPort.setSerialPortParams(baud,SerialPort.DATABITS_8,SerialPort.STOPBITS_1,SerialPort.PARITY_NONE);
in = serialPort.getInputStream();
isr = new InputStreamReader(in);
br = new BufferedReader(isr);
}
}
Serial.java 文件源码
项目:Girinoscope
阅读 17
收藏 0
点赞 0
评论 0
public void connect(CommPortIdentifier portId) throws Exception {
serialPort = (SerialPort) portId.open(getClass().getName(), TIME_OUT);
serialPort.setSerialPortParams(DATA_RATE, SerialPort.DATABITS_8, SerialPort.STOPBITS_1, SerialPort.PARITY_NONE);
serialPort.setFlowControlMode(SerialPort.FLOWCONTROL_NONE);
output = serialPort.getOutputStream();
input = serialPort.getInputStream();
serialPort.notifyOnDataAvailable(false);
}