本文整理匯總了Java中gnu.io.CommPortIdentifier.getName方法的典型用法代碼示例。如果您正苦於以下問題:Java CommPortIdentifier.getName方法的具體用法?Java CommPortIdentifier.getName怎麽用?Java CommPortIdentifier.getName使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類gnu.io.CommPortIdentifier
的用法示例。
在下文中一共展示了CommPortIdentifier.getName方法的11個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: 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;
}
示例2: 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;
}
示例3: 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;
}
示例4: createSerialMenu
import gnu.io.CommPortIdentifier; //導入方法依賴的package包/類
private JMenu createSerialMenu() {
JMenu menu = new JMenu("Serial port");
ButtonGroup group = new ButtonGroup();
for (final CommPortIdentifier portId : Serial.enumeratePorts()) {
Action setSerialPort = new AbstractAction(portId.getName()) {
@Override
public void actionPerformed(ActionEvent event) {
UI.this.portId = portId;
}
};
AbstractButton button = new JCheckBoxMenuItem(setSerialPort);
if (UI.this.portId == null) {
button.doClick();
}
group.add(button);
menu.add(button);
}
return menu;
}
示例5: 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;
}
示例6: listSerialPorts
import gnu.io.CommPortIdentifier; //導入方法依賴的package包/類
/**
* Retrieves the list of available serial ports in the system.
*
* @return List of available serial ports.
*
* @see #listSerialPortsInfo()
*/
public static String[] listSerialPorts() {
ArrayList<String> serialPorts = new ArrayList<String>();
@SuppressWarnings("unchecked")
Enumeration<CommPortIdentifier> comPorts = CommPortIdentifier.getPortIdentifiers();
if (comPorts == null)
return serialPorts.toArray(new String[serialPorts.size()]);
while (comPorts.hasMoreElements()) {
CommPortIdentifier identifier = (CommPortIdentifier)comPorts.nextElement();
if (identifier == null)
continue;
String strName = identifier.getName();
serialPorts.add(strName);
}
return serialPorts.toArray(new String[serialPorts.size()]);
}
示例7: createPortList
import gnu.io.CommPortIdentifier; //導入方法依賴的package包/類
/**
* 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();
}
}
示例8: checkPortList
import gnu.io.CommPortIdentifier; //導入方法依賴的package包/類
/**
* Check if the serial port list has changed
*/
private void checkPortList() {
serialPortCount = 0;
try {
Enumeration<?> portList = CommPortIdentifier.getPortIdentifiers();
while (portList.hasMoreElements()) {
CommPortIdentifier portId = (CommPortIdentifier) portList.nextElement();
if (portId.getPortType() == CommPortIdentifier.PORT_SERIAL) {
String name = portId.getName();
if (!name.startsWith("/dev/tty.")) {
serialPortCount++;
}
}
}
} catch (Exception e) {
e.printStackTrace();
}
if (serialPortCount != serialPorts.getItemCount()) {
// an I/O board was added or removed so update the list
updatePortList();
}
}
示例9: ListarPortas
import gnu.io.CommPortIdentifier; //導入方法依賴的package包/類
public static String[] ListarPortas(){
int i = 0;
String portas[] = new String[10];
Enumeration<CommPortIdentifier> listaDePortas = CommPortIdentifier.getPortIdentifiers();
while (listaDePortas.hasMoreElements()){
CommPortIdentifier ips = listaDePortas.nextElement();
portas[i] = ips.getName();
i++;
}
return portas;
}
示例10: SearchForXbeeOnComports
import gnu.io.CommPortIdentifier; //導入方法依賴的package包/類
public boolean SearchForXbeeOnComports()
{
if(isConnected())
return true;
@SuppressWarnings("unchecked")
Enumeration<CommPortIdentifier> portIdentifiers = CommPortIdentifier.getPortIdentifiers();
String osName = System.getProperty("os.name");
String portName = null;
boolean foundXbee = false;
String comport;
if (osName.equalsIgnoreCase("Mac OS X"))
portName = "tty.usbserial";
else if (osName.equalsIgnoreCase("Linux"))
portName = "ttyUSB";
if(portName != null)
{
while (portIdentifiers.hasMoreElements())
{
CommPortIdentifier pid = (CommPortIdentifier) portIdentifiers.nextElement();
if (pid.getPortType() == CommPortIdentifier.PORT_SERIAL && !pid.isCurrentlyOwned() && pid.getName().contains(portName))
{
comport = pid.getName();
try {
xbee.open(comport, 57600);
foundXbee = true;
break;
} catch(XBeeException e) {
log.debug("Did not find XBee on comport " + comport);
}
}
}
}
if(!foundXbee)
return false;
else
return true;
}
示例11: main
import gnu.io.CommPortIdentifier; //導入方法依賴的package包/類
public static void main(String[] args) {
try {
Layer3Base base = new Layer3Base();
// Find the serial port device
CommPortIdentifier portId = null;
Enumeration portEnum = CommPortIdentifier.getPortIdentifiers();
while(portEnum.hasMoreElements()){
CommPortIdentifier currPort = (CommPortIdentifier) portEnum.nextElement();
String portName = currPort.getName();
if(portName.startsWith("/dev/tty.usbmodem") || portName.startsWith("/dev/ttyACM")){
portId = currPort;
}
}
if(portId == null){
throw new IOException("No serial port found matching the name pattern");
}
SerialRXTXComm serial = new SerialRXTXComm(portId, base);
Thread.sleep(4000);
Layer3Base.NetworkSetupThread setup = base.new NetworkSetupThread();
Thread setupThread = new Thread(setup);
setupThread.start();
setupThread.join();
// Alè, la rete è pronta, adesso posso giocare con i device
Device device = Device.getDeviceFromUniqueId(384932);
if(device!=null && device instanceof LedTestDevice){
LedTestDevice ledDevice = (LedTestDevice) device;
for(int i=0; i<5000; i++){
ledDevice.setLedState(true);
Thread.sleep(20);
ledDevice.setLedState(false);
Thread.sleep(50);
}
} else if(device!=null && device instanceof Led1Analog2Device){
Led1Analog2Device ledDev = (Led1Analog2Device) device;
for(int a=0; a<50; a++){
for(int i=0; i<255; i+=2){
ledDev.setLedPwmState(ledTable8bit[i]);
//Thread.sleep(10);
}
for(int i=255; i>0; i-=2){
ledDev.setLedPwmState(ledTable8bit[i]);
//Thread.sleep(10);
}
}
} else {
System.out.println("Errore get device");
}
Device dev = Device.getDeviceFromUniqueId(484333);
if(dev!=null && dev instanceof LedLamp1Device){
LedLamp1Device lamp = (LedLamp1Device) dev;
/*for(int i=0; i<6; i++){
AbsoluteColor color1 = new AbsoluteColor(0, 0, 0);
lamp.setColor(color1);
Thread.sleep(1000);
}*/
} else {
System.out.println("Error getting led lamp device");
}
} catch (Exception e) {
e.printStackTrace();
}
}