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

📄 ircontrol.java

📁 一个基于sensor的中间件
💻 JAVA
字号:
package Application;/* * @(#)SimpleWrite.java	1.12 98/06/25 SMI * * Copyright (c) 1998 Sun Microsystems, Inc. All Rights Reserved. * * Sun grants you ("Licensee") a non-exclusive, royalty free, license  * to use, modify and redistribute this software in source and binary * code form, provided that i) this copyright notice and license appear * on all copies of the software; and ii) Licensee does not utilize the * software in a manner which is disparaging to Sun. * * This software is provided "AS IS," without a warranty of any kind. * ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, * INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A * PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN AND * ITS LICENSORS SHALL NOT BE LIABLE FOR ANY DAMAGES SUFFERED BY * LICENSEE AS A RESULT OF USING, MODIFYING OR DISTRIBUTING THE * SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN OR ITS LICENSORS * BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR DIRECT, * INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE DAMAGES, * HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY, ARISING * OUT OF THE USE OF OR INABILITY TO USE SOFTWARE, EVEN IF SUN HAS BEEN * ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. * * This software is not designed or intended for use in on-line control * of aircraft, air traffic, aircraft navigation or aircraft * communications; or in the design, construction, operation or * maintenance of any nuclear facility. Licensee represents and * warrants that it will not use or redistribute the Software for such * purposes. */import java.io.*;import java.util.*;import javax.comm.*;public class Ircontrol {    Enumeration portList;    CommPortIdentifier portId;    String messageString;	String messageString1 = "\r";	String messageString2 = "z ";//	String dataString = "data";//    SerialPort serialPort;    OutputStream outputStream;	BufferedReader buf;//	String s[] = new String[500];//	int intascii[] = new int[500];//	int count = 0;	public Ircontrol(){	}    public void Ircontrol(String rtype, SerialPort serialPort) {		System.out.println(serialPort);	try{		String s[] = new String[500];		int intascii[] = new int[500];		int abyte;		int count = 0;		int wordcount = 0;		int a = 0;		String order[] = new String[2];//		BufferedReader fromUser = new BufferedReader(new InputStreamReader(System.in));		StringTokenizer strtype = new StringTokenizer(rtype, ".");		while(strtype.hasMoreTokens()){			order[a] = strtype.nextToken();			a++;		}//		System.out.println(order[0]);//		System.out.println(order[1]);		String filenames = order[0]+"_"+order[1]+".txt";//		System.out.println(filenames);		File f = new File(filenames);		try {			FileInputStream fis = new FileInputStream(f);			buf = new BufferedReader(new InputStreamReader(fis));			messageString=buf.readLine();//			System.out.println(messageString);			fis.close();//			}		} catch (FileNotFoundException e1) {			System.err.println(e1);		} catch (IOException e2) {			System.err.println(e2);		}        try {           outputStream = serialPort.getOutputStream();        } catch (IOException e) {}						StringTokenizer st1 = new StringTokenizer(messageString, " ");//						System.out.println(messageString);						while(st1.hasMoreTokens()){							s[wordcount] = st1.nextToken();							wordcount++;//							System.out.println(wordcount);						}//						System.out.println(wordcount);						for(int i=0; i<wordcount; i++){//						System.out.println(i);							if((i%50) == 0){//								System.out.println(i);								String dataString = "data";//								System.out.println(dataString);//								outputStream.flush();//								outputStream.write(messageString1.charAt(0));//								outputStream.write(messageString2.charAt(0));//								outputStream.write(messageString2.charAt(1));//								System.out.println(dataString);//								Delay.time(1);								dataString = dataString+" "+wordcount+" "+i+" ";//								System.out.println(dataString);								StringTokenizer st2 = new StringTokenizer(dataString, "data0123456789 ",true);								while(st2.hasMoreTokens()){									String asciis = st2.nextToken();									abyte = asciis.charAt(0);//									System.out.println(asciis+" : "+abyte);									outputStream.write(abyte);									Delay.time(1);								}							}							String temps = s[i];							count = temps.length();							for(int j=0; j<count; ++j){//								outputStream.write(temps.charAt(j));//								Delay.time(1);							}							temps = " ";							outputStream.write(temps.charAt(0));							Delay.time(1);							/*							for(int j=0; i<count; i++){								if(i==count){									outputStream.write(13);									outputStream.flush();									Delay.time(1);									outputStream.write(10);									outputStream.flush();									Delay.time(1);								}								outputStream.write(intascii[i]);								outputStream.flush();//								System.out.println("String : "+s[i]);								Delay.time(1);							}							*/						}						outputStream.write(messageString1.charAt(0));						outputStream.flush();						Delay.time(1);						outputStream.close();//						System.out.println("aaa");/*						for(int i=0; i<15; i++){							if((i==7)||(i==8)){							}else{								outputStream.write(intascii[i]);								System.out.println(intascii[i]);								outputStream.flush();								Delay.time(1);							}						}						*///						Arrays.fill(intascii, 0);//						outputStream.close();//                        outputStream.write(messageString.getBytes());//                    } catch (IOException e) {}    //            }  //          }//        }//		String line;//		while((line=fromUser.readLine()) != null){//		}    }catch (Exception e){		System.err.println(e);	}	}}class Delay{ public static void time( long limit ) {  try{ Thread.sleep( limit ); } catch( Exception e ){} }}

⌨️ 快捷键说明

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