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

📄 serialport.java

📁 控制移到机器人的例子程序
💻 JAVA
字号:
import java.lang.*;

/*
This serial class is for you to communicate through the radio modems.
Some details you should remember:
1) the baud rate set up for the modems is 115200 (that is choice 5)
2) the port you specify should be either 1 (COM1), which is the serial
   port we ordinarily use to communicate with the robot; or more correctly
   port 4 (COM4), which is where the pcmcia serial port is placed that you
   will be plugging the radio modem into!
   
3) When both radio modems are on (green lights continuous), then you
    are ready to establish a link. From either modem (the other one 
    doesn't even need to be plugged into a computer), you need to
    type "wms1" (not the quotes, just the stuff inside the quotes), then
    hit return. The way to do this is to send the following bytes 
    to the radio modem: 119 , 109 , 115 , 49 , 13. Once you do this,
    the steady red light should light up on both modems and they're in data
    mode. Don't forget to read all the echo characters off using read-byte
    before you start using the comm link. enjoy.
    
4) Do NOT send the character 124 ('|') across the radio modems. It is a 
    control, escape character if you send it 3 times in a row, followed
    by the return key.
*/


public synchronized class serialPort extends java.lang.Object
{  
    // open serial port at specified baud with other appropriate parameters.
    // returns:
    // 0 on success
    // -1 on failure to open serial port
    // -2 on failure to read port state
    // -3 on failure to set port state
    // coms are: 1 = "COM1"; 2 = "COM2" et cetera    
    // baud rates are: 1 = 9600; 2=19200; 3=38400; 4=57600; 5=115200; 6=230400
    public native int openSerial(int comNum, int baudSpec);
    public native int closeSerial();
    // returns 0 on success or -1 on failure to send byte
    public native int sendByte(int theByte);
    // initialTimeout is measured in milliseconds //
    // returns -6 on failure to set timeout, 0 on success
    public native int setReadTimeout(int initialTimeout);
    // returns -1 in error or timeout, else returns int between 0 and 255
    public native int readByte();
   
   static {
    System.loadLibrary("sserial");
   }
    
}

⌨️ 快捷键说明

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