⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 serialconnector.java

📁 无线通信的主要编程软件,是无线通信工作人员的必备工具,关天相关教程我会在后续传上.
💻 JAVA
📖 第 1 页 / 共 4 页
字号:
/* * Copyright (c) 2003, Vanderbilt University * All rights reserved. * * Permission to use, copy, modify, and distribute this software and its * documentation for any purpose, without fee, and without written agreement is * hereby granted, provided that the above copyright notice, the following * two paragraphs and the author appear in all copies of this software. * * IN NO EVENT SHALL THE VANDERBILT UNIVERSITY BE LIABLE TO ANY PARTY FOR * DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING OUT * OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF THE VANDERBILT * UNIVERSITY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * * THE VANDERBILT UNIVERSITY SPECIFICALLY DISCLAIMS ANY WARRANTIES, * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY * AND FITNESS FOR A PARTICULAR PURPOSE.  THE SOFTWARE PROVIDED HEREUNDER IS * ON AN "AS IS" BASIS, AND THE VANDERBILT UNIVERSITY HAS NO OBLIGATION TO * PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS. */package net.tinyos.mcenter;import java.awt.event.*;import net.tinyos.packet.*;import net.tinyos.message.*;/** * * @author  nadand */public class SerialConnector extends javax.swing.JInternalFrame {        private net.tinyos.packet.PacketSource serialStub;    private MessageFactory messageFactory;    private int action = 0x0; // 0x0: default, 0x1: local, 0x2: server, 0x3 : illegal    private long msgsent=0;    private long msgreceived=0;    private long msgadded=0;    private long msgposted=0;        private PacketReader packetReader;    private DistributorThread distributorThread;        private java.util.Vector packetBuffer = new java.util.Vector();        private java.util.HashMap messageIdRegisterMap = new java.util.HashMap();    private java.util.HashMap clientRegisterMap =  new java.util.HashMap();        static private SerialConnector _instance = null;        private ItemRadioButton lastSelected;         private short maxMsgLength = 36;    private short group=0;        public static final int GET_ALL_MESSAGES = -1;        private static final int PACKET_ADDRESS_FIELD = 0;    private static final int PACKET_TYPE_FIELD = 2;    private static final int PACKET_GROUP_FIELD = 3;    private static final int PACKET_LENGTH_FIELD = 4;    private static final int PACKET_DATA_BEGIN = 5;    private static final int PACKET_CRC_SIZE = 2;        private java.util.prefs.Preferences prefsRoot = java.util.prefs.Preferences.userNodeForPackage(this.getClass());    private java.util.prefs.Preferences prefs;        /** Creates new Singleton SerialConnector */    protected SerialConnector() {        initComponents();        prefs = prefsRoot.node(prefsRoot.absolutePath()+"/SerialConnector");        this.comPortTextField.setText(prefs.get("ComPort","COM1"));        this.comSpeedTextField.setText(prefs.get("ComSpeed","57600"));        //this.sComPortTextField.setText(prefs.get("SyncedComPort","COM1"));        //this.sComPortSpeedTextField.setText(prefs.get("SyncedComSpeed","57600"));        this.ipAddressTextField.setText(prefs.get("IpAddress","127.0.0.1"));        this.ipPortTextField.setText(prefs.get("IpPort","9000"));                this.tossimRadioAddressTextField.setText(prefs.get("TossimIP","127.0.0.1"));        this.tossimSerialAddressTextField.setText(prefs.get("TossimSerialIP", "127.0.0.1"));        this.otherConnTextField.setText(prefs.get("OtherString",""));                //this.lhPortTextField.setText(prefs.get("LocalPort","9000"));        this.groupTextField.setText(prefs.get("GroupId","0x7D"));                        buttonGroup1.add(this.connectionRadioButtonCOM);       // buttonGroup1.add(this.connectionRadioButtonSCOM);        buttonGroup1.add(this.connectionRadioButtonIP);        buttonGroup1.add(this.connectionRadioButtonTossim);        buttonGroup1.add(this.connectionRadioButtonTossimSerial);        buttonGroup1.add(this.connectionRadioButtonOther);        //buttonGroup1.add(this.connectionRadioButtonLH);                setRBstate(false);        lastSelected = (ItemRadioButton)connectionRadioButtonCOM;        this.buttonGroup1.setSelected(this.connectionRadioButtonCOM.getModel(),true);    }    /**************************Singleton Pattern "snstructor"**********************/    static public SerialConnector instance() {        if(null == _instance) {            _instance = new SerialConnector();        }        return _instance;    }        private void setRBstate(boolean enabled){        this.comPortTextField.setEnabled(enabled);        this.comSpeedTextField.setEnabled(enabled);        this.comPortLabel.setEnabled(enabled);        this.speedLabel.setEnabled(enabled);        //this.sComPortTextField.setEnabled(enabled);        //this.sComPortSpeedTextField.setEnabled(enabled);        //this.sComPortLabel.setEnabled(enabled);        //this.sComPortSpeedLabel.setEnabled(enabled);        this.ipLabel.setEnabled(enabled);        this.ipAddressTextField.setEnabled(enabled);        this.ipPortTextField.setEnabled(enabled);        this.portLabel.setEnabled(enabled);                        this.tossimRadioAddressTextField.setEnabled(enabled);        this.tossimSerialAddressTextField.setEnabled(enabled);        this.otherConnTextField.setEnabled(enabled);        this.tossimSerialLabel.setEnabled(enabled);        this.tossimRadioLabel.setEnabled(enabled);        this.otherConnLabel.setEnabled(enabled);                    }        private void setRBenable(ItemRadioButton radioButton,boolean enabled){        int newState = (enabled) ? ItemEvent.SELECTED : ItemEvent.DESELECTED;        radioButton.changeEnabledState(new ItemEvent(radioButton, ItemEvent.ITEM_STATE_CHANGED, radioButton, newState));    }                public short getMsgLength() {        return maxMsgLength;    }        /** This method is called from within the constructor to     * initialize the form.     * WARNING: Do NOT modify this code. The content of this method is     * always regenerated by the Form Editor.     */    private void initComponents() {//GEN-BEGIN:initComponents        java.awt.GridBagConstraints gridBagConstraints;        buttonGroup1 = new javax.swing.ButtonGroup();        mainPanel = new javax.swing.JPanel();        connectionRadioButtonCOM = new ItemRadioButton();        comPortLabel = new javax.swing.JLabel();        comPortTextField = new javax.swing.JTextField();        speedLabel = new javax.swing.JLabel();        comSpeedTextField = new javax.swing.JTextField();        connectionRadioButtonIP = new ItemRadioButton();        ipLabel = new javax.swing.JLabel();        ipAddressTextField = new javax.swing.JTextField();        portLabel = new javax.swing.JLabel();        ipPortTextField = new javax.swing.JTextField();        placeholderjLabel = new javax.swing.JLabel();        jSeparator1 = new javax.swing.JSeparator();        packetSizeLabel = new javax.swing.JLabel();        packetSizeTextField = new javax.swing.JTextField();        groupLabel = new javax.swing.JLabel();        groupTextField = new javax.swing.JTextField();        jSeparator2 = new javax.swing.JSeparator();        oldProtocolCheckBox = new javax.swing.JCheckBox();        threadingCheckBox = new javax.swing.JCheckBox();        connectionRadioButtonTossim = new ItemRadioButton();        connectionRadioButtonTossimSerial = new ItemRadioButton();        connectionRadioButtonOther = new ItemRadioButton();        tossimRadioLabel = new javax.swing.JLabel();        tossimRadioAddressTextField = new javax.swing.JTextField();        tossimSerialLabel = new javax.swing.JLabel();        tossimSerialAddressTextField = new javax.swing.JTextField();        otherConnLabel = new javax.swing.JLabel();        otherConnTextField = new javax.swing.JTextField();        messagePanel = new javax.swing.JPanel();        sentLabel = new javax.swing.JLabel();        sentTextField = new javax.swing.JTextField();        receivedLabel = new javax.swing.JLabel();        receivedTextField = new javax.swing.JTextField();        controlPanel = new javax.swing.JPanel();        ssButton = new javax.swing.JButton();        setIconifiable(true);        setMaximizable(true);        setResizable(true);        setTitle("SerialConnector");        mainPanel.setLayout(new java.awt.GridBagLayout());        mainPanel.setBorder(new javax.swing.border.SoftBevelBorder(javax.swing.border.BevelBorder.RAISED));        connectionRadioButtonCOM.setText("Serial Port");        connectionRadioButtonCOM.addItemListener(new java.awt.event.ItemListener() {            public void itemStateChanged(java.awt.event.ItemEvent evt) {                connectionRadioButtonCOMItemStateChanged(evt);            }        });        gridBagConstraints = new java.awt.GridBagConstraints();        gridBagConstraints.gridwidth = 2;        gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;        gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;        mainPanel.add(connectionRadioButtonCOM, gridBagConstraints);        comPortLabel.setHorizontalAlignment(javax.swing.SwingConstants.TRAILING);        comPortLabel.setText("port");        gridBagConstraints = new java.awt.GridBagConstraints();        gridBagConstraints.anchor = java.awt.GridBagConstraints.EAST;        mainPanel.add(comPortLabel, gridBagConstraints);        comPortTextField.setText("COM1");        gridBagConstraints = new java.awt.GridBagConstraints();        gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;        mainPanel.add(comPortTextField, gridBagConstraints);        speedLabel.setHorizontalAlignment(javax.swing.SwingConstants.TRAILING);        speedLabel.setText("speed");        gridBagConstraints = new java.awt.GridBagConstraints();        gridBagConstraints.anchor = java.awt.GridBagConstraints.EAST;        mainPanel.add(speedLabel, gridBagConstraints);        comSpeedTextField.setText("57600");        gridBagConstraints = new java.awt.GridBagConstraints();        gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER;        gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;        mainPanel.add(comSpeedTextField, gridBagConstraints);        connectionRadioButtonIP.setText("Remote Server");        connectionRadioButtonIP.addItemListener(new java.awt.event.ItemListener() {            public void itemStateChanged(java.awt.event.ItemEvent evt) {                connectionRadioButtonIPItemStateChanged(evt);            }        });        gridBagConstraints = new java.awt.GridBagConstraints();        gridBagConstraints.gridx = 0;        gridBagConstraints.gridy = 2;        gridBagConstraints.gridwidth = 2;        gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;        mainPanel.add(connectionRadioButtonIP, gridBagConstraints);        ipLabel.setHorizontalAlignment(javax.swing.SwingConstants.TRAILING);        ipLabel.setText("address");        gridBagConstraints = new java.awt.GridBagConstraints();        gridBagConstraints.gridx = 2;        gridBagConstraints.gridy = 2;        gridBagConstraints.anchor = java.awt.GridBagConstraints.EAST;        mainPanel.add(ipLabel, gridBagConstraints);        ipAddressTextField.setText("127.0.0.1");        gridBagConstraints = new java.awt.GridBagConstraints();        gridBagConstraints.gridx = 3;        gridBagConstraints.gridy = 2;        gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;        mainPanel.add(ipAddressTextField, gridBagConstraints);

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -