首页 新闻 论坛 群组 Blog 文档 下载 读书 Tag 网摘 搜索 .NET Java 游戏 视频 人才 外包 培训 数据库 书店 程序员
中国软件网
欢迎您:游客 | 登录 注册 帮助
  • JAVA 串口通信 [已结贴,结贴人:cxxlp]
    进入用户个人空间
    加为好友
    发送私信
    在线聊天
    • cxxlp
    • 等级:
    • 可用分等级:
    • 总技术分:
    • 总技术分排名:
    • 揭贴率:
    发表于:2008-08-21 20:40:20 楼主
    谁有这方面的程序,,可以给我一份,,我想要具体的运行方式,,和代码
    50  修改 删除 举报 引用 回复
    进入用户个人空间
    加为好友
    发送私信
    在线聊天
    • kokobox
    • 等级:
    • 可用分等级:
    • 总技术分:
    • 总技术分排名:
    发表于:2008-08-21 23:14:011楼 得分:50
    程序:
    Java code
    /* * * IMU.java 1.0 * Main Program for Serial Communication * * Created: March 27, 2001 * * Author : Qingye Jiang (John) * American GNC Corporation * 888 Easy St, Simi Valley CA 93065-1812 * * Contact: (805) 582-0582 (Tel), (805) 582-0098 (Fax) * qjiang@tsinghua.edu * */ import java.io.*; class IMU { public static void main(String[] args) { //TO DO: Add your JAVA codes here File ComPort = new File("COM1"); SerialBuffer SB = new SerialBuffer(); ReadSerial r1 = new ReadSerial(SB, ComPort); ReadBuffer r2 = new ReadBuffer(SB); WriteSerial r3 = new WriteSerial(ComPort); r1.start(); r2.start(); r3.start(); } } /* * * ReadBuffer.java 1.0 * Program to Read the Serial Buffer * * Created: March 27, 2001 * * Author : Qingye Jiang (John) * American GNC Corporation * 888 Easy St, Simi Valley CA 93065-1812 * * Contact: (805) 582-0582 (Tel), (805) 582-0098 (Fax) * qjiang@tsinghua.edu * */ import java.io.*; public class ReadBuffer extends Thread { private SerialBuffer ComBuffer; public ReadBuffer(SerialBuffer SB) { ComBuffer = SB; } public void run() { String Msg; while (true) { Msg = ComBuffer.GetMsg(); System.out.println(Msg); } } } /* * * ReadSerial.java 1.0 * Program to read characters from the serial port and put it * to the buffer * * Created: March 27, 2001 * * Author : Qingye Jiang (John) * American GNC Corporation * 888 Easy St, Simi Valley CA 93065-1812 * * Contact: (805) 582-0582 (Tel), (805) 582-0098 (Fax) * qjiang@tsinghua.edu * */ import java.io.*; public class ReadSerial extends Thread { private SerialBuffer ComBuffer; private File ComPort; public ReadSerial(SerialBuffer SB, File Port) { ComBuffer = SB; ComPort = Port; } public void run() { int c; try { FileReader in = new FileReader(ComPort); while (true) { c = in.read(); ComBuffer.PutChar(c); } try { FileReader in = new FileReader(ComPort); while (true) { c = in.read(); ComBuffer.PutChar(c); } } catch (IOException e) {} } } /* * * SerialBuffer.java 1.0 * Class that implements the serial buffer * * Created: March 27, 2001 * * Author : Qingye Jiang (John) * American GNC Corporation * 888 Easy St, Simi Valley CA 93065-1812 * * Contact: (805) 582-0582 (Tel), (805) 582-0098 (Fax) * qjiang@tsinghua.edu * */ public class SerialBuffer { private String Content = ""; private String CurrentMsg, TempContent; private boolean available = false; public synchronized String GetMsg() { int SepMark; if ((SepMark = Content.indexOf('*')) == -1) { available = false; while (available == false) { try { wait(); } catch (InterruptedException e) { } } SepMark = Content.indexOf('*'); } CurrentMsg = Content.substring(0, SepMark); TempContent = Content.substring(SepMark+1); Content = TempContent; notifyAll(); return CurrentMsg; } public synchronized void PutChar(int c) { Character d = new Character((char) c); Content = Content.concat(d.toString()); if (c == '*') { available = true; } notifyAll(); } } /* * * WriteSerial.java 1.0 * Program to send a character to the serial port * * Created: March 27, 2001 * * Author : Qingye Jiang (John) * American GNC Corporation * 888 Easy St, Simi Valley CA 93065-1812 * * Contact: (805) 582-0582 (Tel), (805) 582-0098 (Fax) * qjiang@tsinghua.edu * */ import java.io.*; public class WriteSerial extends Thread { private SerialBuffer ComBuffer; private File ComPort; public WriteSerial(File Port) { ComPort = Port; } public void run() { int c; try { FileWriter out = new FileWriter(ComPort); while (true) { out.write('*'); } } catch (IOException e) { System.out.println(e.getMessage()); } } } /* * * SendCom.java 1.0 * * Project: Java Based Information Exchange Support System * Onboard Plug-in System * Sending data through serial port * * Created: March 15, 2001 * * Author : Qingye Jiang (John) * American GNC Corporation * 888 Easy St, Simi Valley CA 93065-1812 * * Contact: (805) 582-0582 (Tel), (805) 582-0098 (Fax) * */ import java.io.*; public class SendCom { public static void main(String[] args) { File OutFile = new File("SEND.TXT"); File ComPort = new File("COM2"); int c; try { FileReader in = new FileReader(OutFile); FileWriter out = new FileWriter(ComPort); while ((c = in.read()) != -1) out.write(c); in.close(); out.close(); } catch (IOException e) {} } }



    详解地址:http://www.qqread.com/java/c192396600.html
    修改 删除 举报 引用 回复
    进入用户个人空间
    加为好友
    发送私信
    在线聊天
    • cxxlp
    • 等级:
    • 可用分等级:
    • 总技术分:
    • 总技术分排名:
    发表于:2008-08-22 08:26:422楼 得分:0
    具体的测试方法怎么来啊,,,我也不是很清楚,,啊,
    修改 删除 举报 引用 回复

    网站简介广告服务网站地图帮助联系方式诚聘英才English 问题报告
    北京创新乐知广告有限公司 版权所有 京 ICP 证 070598 号
    世纪乐知(北京)网络技术有限公司 提供技术支持
    Copyright © 2000-2008, CSDN.NET, All Rights Reserved