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

📄 java.txt

📁 java实现串口通信
💻 TXT
字号:
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);  
}  

}  

}  

/*  
*  
* WriteSerial.java 1.0  
* Program to send a star to the serial port every 5 seconds.  
*  
* 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 OutputStream ComPort;  

public WriteSerial(OutputStream Port)  
{  
        ComPort = Port;  
}  

public void run()  
{  

int c;  
try  
{  

while (true)  
{ 

ComPort.write('*');  
try  
{  
        wait(5000);  
} catch (InterruptedException e) { }  

}  

} 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) {}  

}  

}  

⌨️ 快捷键说明

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