本文整理汇总了Java中gnu.io.CommPortIdentifier.PORT_SERIAL属性的典型用法代码示例。如果您正苦于以下问题:Java CommPortIdentifier.PORT_SERIAL属性的具体用法?Java CommPortIdentifier.PORT_SERIAL怎么用?Java CommPortIdentifier.PORT_SERIAL使用的例子?那么恭喜您, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在类gnu.io.CommPortIdentifier
的用法示例。
在下文中一共展示了CommPortIdentifier.PORT_SERIAL属性的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: initialize
public void initialize() {
System.setProperty("gnu.io.rxtx.SerialPorts", getComPortName());
CommPortIdentifier portId = null;
Enumeration portEnum = CommPortIdentifier.getPortIdentifiers();
while (portEnum.hasMoreElements()) {
CommPortIdentifier currPortId = (CommPortIdentifier) portEnum.nextElement();
if(currPortId.getPortType() == CommPortIdentifier.PORT_SERIAL) {
if (currPortId.getName().equals(txtComPortName.getText())) {
System.out.println(txtComPortName.getText());
portId = currPortId;
break;
}
}
}
if (portId == null) {
JOptionPane.showMessageDialog(null," Portuna bağlı cihaz yok!","Hata",JOptionPane.ERROR_MESSAGE);
System.out.println("Porta bağlı cihaz yok!");
return;
}
System.out.println(portId);
try {
serialPort = (SerialPort) portId.open(this.getClass().getName(), TIME_OUT);
serialPort.setSerialPortParams(DATA_RATE, SerialPort.DATABITS_8, SerialPort.STOPBITS_1,
SerialPort.PARITY_NONE);
input = new BufferedReader(new InputStreamReader(serialPort.getInputStream()));
output = serialPort.getOutputStream();
serialPort.addEventListener((SerialPortEventListener) this);
serialPort.notifyOnDataAvailable(true);
} catch (Exception e) {
System.err.println(e.toString());
}
}
示例2: getPortNames
/**
* gets a list of all available serial port names
*
* @return a platform dependent list of strings representing all the
* available serial ports -- it is the application's responsibility
* to identify the right port to which the device is actually connected
*/
public String[] getPortNames()
{
ArrayList<String> ret= new ArrayList<String>();
Enumeration<CommPortIdentifier> portsEnum= CommPortIdentifier.getPortIdentifiers();
while(portsEnum.hasMoreElements())
{
CommPortIdentifier pid= portsEnum.nextElement();
if (pid.getPortType() == CommPortIdentifier.PORT_SERIAL) {
ret.add(pid.getName());
}
}
return ret.toArray(new String[ret.size()]);
}
示例3: findSerialPort
public static CommPortIdentifier findSerialPort() throws Exception {
CommPortIdentifier serialPort = null;
@SuppressWarnings("unchecked")
java.util.Enumeration<CommPortIdentifier> portEnum = CommPortIdentifier.getPortIdentifiers();
while ( portEnum.hasMoreElements() )
{
CommPortIdentifier portIdentifier = portEnum.nextElement();
if (CommPortIdentifier.PORT_SERIAL==portIdentifier.getPortType()) {
if (serialPort==null)
serialPort = portIdentifier;
else
throw new Exception("More than one serial port found! "+serialPort.getName()+" and "+portIdentifier.getName());
}
}
return serialPort;
}
示例4: init
private void init() {
try {
if (m_out == null) {
m_PortIdPrinter = CommPortIdentifier.getPortIdentifier(m_sPort); // Tomamos el puerto
m_CommPortPrinter = m_PortIdPrinter.open("PORTID", 2000); // Abrimos el puerto
m_out = m_CommPortPrinter.getOutputStream(); // Tomamos el chorro de escritura
if (m_PortIdPrinter.getPortType() == CommPortIdentifier.PORT_SERIAL) {
((SerialPort)m_CommPortPrinter).setSerialPortParams(9600, SerialPort.DATABITS_8, SerialPort.STOPBITS_1, SerialPort.PARITY_NONE); // Configuramos el puerto
} else if (m_PortIdPrinter.getPortType() == CommPortIdentifier.PORT_PARALLEL) {
((ParallelPort)m_CommPortPrinter).setMode(1);
}
}
} catch (Exception e) {
m_PortIdPrinter = null;
m_CommPortPrinter = null;
m_out = null;
m_in = null;
// } catch (NoSuchPortException e) {
// } catch (PortInUseException e) {
// } catch (UnsupportedCommOperationException e) {
// } catch (IOException e) {
}
}
示例5: getPortList
/**
* This method is used to get a list of all the available Serial ports
* (note: only Serial ports are considered). Any one of the elements
* contained in the returned {@link List} can be used as a parameter in
* {@link #connect(String)} or {@link #connect(String, int)} to open a
* Serial connection.
*
* @return A {@link List} containing {@link String}s showing all available
* Serial ports.
*/
public List<String> getPortList() {
List<String> ports = new ArrayList<String>();
Enumeration<?> portList = CommPortIdentifier.getPortIdentifiers();
while (portList.hasMoreElements()) {
CommPortIdentifier portId = (CommPortIdentifier) portList.nextElement();
if (portId.getPortType() == CommPortIdentifier.PORT_SERIAL) {
ports.add(portId.getName());
}
}
writeLog("found the following ports:");
for (String port : ports) {
writeLog(" " + port);
}
return ports;
}
示例6: enumerateSerialPorts
/**
* Get a vector of all the ports identified on this computer
*
* @return
*/
public static Vector enumerateSerialPorts() {
Enumeration ports = CommPortIdentifier.getPortIdentifiers();
Vector portStrings = new Vector();
while(ports.hasMoreElements()) {
CommPortIdentifier currentPort = (CommPortIdentifier)ports.nextElement();
if(currentPort.getPortType() != CommPortIdentifier.PORT_SERIAL)
continue;
portStrings.add(new String(currentPort.getName()));
}
return portStrings;
}
示例7: setComs
public void setComs() {
ArrayList<String> comList = new ArrayList<String>();
Enumeration<CommPortIdentifier> comm = CommPortUtils.getComPorts();
while (comm.hasMoreElements()) {
CommPortIdentifier port_identifier = (CommPortIdentifier) comm
.nextElement();
if (port_identifier.getPortType() == CommPortIdentifier.PORT_SERIAL) {
// if (!comOldList.contains(port_identifier.getName()))
comList.add(port_identifier.getName());
}
}
if (comList.isEmpty()) {
addCom("N�o h� portas dispon�veis");
} else {
addCom(comList);
}
}
示例8: findPort
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);
}
示例9: getPortTypeName
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";
}
}
示例10: discoverSticks
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");
}
}
示例11: findSerialPortIdentifier
@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));
}
示例12: listSerialPorts
/**
* @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;
}
示例13: getPortNames
/**
* Get a list of the available serial ports.
*
* @return the names of the available serial ports, alphabetically sorted.
*/
public static String[] getPortNames()
{
if (!serialPortLibLoaded)
loadSerialPortLib();
final Enumeration<?> portList = CommPortIdentifier.getPortIdentifiers();
final Vector<String> portNames = new Vector<String>(20);
while (portList.hasMoreElements())
{
CommPortIdentifier portIdent = (CommPortIdentifier) portList.nextElement();
if (portIdent.getPortType() == CommPortIdentifier.PORT_SERIAL)
portNames.add(portIdent.getName());
}
final String[] result = new String[portNames.size()];
portNames.toArray(result);
Arrays.sort(result);
return result;
}
示例14: getSerialPortIdentifiers
@SuppressWarnings("unchecked")
public static Enumeration<String> getSerialPortIdentifiers() {
synchronized(vPortIDs) {
if(vPortIDs.isEmpty()) {
for (Enumeration<CommPortIdentifier> e = CommPortIdentifier.getPortIdentifiers(); e.hasMoreElements(); ) {
CommPortIdentifier portID = e.nextElement();
if (portID.getPortType() == CommPortIdentifier.PORT_SERIAL) {
vPortIDs.add(portID.getName());
}
}
}
return vPortIDs.elements();
}
}
示例15: createPortList
/**
* Populate the serial port drop-down list
*/
private void createPortList() {
try {
Enumeration<?> portList = CommPortIdentifier.getPortIdentifiers();
while (portList.hasMoreElements()) {
CommPortIdentifier portId = (CommPortIdentifier) portList.nextElement();
if (portId.getPortType() == CommPortIdentifier.PORT_SERIAL) {
String name = portId.getName();
// ignore /dev/tty to prevent duplicate serial port listings (/dev/tty and /dev/cu)
//if (!name.startsWith("/dev/tty.")) {
serialPorts.addItem(name);
//}
}
}
} catch (Exception e) {
e.printStackTrace();
}
}