<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è)用戶登錄后才能發(fā)表評(píng)論。


    網(wǎng)站導(dǎo)航:
     
    主站蜘蛛池模板: 亚洲乱码中文字幕综合| 337p日本欧洲亚洲大胆色噜噜| 成年免费大片黄在线观看com| 国产成人精品日本亚洲专区| 无码国产精品一区二区免费3p| 亚洲天堂福利视频| 亚洲AV无码成H人在线观看| a级毛片在线免费| 亚洲久悠悠色悠在线播放| 亚洲免费日韩无码系列| 最近免费中文字幕大全免费| 国产精品亚洲专区无码牛牛 | 黄色免费网站网址| 免费国产黄网站在线看| 蜜芽亚洲av无码精品色午夜| 国产18禁黄网站免费观看| 99re免费99re在线视频手机版| 黄色网址免费在线| 2020国产精品亚洲综合网| 亚洲乱码一区二区三区在线观看 | 亚洲色图综合在线| 国产v精品成人免费视频400条| free哆拍拍免费永久视频 | 国产成人精品免费久久久久| 亚洲字幕AV一区二区三区四区| 国产亚洲精品xxx| 国产免费av片在线无码免费看| 99久久免费精品高清特色大片| 日韩毛片一区视频免费| 亚洲sss综合天堂久久久| 亚洲成色WWW久久网站| 日本中文一区二区三区亚洲| 亚洲人成人网站在线观看| 波多野结衣中文字幕免费视频| 毛片基地看看成人免费| 亚洲av永久无码天堂网| 亚洲人成网站在线观看播放动漫| 久久精品国产亚洲网站| 亚洲无码视频在线| 国产一卡二卡≡卡四卡免费乱码 | 亚洲码国产精品高潮在线|