Best Projects

Bug Trackingsystem,Books online shopping,college management system,HR management system,Internet banking,Online chat room ,Online exam,Telephone billing system,Banking application,ATM database,airways reservation system,virtual network computing ,calculator,SMTP(simple mail transfer protocol)

Parellel Port Viewer





/*
* ParallelPort.class must be in parport subdirectory.
* UserPort must be installed.
* parport.dll must be in path directory like C:\Windows\System32
* or C:\Program Files\j2sdk_nb\j2sdk1.4.2\bin or in the same directory which
* contains paraport subdirectory with ParallelPort.class.
*/

package parport;
public class ParallelPort {
private static final int lpt1DataPortAddr=0x378; //LPT1 data port address
private static final int lpt1StatusPortAddr=lpt1DataPortAddr+1; //LPT1 status port address
private static final int lpt1ControlPortAddr=lpt1DataPortAddr+2; //LPT1 control port address
private static final int lpt2DataPortAddr=0x278; //LPT2 data port address
private static final int lpt2StatusPortAddr=lpt2DataPortAddr+1; //LPT2 status port address
private static final int lpt2ControlPortAddr=lpt2DataPortAddr+2; //LPT2 control port address
private static final int LPT1=1; //LPT1 Constant
private static final int LPT2=2; //LPT2 Constant
private static int lpt1Data; //Data temporary variable of LPT1
private static int lpt1Status; //Status temporary variable of LPT1
private static int lpt1Control; //Control temporary variable of LPT1
private static int lpt2Data; //Data temporary variable of LPT2
private static int lpt2Status; //Status temporary variable of LPT2
private static int lpt2Control; //Control temporary variable of LPT2
private static boolean lpt1Port[]=new boolean[18];
private static boolean lpt2Port[]=new boolean[18];

//NATIVE Functions
private static native int readOneByte (int address);
private static native void writeOneByte (int address, int oneByte);
static {System.loadLibrary("parport");}
//Main Read/Write Functions
private static int readOneByteFromPort (int address) { //Native function that reads a byte from port
return (ParallelPort.readOneByte(address));
}
private static void writeOneByteToPort (int address,int byteToSend) { //Native function that writes a byte to port
ParallelPort.writeOneByte (address,byteToSend);
}
//My Port Functions
private static void readFromLPT1(){
boolean temp1[]=new boolean[24];
lpt1Data=readOneByteFromPort(lpt1DataPortAddr);
lpt1Status=readOneByteFromPort(lpt1StatusPortAddr);
lpt1Control=readOneByteFromPort(lpt1ControlPortAddr);
for (int i=0;i<8;i++){
temp1[i]=((lpt1Data & (1< temp1[i+8]=((lpt1Status & (1< temp1[i+16]=((lpt1Control & (1< }
lpt1Port[0]=temp1[21];
lpt1Port[1]=temp1[16];
lpt1Port[2]=temp1[0];
lpt1Port[3]=temp1[1];
lpt1Port[4]=temp1[2];
lpt1Port[5]=temp1[3];
lpt1Port[6]=temp1[4];
lpt1Port[7]=temp1[5];
lpt1Port[8]=temp1[6];
lpt1Port[9]=temp1[7];
lpt1Port[10]=temp1[14];
lpt1Port[11]=temp1[15];
lpt1Port[12]=temp1[13];
lpt1Port[13]=temp1[12];
lpt1Port[14]=temp1[17];
lpt1Port[15]=temp1[11];
lpt1Port[16]=temp1[18];
lpt1Port[17]=temp1[19];
}
private static void writeToLPT1(){
boolean temp1[]=new boolean[24];
lpt1Data=readOneByteFromPort(lpt1DataPortAddr);
lpt1Status=readOneByteFromPort(lpt1StatusPortAddr);
lpt1Control=readOneByteFromPort(lpt1ControlPortAddr);
for (int i=0;i<8;i++){
temp1[i]=((lpt1Data & (1< temp1[i+8]=((lpt1Status & (1< temp1[i+16]=((lpt1Control & (1< }
temp1[21]=lpt1Port[0];
temp1[16]=lpt1Port[1];
temp1[0]=lpt1Port[2];
temp1[1]=lpt1Port[3];
temp1[2]=lpt1Port[4];
temp1[3]=lpt1Port[5];
temp1[4]=lpt1Port[6];
temp1[5]=lpt1Port[7];
temp1[6]=lpt1Port[8];
temp1[7]=lpt1Port[9];
temp1[14]=lpt1Port[10];
temp1[15]=lpt1Port[11];
temp1[13]=lpt1Port[12];
temp1[12]=lpt1Port[13];
temp1[17]=lpt1Port[14];
temp1[11]=lpt1Port[15];
temp1[18]=lpt1Port[16];
temp1[19]=lpt1Port[17];
lpt1Data=0;
lpt1Status=0;
lpt1Control=0;
for (int i=0;i<8;i++){
lpt1Data+=(temp1[i]==true)?(1< lpt1Status+=(temp1[i+8]==true)?(1< lpt1Control+=(temp1[i+16]==true)?(1< }
writeOneByteToPort(lpt1DataPortAddr,lpt1Data);
writeOneByteToPort(lpt1StatusPortAddr,lpt1Status);
writeOneByteToPort(lpt1ControlPortAddr,lpt1Control);
}
private static void readFromLPT2(){
boolean temp2[]=new boolean[24];
lpt2Data=readOneByteFromPort(lpt2DataPortAddr);
lpt2Status=readOneByteFromPort(lpt2StatusPortAddr);
lpt2Control=readOneByteFromPort(lpt2ControlPortAddr);
for (int i=0;i<8;i++){
temp2[i]=((lpt2Data & (1< temp2[i+8]=((lpt2Status & (1< temp2[i+16]=((lpt2Control & (1< }
lpt2Port[0]=temp2[21];
lpt2Port[1]=temp2[16];
lpt2Port[2]=temp2[0];
lpt2Port[3]=temp2[1];
lpt2Port[4]=temp2[2];
lpt2Port[5]=temp2[3];
lpt2Port[6]=temp2[4];
lpt2Port[7]=temp2[5];
lpt2Port[8]=temp2[6];
lpt2Port[9]=temp2[7];
lpt2Port[10]=temp2[14];
lpt2Port[11]=temp2[15];
lpt2Port[12]=temp2[13];
lpt2Port[13]=temp2[12];
lpt2Port[14]=temp2[17];
lpt2Port[15]=temp2[11];
lpt2Port[16]=temp2[18];
lpt2Port[17]=temp2[19];
}
private static void writeToLPT2(){
boolean temp2[]=new boolean[24];
lpt2Data=readOneByteFromPort(lpt2DataPortAddr);
lpt2Status=readOneByteFromPort(lpt2StatusPortAddr);
lpt2Control=readOneByteFromPort(lpt2ControlPortAddr);
for (int i=0;i<8;i++){
temp2[i]=((lpt2Data & (1< temp2[i+8]=((lpt2Status & (1< temp2[i+16]=((lpt2Control & (1< }
temp2[21]=lpt2Port[0];
temp2[16]=lpt2Port[1];
temp2[0]=lpt2Port[2];
temp2[1]=lpt2Port[3];
temp2[2]=lpt2Port[4];
temp2[3]=lpt2Port[5];
temp2[4]=lpt2Port[6];
temp2[5]=lpt2Port[7];
temp2[6]=lpt2Port[8];
temp2[7]=lpt2Port[9];
temp2[14]=lpt2Port[10];
temp2[15]=lpt2Port[11];
temp2[13]=lpt2Port[12];
temp2[12]=lpt2Port[13];
temp2[17]=lpt2Port[14];
temp2[11]=lpt2Port[15];
temp2[18]=lpt2Port[16];
temp2[19]=lpt2Port[17];
lpt2Data=0;
lpt2Status=0;
lpt2Control=0;
for (int i=0;i<8;i++){
lpt2Data+=(temp2[i]==true)?(1< lpt2Status+=(temp2[i+8]==true)?(1< lpt2Control+=(temp2[i+16]==true)?(1< }
writeOneByteToPort(lpt2DataPortAddr,lpt2Data);
writeOneByteToPort(lpt2StatusPortAddr,lpt2Status);
writeOneByteToPort(lpt2ControlPortAddr,lpt2Control);
}

/*
* Returns boolean array that contains LPT1 pin potentials of 17 pins.
* Zero's cell of an array contains Control's 5th bit
*/
public static synchronized boolean[] getLPT1Port(){
boolean temp1[]=new boolean[18];
readFromLPT1();
for(int i=0;i<18;i++) temp1[i]=lpt1Port[i];
return(temp1);
}
/*
* Returns boolean array that contains LPT2 pin potentials of 17 pins.
* Zero's cell of an array contains Control's 5th bit
*/
public static synchronized boolean[] getLPT2Port(){
boolean temp2[]=new boolean[18];
readFromLPT2();
for(int i=0;i<18;i++) temp2[i]=lpt2Port[i];
return(temp2);
}
/*
* Returns boolean array that contains LPT1 pin potentials of 17 pins
* after inverting an inverted pins (1,11,14,17)
* Zero's cell of an array contains Control's 5th bit
*/
public static synchronized boolean[] getLPT1PortWithNoInverted(){
boolean temp1[]=new boolean[18];
readFromLPT1();
for(int i=0;i<18;i++) temp1[i]=lpt1Port[i];
temp1[1]=(!temp1[1]);
temp1[11]=(!temp1[11]);
temp1[14]=(!temp1[14]);
temp1[17]=(!temp1[17]);
return(temp1);
}
/*
* Returns boolean array that contains LPT2 pin potentials of 17 pins
* after inverting an inverted pins (1,11,14,17)
* Zero's cell of an array contains Control's 5th bit
*/
public static synchronized boolean[] getLPT2PortWithNoInverted(){
boolean temp2[]=new boolean[18];
readFromLPT2();
for(int i=0;i<18;i++) temp2[i]=lpt2Port[i];
temp2[1]=(!temp2[1]);
temp2[11]=(!temp2[11]);
temp2[14]=(!temp2[14]);
temp2[17]=(!temp2[17]);
return(temp2);
}
/*
* Sets boolean array that contains LPT1 pin potentials of 17 pins.
* Zero's cell of an array contains Control's 5th bit
*/
public static synchronized void setLPT1Port(boolean lpt1PortParam[]){
if (lpt1PortParam.length==18){
for(int i=0;i<18;i++) lpt1Port[i]=lpt1PortParam[i];
writeToLPT1();
}
}
/*
* Sets boolean array that contains LPT2 pin potentials of 17 pins.
* Zero's cell of an array contains Control's 5th bit
*/
public static synchronized void setLPT2Port(boolean lpt2PortParam[]){
if (lpt2PortParam.length==18){
for(int i=0;i<18;i++) lpt2Port[i]=lpt2PortParam[i];
writeToLPT2();
}
}
/*
* Sets boolean array that contains LPT1 pin potentials of 17 pins
* after inverting an inverted pins (1,11,14,17)
* Zero's cell of an array contains Control's 5th bit
*/
public static synchronized void setLPT1PortWithNoInverted(boolean lpt1PortParam[]){
if (lpt1PortParam.length==18){
for(int i=0;i<18;i++) lpt1Port[i]=lpt1PortParam[i];
lpt1Port[1]=(!(lpt1Port[1]));
lpt1Port[11]=(!(lpt1Port[11]));
lpt1Port[14]=(!(lpt1Port[14]));
lpt1Port[17]=(!(lpt1Port[17]));
writeToLPT1();
}
}
/*
* Sets boolean array that contains LPT2 pin potentials of 17 pins
* after inverting an inverted pins (1,11,14,17)
* Zero's cell of an array contains Control's 5th bit
*/
public static synchronized void setLPT2PortWithNoInverted(boolean lpt2PortParam[]){
if (lpt2PortParam.length==18){
for(int i=0;i<18;i++) lpt2Port[i]=lpt2PortParam[i];
lpt2Port[1]=(!(lpt2Port[1]));
lpt2Port[11]=(!(lpt2Port[11]));
lpt2Port[14]=(!(lpt2Port[14]));
lpt2Port[17]=(!(lpt2Port[17]));
writeToLPT2();
}
}
}

No comments: