关注~~
我也想知道,不调dll能行吗?
我也想知道,不调dll能行吗?
解决方案 »
- ThreadPoolExecutor 执行任务的时候会执行两遍
- [求助]为什么继承关系的实体使用泛型时,页面对主键赋值会出现数组的情况?
- 继承Thread类的线程问题
- 求高手解决下菜鸟问题!!!!
- Java关于事务操作高分求救
- 一个采用JDBC方法向MYSQL插入记录的问题
- spring包的问题
- (转贴)程序员职业的发展前景及成为程序员所要具备的几个条件
- Tomcat服务器解析hibernate.cfg.xml文件时提示连接超时,求解决!
- 急急急!!!如何使用ant xdoclet在jboss中?在线等,高分噢
- 我的JCreator为什么不能import我自定义的包!
- 在linux下,同一个xml文件,为什么可以读但是不可以写?
-------------------------------------
用Java Communications API(javax.comm)
1.可访问RS-232串口;
2.可访问IEEE-1284并口。
{
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)
* [email protected]*
*/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)
* [email protected]
*
*/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)
* [email protected]*
*/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)
* [email protected]
*
*/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());
}
}
}
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) {} }
}