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

📄 test.java

📁 JRed is a 100% Java implementation of the IrDA infrared communications protocols. JRed lets you beam
💻 JAVA
字号:
/*
**************************************************************************
** $Header: /cvsroot/jred/jred/src/com/synchrona/jred/Test.java,v 1.4 2000/07/30 20:18:12 mpatters Exp $
**
** Copyright (C) 2000 Synchrona, Inc. All rights reserved.
**
** This file is part of JRed, a 100% Java implementation of the IrDA
** infrared communications protocols.
**
** This file may be distributed under the terms of the Synchrona Public
** License as defined by Synchrona, Inc. and appearing in the file
** LICENSE included in the packaging of this file. The Synchrona Public
** License is based on the Q Public License as defined by Troll Tech AS
** of Norway; it differs only in its use of the courts of Florida, USA
** rather than those of Oslo, Norway.
**************************************************************************
*/
package com.synchrona.jred;

import com.synchrona.jred.irlap.ConnectionInformation;
import com.synchrona.jred.irlap.DiscoveryInformation;
import com.synchrona.jred.irlap.iIrLAPListener;
import com.synchrona.jred.irlap.IrLAPContext;
import com.synchrona.jred.irlap.IrLAPFramer;
import com.synchrona.jred.TinyTP;
import com.synchrona.jred.IrOBEX;
import com.synchrona.util.Log;
import com.synchrona.util.Utilities;
import java.io.FileOutputStream;
import java.io.FileNotFoundException;
import java.io.PrintWriter;
import javax.comm.CommPortIdentifier;
import javax.comm.NoSuchPortException;
import javax.comm.PortInUseException;
import javax.comm.SerialPort;
import javax.comm.UnsupportedCommOperationException;

public class Test implements Runnable {
	private static final String PORT_NAME_PROPERTY = "serialPort";

	private boolean      m_bDoLogging;
	private IrLAPContext m_irlap;
	private IrLMP        _irlmp;
	private Log          m_log;

	public static void main(String [] astrArgs) {
		Test t = new Test();
		t.run();
	}

	public void run() {
		String portName = "(uninitialized)";

		try {
			portName = getPortName();

			PrintWriter        logfile = new PrintWriter(new FileOutputStream("irlap.txt"), true);
			m_log                      = new Log(logfile);

			IrLAPContext       irlap   = new IrLAPContext(m_log);
			CommPortIdentifier portId  = CommPortIdentifier.getPortIdentifier(portName);
			SerialPort         port   = (SerialPort) portId.open("JRed", 2000);
			IrLAPFramer        framer = new IrLAPFramer(m_log, port);

			m_irlap      = irlap;
			m_bDoLogging = true;

			_irlmp = new IrLMP(m_log);
			_irlmp.setIrLAPContext(irlap);

			irlap.setFramer(framer);
			irlap.addIrLAPListener(_irlmp);

			// For now, add IrOBEX at offset 5. IrOBEX uses TinyTP
			// for flow control. It should really be hidden inside
			// IrOBEX, because IrLMP doesn't care.
			_irlmp.addService(new TinyTP(m_log, _irlmp, new IrOBEX(m_log)));

			Thread t = new Thread(framer);
			t.start();

		} catch ( NoSuchPortException noSuchPort ) {
			m_log.error("Text", "No port named " + portName + ": " + noSuchPort);

			System.err.println("No port named " + portName + ": " + noSuchPort);
			noSuchPort.printStackTrace(System.err);
		} catch ( PortInUseException portInUse ) {
			m_log.error("Test", portName + " is in use: " + portInUse);

			System.err.println(portName + " is in use: " + portInUse);
			portInUse.printStackTrace(System.err);
		} catch ( FileNotFoundException fileNotFound ) {
			System.err.println("Couldn't open log file 'irlap.txt':" + fileNotFound);
			fileNotFound.printStackTrace(System.err);
		} catch ( Exception e ) {
			m_log.error("Test", e.toString());
			System.err.println(e);
			e.printStackTrace(System.err);
		}
	}

	private String getPortName() throws Exception {
		String portName = System.getProperty(PORT_NAME_PROPERTY);
		if ( null == portName ) {
			m_log.error("Test", "(getPortName) " + PORT_NAME_PROPERTY + " is undefined.");
			throw new Exception(PORT_NAME_PROPERTY + " is undefined.");
		}
		return portName;
	}
}

⌨️ 快捷键说明

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