本文整理汇总了Java中gnu.io.CommPortIdentifier.getPortIdentifiers方法的典型用法代码示例。如果您正苦于以下问题:Java CommPortIdentifier.getPortIdentifiers方法的具体用法?Java CommPortIdentifier.getPortIdentifiers怎么用?Java CommPortIdentifier.getPortIdentifiers使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类gnu.io.CommPortIdentifier
的用法示例。
在下文中一共展示了CommPortIdentifier.getPortIdentifiers方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: initialize
import gnu.io.CommPortIdentifier; //导入方法依赖的package包/类
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
import gnu.io.CommPortIdentifier; //导入方法依赖的package包/类
/**
* 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
import gnu.io.CommPortIdentifier; //导入方法依赖的package包/类
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: getPortList
import gnu.io.CommPortIdentifier; //导入方法依赖的package包/类
/**
* 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;
}
示例5: enumerateSerialPorts
import gnu.io.CommPortIdentifier; //导入方法依赖的package包/类
/**
* 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;
}
示例6: getSerialPort
import gnu.io.CommPortIdentifier; //导入方法依赖的package包/类
private CommPortIdentifier getSerialPort() {
if (port != null) {
try {
return CommPortIdentifier.getPortIdentifier(port);
} catch (NoSuchPortException e) {
e.printStackTrace();
}
return null;
}
Enumeration<?> portEnum = CommPortIdentifier.getPortIdentifiers();
while (portEnum.hasMoreElements()) {
CommPortIdentifier currPortId = (CommPortIdentifier) portEnum.nextElement();
for (String portName : PORT_NAMES) {
if (currPortId.getName().equals(portName)) {
return currPortId;
}
}
}
return null;
}
示例7: listPorts
import gnu.io.CommPortIdentifier; //导入方法依赖的package包/类
public String listPorts() {
List<String> port_name = new ArrayList<String>();
String tmp = "";
// int i = 0;
@SuppressWarnings("unchecked")
Enumeration<CommPortIdentifier> portEnum = CommPortIdentifier
.getPortIdentifiers();
// Enumeration portList = CommPortIdentifier.getPortIdentifiers();
while (portEnum.hasMoreElements()) {
CommPortIdentifier portIdentifier = (CommPortIdentifier) portEnum
.nextElement();
if (getPortTypeName(portIdentifier.getPortType()) == "Serial") {
port_name.add(portIdentifier.getName());
String tmp2 = portIdentifier.getName() + "#";
tmp = tmp + tmp2;
}
System.out.println(portIdentifier.getName() + " - "
+ getPortTypeName(portIdentifier.getPortType()));
}
// i = port_name.size();
return tmp;
}
示例8: findPort
import gnu.io.CommPortIdentifier; //导入方法依赖的package包/类
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: oeffneSerialPort
import gnu.io.CommPortIdentifier; //导入方法依赖的package包/类
/**
* 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;
}
示例10: discoverSticks
import gnu.io.CommPortIdentifier; //导入方法依赖的package包/类
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: getSerialPortIdentifiers
import gnu.io.CommPortIdentifier; //导入方法依赖的package包/类
@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();
}
}
示例12: enumeratePorts
import gnu.io.CommPortIdentifier; //导入方法依赖的package包/类
public static List<CommPortIdentifier> enumeratePorts() {
List<CommPortIdentifier> ports = new LinkedList<CommPortIdentifier>();
Enumeration<?> portEnum = CommPortIdentifier.getPortIdentifiers();
while (portEnum.hasMoreElements()) {
CommPortIdentifier portIdentifier = (CommPortIdentifier) portEnum.nextElement();
for (Pattern acceptablePortName : ACCEPTABLE_PORT_NAMES) {
String portName = portIdentifier.getName();
if (acceptablePortName.matcher(portName).matches()) {
ports.add(portIdentifier);
}
}
}
return ports;
}
示例13: initialize
import gnu.io.CommPortIdentifier; //导入方法依赖的package包/类
public void initialize(testEngine tee) {
te=tee;
CommPortIdentifier portId = null;
Enumeration portEnum = CommPortIdentifier.getPortIdentifiers();
// iterate through, looking for the port
while (portEnum.hasMoreElements()) {
CommPortIdentifier currPortId = (CommPortIdentifier) portEnum.nextElement();
for (String portName : PORT_NAMES) {
if (currPortId.getName().equals(portName)) {
portId = currPortId;
break;
}
}
}
if (portId == null) {
te.log("Could not find COM port.");
return;
}else{
te.log("Found your Port");
}
try {
// open serial port, and use class name for the appName.
serialPort = (SerialPort) portId.open(this.getClass().getName(),TIME_OUT);
// set port parameters
serialPort.setSerialPortParams(DATA_RATE,
SerialPort.DATABITS_8,
SerialPort.STOPBITS_1,
SerialPort.PARITY_NONE);
// open the streams
input = serialPort.getInputStream();
output = serialPort.getOutputStream();
// add event listeners
serialPort.addEventListener(this);
serialPort.notifyOnDataAvailable(true);
} catch (Exception e) {
System.err.println(e.toString());
}
}
示例14: getPortList
import gnu.io.CommPortIdentifier; //导入方法依赖的package包/类
public static String[] getPortList() {
Enumeration portList = CommPortIdentifier.getPortIdentifiers();
int portCount = 0;
while (portList.hasMoreElements()) {
portList.nextElement();
portCount++;
}
String[] retVal = new String[portCount];
portCount = 0;
portList = CommPortIdentifier.getPortIdentifiers();
while (portList.hasMoreElements()) {
CommPortIdentifier portId = (CommPortIdentifier) portList.nextElement();
retVal[portCount++] = portId.getName();
}
return retVal;
}
示例15: getPortNames
import gnu.io.CommPortIdentifier; //导入方法依赖的package包/类
/**
* 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;
}