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

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

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

    java Source

      BlogJava :: 首頁(yè) :: 聯(lián)系 :: 聚合  :: 管理
      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設(shè)備自動(dòng)搜索中",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設(shè)備:" + 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設(shè)備在端口" + 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 閱讀(1502) 評(píng)論(0)  編輯  收藏

    只有注冊(cè)用戶(hù)登錄后才能發(fā)表評(píng)論。


    網(wǎng)站導(dǎo)航:
     
    主站蜘蛛池模板: 久久久久亚洲AV片无码| 亚洲嫩草影院在线观看| 国产亚洲精品a在线观看| 青青草原1769久久免费播放| 日韩亚洲Av人人夜夜澡人人爽| 九九99热免费最新版| 亚洲AV成人精品网站在线播放| 成人影片麻豆国产影片免费观看| 亚洲成AV人片在WWW色猫咪| 可以免费看黄的网站| 亚洲视频在线免费播放| 日美韩电影免费看| 日韩免费的视频在线观看香蕉| 亚洲av永久无码一区二区三区| 国产JIZZ中国JIZZ免费看| 免费a级毛片永久免费| 国产成人精品一区二区三区免费| 亚洲午夜无码久久久久软件| 大陆一级毛片免费视频观看i| 亚洲色一区二区三区四区| 亚洲午夜国产精品无码| 成人免费午间影院在线观看| 中文字幕亚洲精品无码| 亚洲日韩一页精品发布| 免费鲁丝片一级观看| 99久久99久久精品免费观看 | 亚洲av综合色区| 免费黄色网址入口| 1000部无遮挡拍拍拍免费视频观看| 全部一级一级毛片免费看| 亚洲Av无码一区二区二三区| 亚洲啪啪AV无码片| 国产免费私拍一区二区三区| 男性gay黄免费网站| 亚洲日韩人妻第一页| 国产免费爽爽视频在线观看| 亚洲国产精品一区二区久久| 97热久久免费频精品99| 91免费福利视频| 人成电影网在线观看免费| 亚洲免费网站观看视频|