Sunday, April 26, 2009

Use Pen drive as RAM (Vista/Windows 7)

Recently i came across an article that said that Pen Drive can be used to speed up windows vista.USB 2.0 and above, SD card, Compact Flash or any other massive portable flash drive can be used to speed up the working of vista using the ReadyBoost feature.

When a removable memory device such as a
USB flash drive is first inserted into a port, vista checks if it is fast enough to work with the Superfetch mechanism that ReadyBoost uses. If so,we are asked if we want the drive to be used for improving system performance. We can then choose to allocate part of a USB drive's memory to speed up performance and use the remainder to store files.





The performance is drastically improved.In some cases a system whose memory is increased from 512MB to 1 GB through the external plugged device can see the speed improving from 11 sec to 2 sec. The performance is even better in the case of laptop systems as laptops have a relatively low 'rpm's than the desktop systems.It also saves the battery power of the laptops.

Sunday, June 29, 2008

Serial Port Access using RXTX in JAVA

This is the sample code to access serial port using RXTX in java,,,,
the packages can be downloded from rxtx.org and to be placed in the locations specified in that link,,,,,




import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.OutputStreamWriter;
import java.sql.Date;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Enumeration;

import gnu.io.CommPortIdentifier;
import gnu.io.SerialPort;

public class Port {

private CommPortIdentifier portId;
private SerialPort port;
private OutputStreamWriter out;
private InputStreamReader in;

public void open(String comportUsed) {
try {

Enumeration portList;
String defaultPort;

String osname = System.getProperty("os.name", "").toLowerCase();
if (osname.startsWith("windows")) {
// windows
defaultPort = "COM1";
} else if (osname.startsWith("linux")) {
// linux
defaultPort = "/dev/ttyS0";
} else if (osname.startsWith("mac")) {
// mac
defaultPort = "????";
} else {
System.out
.println("Sorry, your operating system is not supported");

}

portList = CommPortIdentifier.getPortIdentifiers();
while (portList.hasMoreElements()) {
portId = (CommPortIdentifier) portList.nextElement();
if (portId.getPortType() == CommPortIdentifier.PORT_SERIAL) {
if (portId.getName().equals(comportUsed)) {
System.out.println("Found port: " + comportUsed);
break;
}
}
}

this.port = (SerialPort) this.portId.open(comportUsed, 2000);
port.setSerialPortParams(19200, SerialPort.DATABITS_8,
SerialPort.STOPBITS_1, SerialPort.PARITY_NONE);
in = new InputStreamReader(port.getInputStream());
out = new OutputStreamWriter(port.getOutputStream());
System.err.println("Port Open:Success");

} catch (Exception e) {
System.err.println("Port Open:Failed");
System.out.println("Port is already used from other application,");
System.out.println("Close that application and re-run this application");
}
}

private void write(String s) throws Exception {

out.write(s);
out.flush();
}

private void write(byte s) throws Exception {
out.write(s);
out.flush();
}

private void write(int s) throws Exception {
out.write(s);
out.flush();
}


private String read() throws Exception {
int n, i;
char c;
String answer = new String("");

for (i = 0; i <>
while (in.ready()) {
n = in.read();
if (n != -1) {
c = (char) n;
answer = answer + c;
Thread.sleep(1);
} else
break;
}
delay(1);
}


return answer;
}



private void delay(int a) {
try {
Thread.sleep(a);
} catch (InterruptedException e) {
}
}



public void close() throws Exception {
try {
port.close();
System.err.println("close port");
} catch (Exception e) {
System.err.println("Error: close port failed: " + e);
}
}


}