亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频

? 歡迎來到蟲蟲下載站! | ?? 資源下載 ?? 資源專輯 ?? 關于我們
? 蟲蟲下載站

?? pmac.java

?? j2me實現的移動機器人代碼(Java實現)
?? JAVA
字號:
/*
 * Created on 2004-12-2
 *
 * This class is a wrap class for PMAC connected with the PC
 * through the serial port.
 */
package cie.mobile.pmac;

import java.io.IOException;
import java.io.Reader;
import java.util.Vector;
import javax.comm.SerialPort;
import name.lxm.comm.*;

/**
 * The encapsulated class for the PMAC interface
 * 
 * @author Richard Lee (lxm_zju@yahoo.com.cn)
 */
public class Pmac {
    /**Serial Port Name, Such as COM1, COM2, etc */
    private String commName;
    /** Serial Communication Mode, Block or Use Event Handler */
    private int mode;
    /** the mode using blocking reading/writing method from/to the stream */
    public static final int BLOCKING_MODE = 1;
    /** the mode using the serial port event handler for recieving data, not implemented yet. */
    public static final int NON_BLOCKING_MODE = 2;
    /** State ready for command */
    public static final int STATE_READY = 1;
    /** State ready for power off */
    public static final int STATE_OFFLINE = 2;

    //listeners
    private Vector listeners = new Vector();
    //serial port
    private CommSerialPort comm;
    //state
    private int state = 0;
    //buffer to receive port response
    private byte[] buf = new byte[32];
    //regist itself
    private static Pmac thePmac = null;

    /**
     * Default Contructor. <BR>
     * The Card will be initialized and is ready for command. <BR>
     * 
     * @throws PMACException
     *  
     */
    private Pmac() throws PMACException {
        this(BLOCKING_MODE);
    }

    /**
     * Constructor The Card will be initialized and is ready for command.
     * 
     * @param mode
     *            there are two choice: blocking method or non-block method
     * @throws PMACException
     */
    private Pmac(int mode) throws PMACException {
        this.mode = mode;
        //init();
    }

    /**
     * Initialize the serial port connected with the PMAC Card. Initialize the
     * PMAC Card, to make it ready for motion control
     * 
     * @throws PMACException
     */
    public void init(String com) throws PMACException {
        try {
            //load requested serial port
	    commName = com;
            comm = CommPortFactory.getSerialPort(commName, "pmac");
            //set the default parameters
            comm.setBaudrate(9600);
            comm.setDataBits(SerialPort.DATABITS_8);
            comm.setParity(SerialPort.PARITY_NONE);
            comm.setStopBits(SerialPort.STOPBITS_1);
            //open the serial port
            comm.open();
        } catch (Exception e) {
            throw new PMACException("Communication With PMAC Error.");
        }
        //sending commands to initialize the PMAC Card
	try{
		initCard();
		System.out.println("Card has been initialized!");
	}
	catch(IOException e){
		throw new PMACException(e.getMessage());
	}
	catch(CommPortTimedOutException e)
	{
		throw new PMACException(e.getMessage());
	}
    }

    /**
     * Put the PMAC Code here, such as the program to be downloaded to the PMAC
     * Having not been implemented.
     */
    private void initCard() throws IOException, CommPortTimedOutException
    {
    	int t=0;
	while(t<3)
	{
		String resp = sendCommandLine("a");
		//comm.writeLine("a");
		//comm.wait4DataReady();
		//int i = comm.readBytes(buf);
		if(resp.length() == 0)
		{
			sendCommandLine("#1HMZ#2HMZ");
			break;	
		}
		t++;
	}
	if(t ==3)
		throw new IOException ("Initial Pmac Card Failed.");
    }

    /**
     * <p>Send a command to PMAC.</p>
     * <p>Attention!May Get Blocked!</p>
     * 
     * @param cmd
     * @return a string contains the return message
     * @throws IOException
     * @throws CommPortTimedOutException
     */
    public String sendCommandLine(String cmd) throws IOException, CommPortTimedOutException {
        comm.writeLine(cmd);
	comm.wait4DataReady();
	String msg = comm.readLine(6);
        dispatchLog(cmd, true);
	return msg;
    }

    /**
     * Read message from PMAC <br>
     * This is a blocking method <br>
     * 
     * @return A Line Message
     * @throws CommPortTimedOutException
     * @throws IOException
     */
    public String getResponseMessage() throws IOException,
            CommPortTimedOutException {
        int c;
	comm.wait4DataReady();
	String s = comm.readLine(6);
        dispatchLog(s, false);
        return s;
    }

    /**
     * Sending data to registered listeners
     * @param s
     */
    private void dispatchLog(String s, boolean b) {
        if (b)//send message to PMAC
        {
		//System.out.println("Sended: " + s);
            for (int i = 0; i < listeners.size(); i++) {
                ((PmacListener) listeners.get(i)).msgSend(s);
            }
        } else { //get message from PMAC
		//System.out.println("Recieved: " + s);
            for (int i = 0; i < listeners.size(); i++) {
                ((PmacListener) listeners.get(i)).msgRecieved(s);
            }
        }
    }

    /**
     * Add listener for communication data probe
     * @param l the listener
     */
    public void addPmacListener(PmacListener l) {
        listeners.addElement(l);
    }

    /**
     * remove listener for communication data probe
     * @param l 
     * 			the listener
     */
    public void removePmacListener(PmacListener l) {
        listeners.removeElement(l);
    }

    /**
     * PMAC is an multi-axis controller. This method is used to querry the
     * current position of the specified axis. Do NOT forget the returned value
     * are in the unit of PMAC. You should scale it very carefully. This is one
     * the of on-line command provided by PMAC.
     * 
     * @param axis
     *            which axis (motor) you want to querry
     * @return position of specified axis, in the unit of PMAC
     * @throws IOException
     * @throws CommPortTimedOutException
     */
    public double getAxisPosition(int axis) throws IOException {
        String s = "#" + axis + "P";
        String resp;
        try {
		resp = sendCommandLine(s);
        } catch (CommPortTimedOutException e) {
            throw new IOException("No response from PMAC.");
        }
	if(resp.length() > 0)
		return Double.parseDouble(resp);
	else 
		throw new IOException("Empty string responsed from pmac.");
    }

    /**
     * Drive Specified Axis move a specified distance. The distance can be
     * negtive. One of the online motor command.
     * 
     * @param axis
     *            which axis to drive
     * @param distance
     *            how long would you want to go
     * @throws IOException
     * @throws CommPortTimedOutException
     */
    public void moveRelative(int axis, long distance) throws IOException, CommPortTimedOutException
    {
        String s = "#" + Integer.toString(axis) + "J:"
                + Long.toString(distance);
        sendCommandLine(s);
    }

    /**
     * Drive Specified Axis to Specified Position One of the online motor
     * command.
     * 
     * @param axis
     *            which axis to drive
     * @param position
     *            Where do you want to go?
     * @throws IOException
     */
    public void moveToPos(int axis, long position) throws IOException, CommPortTimedOutException
   {
        String s = "#" + Integer.toString(axis) + "J="
                + Long.toString(position);
        sendCommandLine(s);
    }

    /**
     * Move back to last position (online command)
     * 
     * @param axis
     *            which axis do you want to drive
     * @throws IOException
     */
    public void moveToLastPos(int axis) throws IOException, CommPortTimedOutException
   {
        String s = "#" + Integer.toString(axis) + "J=";
        sendCommandLine(s);
    }

    /**
     * Drive specified axis move infinately.
     * 
     * @param axis
     *            which axis to drive
     * @param dir
     *            the direction, can be any value of positive or negtive
     * @throws IOException
     */
    public void move(int axis, int dir) throws IOException, CommPortTimedOutException {
        String s;
        if (dir > 0)
            s = "#" + Integer.toString(axis) + "J+";
        else
            s = "#" + Integer.toString(axis) + "J-";
        sendCommandLine(s);
    }

    /**
     * Download a program to PMAC and Run it
     * 
     * @param r
     *            the reader where script can be found
     * @param autoStart
     *            automatic run this program?
     */
    public void runProgram(Reader r, boolean autoStart) {

    }

    /** 
     * Get the communicating serial port for later reference
     * @return serial commnuication port object
     */
    public CommSerialPort getCommunicationPort() {
        return comm;
    }

    /**
     * Get the global unique PMAC object
     * @return pmac object
     * @throws PMACException
     */
    public static Pmac getTheMobilePmac() throws PMACException {
        if (thePmac == null) {
            thePmac = new Pmac();
        }
        return thePmac;
    }
    
    /**
     * Stop moving immediately
     * @param axis
     * @throws IOException
     */
    public void stop(int axis) throws IOException,CommPortTimedOutException
    {
        sendCommandLine("#" + Integer.toString(axis) + "j/");
    }
}

?? 快捷鍵說明

復制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號 Ctrl + =
減小字號 Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
日韩成人伦理电影在线观看| 欧美一区二区成人| 欧美成人激情免费网| 国产精品三级视频| 日本人妖一区二区| 色综合咪咪久久| 国产亚洲精品资源在线26u| 一区二区三区精品视频在线| 国产麻豆视频精品| 欧美精品精品一区| 一区二区三区免费网站| 国产剧情在线观看一区二区| 欧美精品久久久久久久久老牛影院| 国产精品日产欧美久久久久| 捆绑变态av一区二区三区| 欧美午夜在线一二页| 国产精品毛片大码女人| 国产激情视频一区二区三区欧美| 91精品国产高清一区二区三区蜜臀| 亚洲综合色视频| 91一区二区三区在线播放| 日本一区二区在线不卡| 国产呦精品一区二区三区网站| 欧美一区二区三区四区视频| 日日夜夜精品视频免费| 欧美午夜免费电影| 亚洲在线视频免费观看| 在线免费观看日本欧美| 日韩电影一区二区三区四区| 欧美色男人天堂| 亚洲一二三四久久| 欧美日韩小视频| 午夜精品福利在线| 制服视频三区第一页精品| 亚洲18色成人| 91精品国产免费| 免费不卡在线视频| 精品成人a区在线观看| 紧缚奴在线一区二区三区| 久久色在线观看| 福利电影一区二区| 亚洲人亚洲人成电影网站色| 色婷婷精品久久二区二区蜜臀av| 一区二区三区欧美视频| 欧美高清视频一二三区| 久久99精品久久久| 日本一区二区三区高清不卡 | 久久九九久久九九| 国产成人综合在线| 综合色中文字幕| 欧美性一二三区| 美女精品一区二区| 国产精品视频线看| 欧美四级电影网| 欧美日韩国产电影| 蜜臀国产一区二区三区在线播放| 欧美精品一区二区久久婷婷| www.亚洲人| 香蕉久久一区二区不卡无毒影院| 精品日韩一区二区| 99精品黄色片免费大全| 偷拍亚洲欧洲综合| 国产喂奶挤奶一区二区三区| 色综合久久久久综合体| 美女久久久精品| 亚洲丝袜另类动漫二区| 日韩色视频在线观看| 成人性视频免费网站| 亚洲高清免费观看| 欧美韩日一区二区三区四区| 欧美日韩激情在线| 成人涩涩免费视频| 日韩成人一级大片| 中文字幕佐山爱一区二区免费| 欧美一区二区三区人| www.66久久| 狠狠色丁香久久婷婷综| 亚洲日本va午夜在线影院| 精品人在线二区三区| 欧美亚洲禁片免费| 成人一区二区三区视频在线观看| 三级成人在线视频| 亚洲欧美日本韩国| 国产午夜亚洲精品理论片色戒| 欧美日韩精品福利| 91美女福利视频| 国产精品一品视频| 青青草97国产精品免费观看 | 国产精品福利电影一区二区三区四区| 欧美日韩视频专区在线播放| youjizz国产精品| 国产一区二区三区黄视频| 婷婷久久综合九色综合绿巨人| 国产精品精品国产色婷婷| 欧美成人官网二区| 91精品国产综合久久精品app| 色综合中文综合网| 91视频在线看| 国产成人高清在线| 国产在线国偷精品免费看| 免费观看在线综合色| 偷偷要91色婷婷| 亚洲亚洲人成综合网络| 一区二区三区在线不卡| 中文字幕日韩一区二区| 国产精品视频观看| 国产亚洲精品资源在线26u| 精品日韩在线观看| 精品少妇一区二区三区视频免付费| 欧美日韩成人在线| 欧美日韩国产免费一区二区| 欧美最猛黑人xxxxx猛交| 色综合天天综合网天天狠天天| 欧美一级黄色片| 日韩情涩欧美日韩视频| 欧美成人一区二区三区在线观看 | 97成人超碰视| a亚洲天堂av| 一本到高清视频免费精品| 91在线视频在线| 91久久精品一区二区| 日本久久电影网| 在线观看一区日韩| 欧美精品在线观看一区二区| 69久久夜色精品国产69蝌蚪网| 日韩视频永久免费| 国产亚洲欧美日韩在线一区| 中文字幕第一区| 亚洲精品成a人| 日日摸夜夜添夜夜添亚洲女人| 日本成人中文字幕在线视频| 狠狠色狠狠色综合| 成人av免费在线观看| 色88888久久久久久影院按摩| 欧美喷水一区二区| 精品国产凹凸成av人导航| 国产日韩高清在线| 亚洲日本在线a| 奇米影视一区二区三区小说| 国产精品夜夜嗨| 色综合咪咪久久| 欧美一级午夜免费电影| 国产欧美一区二区三区沐欲| 亚洲黄网站在线观看| 日本欧美一区二区三区| 成人午夜激情片| 欧美三级电影网站| 首页国产欧美久久| 国产精品亚洲一区二区三区妖精 | 国产一区二区三区美女| 99免费精品视频| 欧美一区二区播放| 国产精品久久一卡二卡| 日韩精品电影在线| 成人av网站在线观看| 91麻豆精品国产91| 1区2区3区国产精品| 秋霞成人午夜伦在线观看| 成人听书哪个软件好| 51精品秘密在线观看| 中文字幕亚洲视频| 久久精品国内一区二区三区| 91麻豆国产福利在线观看| 日韩一区二区麻豆国产| 亚洲免费在线观看视频| 国产在线看一区| 欧美日韩一区视频| 国产精品灌醉下药二区| 久久99九九99精品| 欧美三级视频在线观看| 国产精品国产馆在线真实露脸| 免费成人在线观看| 欧美视频在线一区二区三区| 亚洲国产精品传媒在线观看| 欧美a一区二区| 欧美日韩一区二区三区不卡| 国产精品乱人伦一区二区| 狠狠色丁香婷综合久久| 欧美肥大bbwbbw高潮| 亚洲视频一二三| 成人午夜激情视频| 国产欧美视频一区二区三区| 久久精品国产亚洲aⅴ| 4hu四虎永久在线影院成人| 亚洲国产精品久久人人爱蜜臀 | 日韩精品久久久久久| 91九色02白丝porn| 亚洲色图清纯唯美| 成人免费视频caoporn| 久久毛片高清国产| 美脚の诱脚舐め脚责91| 91麻豆精品国产91久久久使用方法 | 国产精品私人自拍| 国产成人啪免费观看软件| 2欧美一区二区三区在线观看视频| 日韩黄色小视频| 欧美精品色综合| 人人爽香蕉精品| 欧美大白屁股肥臀xxxxxx| 卡一卡二国产精品|