<rt id="bn8ez"></rt>
<label id="bn8ez"></label>

  • <span id="bn8ez"></span>

    <label id="bn8ez"><meter id="bn8ez"></meter></label>

    java Source

      BlogJava :: 首頁 :: 聯系 :: 聚合  :: 管理
      14 Posts :: 24 Stories :: 8 Comments :: 0 Trackbacks
    1.Library:RXTXComm.jar



    /*

     * GPSSerialPortScaner.java
     * Copyright (C) 2009  <JustinLei@gmail.com>
     *
     *        This program is free software; you can redistribute it and/or modify
     *        it under the terms of the GNU General Public License as published by
     *      the Free Software Foundation; either version 2 of the License, or
     *     (at your option) any later version.
     *
     *       This program is distributed in the hope that it will be useful,
     *      but WITHOUT ANY WARRANTY; without even the implied warranty of
     *     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     *        GNU General Public License for more details.
     *
     
    */
    package org.lambdasoft.serial.gps;
    import gnu.io.CommPort;
    import gnu.io.CommPortIdentifier;
    import gnu.io.PortInUseException;
    import gnu.io.SerialPort;
    import gnu.io.UnsupportedCommOperationException;

    import java.io.InputStream;
    import java.util.Enumeration;

    import org.lambdasoft.ui.dialog.BubbleDialog;
    import org.lambdasoft.ui.systray.statusbar.StatusBar;
    import org.lambdasoft.util.StringUtils;

    /**
     * 
    @author lei.tang (justinlei@gmail.com)
     * @date 2010-3-8
     * 
    @version
     
    */
    public class GPSSerialPortScaner {
        
    private static GPSSerialPortScaner finder;
        
    private static final int SCANTIME = 2000;
        
    private static final int[] PORTSPEED = new int[]{4800,9600};
        
    private GPSSerialPortScaner() {}
        
        
    public static GPSSerialPortScaner getScaner() {
            
    if(finder == null)
                finder 
    = new GPSSerialPortScaner();
            
    return finder;
        }

        
    public String scan() {
            BubbleDialog.getBubble().display(
    "GPS設備自動搜索中",false,false);
            
    for (int speed : PORTSPEED) {
                String port 
    = scan(speed);
                
    if(StringUtils.isNotEmpty(port))
                    
    return port;
            }
            
    return null;
        }
        
        @SuppressWarnings(
    "unchecked")
        
    public String scan(Integer speed) {
            StatusBar statusBar 
    = StatusBar.getBar();
            Enumeration
    <CommPortIdentifier> commons = CommPortIdentifier.getPortIdentifiers();
            CommPortIdentifier com 
    = null;
            CommPort serialPort 
    = null;
            
    while (commons.hasMoreElements()) {
                com 
    = commons.nextElement();
                
    if(statusBar != null)
                    statusBar.setGPSInfo(
    "掃描GPS設備:" + com.getName() + " 掃描速率:" + speed);
                
    try {
                    serialPort 
    = com.open("PortOpener"10);
                } 
    catch (PortInUseException piue) {
                    serialPort 
    = null;
                    
    continue;
                }
                
    if (com.getPortType() == CommPortIdentifier.PORT_SERIAL) {
                    SerialPort sp 
    = (SerialPort) serialPort;
                    
    try {
                        
    // Settings for B&G Hydra
                        sp.setSerialPortParams(speed.intValue(), SerialPort.DATABITS_8,
                                SerialPort.STOPBITS_1, SerialPort.PARITY_NONE);
                    } 
    catch (UnsupportedCommOperationException ucoe) {
                        serialPort 
    = null;
                        
    continue;
                    }
                }
                
    try {
                    InputStream input 
    = serialPort.getInputStream();
                    
    int readChar = -1;
                    
    long currentTime = System.currentTimeMillis();
                    
    while((System.currentTimeMillis() - currentTime) <= SCANTIME) {
                        
    if((readChar = input.read()) == -1) {
                            
    continue;
                        }
                        
    if((char)readChar == '$') {
                            StringBuilder builder 
    = new StringBuilder();
                            
    for (int j = 0; j < 5; j++) {
                                builder.append((
    char)(input.read()));
                            }
                            String head 
    = builder.toString();
                            
    if(head.equals("GPGGA")) {
                                serialPort.close();
                                
    if(statusBar != null) {
                                    String successMsg 
    = "GPS設備在端口" + com.getName() +"初始化成功,速率: " + speed;
                                    BubbleDialog.getBubble().display(successMsg,
    false,true);
                                    statusBar.setGPSInfo(successMsg);
                                }
                                
    return com.getName();
                            }
                        }
                    }
                } 
    catch (Exception e) {
                    
    return null;
                }
                serialPort.close();
            }
            
    if(serialPort != null)
                serialPort.close();
            
    return null;
        }
    }
    posted on 2010-04-06 16:47 JustinLei 閱讀(1493) 評論(0)  編輯  收藏

    只有注冊用戶登錄后才能發表評論。


    網站導航:
     
    主站蜘蛛池模板: 亚洲精品美女久久久久99小说| 一个人免费观看视频www| 亚洲一区二区精品视频| 国产亚洲精品美女久久久久久下载| 永久免费av无码不卡在线观看 | 亚洲综合精品香蕉久久网| 欧亚一级毛片免费看| 亚洲av无码不卡私人影院| 男女超爽视频免费播放| 亚洲精品成人区在线观看| 在线视频网址免费播放| 亚洲VA中文字幕无码毛片| 久久久高清日本道免费观看| 久久久久亚洲Av无码专| 精品香蕉在线观看免费| 亚洲一区二区三区在线观看蜜桃| 特级做A爰片毛片免费69| 亚洲精品无码成人片久久不卡 | 国产精品观看在线亚洲人成网| 黑人粗长大战亚洲女2021国产精品成人免费视频 | 亚洲男人的天堂www| 无码国产精品一区二区免费3p | 亚洲日本中文字幕一区二区三区| 成人毛片100免费观看| 亚洲综合自拍成人| 91久久成人免费| 国产成人亚洲综合在线| 亚洲精品tv久久久久久久久 | 朝桐光亚洲专区在线中文字幕 | 亚洲男人在线无码视频| 无码国产精品一区二区免费式芒果 | 亚洲AV成人精品一区二区三区| 亚洲AV中文无码乱人伦| 一级毛片在线免费看| 亚洲av无码片vr一区二区三区 | 国产亚洲精品无码拍拍拍色欲 | 免费又黄又爽又猛的毛片| 久久午夜无码免费| 日韩色日韩视频亚洲网站| 亚洲国产精品婷婷久久| 四虎永久精品免费观看|