Archive

Archive for 2013

Sharing dial-up Internet Connection in Local Network Using Router.

December 30th, 2013 No comments
    In this tutorial I am going to show you how to share your dial-up internet connection (like USB dongle,bluetooth modem etc) with other computers or devices present in the network.This comes handy when you have no other internet options for all your devices.You can use a router to share your internet connection through wireless with others.Here are the steps to be followed.

Step-I:
    Configure you router as below.I have taken an IP of 192.168.0.125 but you can take anyone  like 192.168.0.xxx.Set the netmask and IP range and save it.I have used one Netgear router.

  Then configure the connection you want to share as follows.Go to sharing tab and share the connection which looks like this..

 This will pop a dialog saying your LAN IP has been changed click OK and move to the LAN properties and set the IPV4 settings as follows
 

 Its done with your PC now suppose you want to connect to Internet from other PC using Wi-Fi or LAN change the adapter properties of Wi-Fi or LAN (That is you are using to connect) as shown below..

  
Thats it you have set up the network successfully. You can check it out.


Static IP setup for Raspberry PI

December 20th, 2013 No comments
Many time while using Raspberry PI people come across a situation that they have to connect their PI to the Internet through the Local n/ws.Usually a systemis assigned with IPs those are dynamic(DHCP) i.e. any IP is assigned to the device during the connection setup and that’s the case for PI also and it works fine also.But in certain cases yo may have to configure your PI with a static IP ,like suppose you want to make your PI a server.Here i have given the steps to add a static IP to your Pi.

   Open the terminal and type

                    cd  /etc/network

then

                    sudo pico interfaces

   Then change the content to this,where you will have to set the corresponding values depending upon your network.

                     auto lo

                     iface lo inet loopback

                     iface eth0 inet static
                                    address  xx.xx.xx.xx

                                    network xx.xx.xx.xx

                                    broadcast xx.xx.xx.xx

                                    gateway xx.xx.xx.xx

press

ctrl+x
 

and then

 y
 

to save and exit.

 

       Now we have to set the DNS and that is done by esiting the file resolv.conf.So you can edit it by

sudo nano /etc/resolv.conf

and add below shown to the file and save it like before.

nameserver xx.xx.xx.xx

Now reboot your system by giving command

                   

 reboot

That’s all you are ready to go.

RX-30 Finger Print Module Device Interfacing

December 13th, 2013 No comments
     Many of  you have must heard about the finger print sensor which actually a nice way to provide security.Here  i have given the interfacing of the R30-X finger print sensor module with  ARM LPC2148 board but the basics remains same for all the micro-controllers.

    The first thing for interfacing the sensor with the controller is the handshaking,in which the controller first sends a signal or hex codes to the sensor and it acknowledges .After handshaking only the controller can talk to the sensor.

unsigned char Message[16] = {0XEF,0X01,0XFF,0XFF,0XFF,0XFF,0X01,0X00,0X07,0X13,0X00,0X00,0X00,0X00,0X00,0X1B};

   This line of commands are the first to be sent to the sensor so as to start the communication.I have given the complete code to communicate with the LPC 2148 below.

Code:


#include
#include "Serial.h"
#include "Utility.h"
#include "LCD4.h"
#include "Glcd.h"

unsigned char Message[16] = {0XEF,0X01,0XFF,0XFF,0XFF,0XFF,0X01,0X00,0X07,0X13,0X00,0X00,0X00,0X00,0X00,0X1B};
unsigned char ack[12]={0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,};
unsigned char gim[12]={0XEF,0X01,0XFF,0XFF,0XFF,0XFF,0X01,0X00,0X03,0X01,0X00,0X05};
unsigned char uim[12]={0XEF,0X01,0XFF,0XFF,0XFF,0XFF,0X01,0X00,0X03,0X0A,0X00,0X0E};
int main (void)
{ int i;
PINSEL0 = 0;
PINSEL1 = 0;
PINSEL2 &= 0x0000000C;
PINSEL2 |= 0x00000030;
DelayProc(0.2 * CCLOCK);

LCD4_init(&IOPIN0, 20/*D4*/, 12/*RS*/, 14/*E*/);
UART1_init(9600/*bps*/, 15000/*kHz*/,length_8_bit, stop_bit_1, parity_disable, parity_odd);
UART0_init(9600/*bps*/, 15000/*kHz*/, length_8_bit, stop_bit_1, parity_disable, parity_odd);


for(i=0;i<16;i++)
{
UART1_sendchar(Message[i]);

}
for(i=0;i<12;i++)
{
ack[i]=UART1_getchar();
}
if(ack[9]==0x00)
{
UART0_sendstring("password checked sucessfullynn");
LCD4_sendstr (0,2, "password checked sucessfully");
}
label:
for(i=0;i<12;i++)
{
UART1_sendchar(gim[i]);

}
for(i=0;i<12;i++)
{
ack[i]=UART1_getchar();
}

if(ack[9]==0x02)
{
UART0_sendstring("cant find fingernn");
LCD4_sendstr (0,1, "cant find finger");
DelayProc(.7 * CCLOCK);
LCD4_sendstr (0,1, "Put finger");
UART0_sendstring("Put fingernn");
DelayProc(.7* CCLOCK);
goto label;

}
if(ack[9]==0x00)
{
UART0_sendstring("finger scan sucessfully completednn");
LCD4_sendstr (0,1, "finger scan sucessfully completed");
}

for(i=0;i<12;i++)
{
UART1_sendchar(uim[i]);

}
for(i=0;i<40000;i++)
{
UART0_sendchar(UART1_getchar());
}


LCD4_sendstr (0,1, "image downloaded");

}

We are Dreamers

December 12th, 2013 No comments
  We are the dreamers
             We are the dreamers
                                      with a dream of flying high,
     We try to touch the sky,
                                    And go to a boundless world.
            We believe in what we are,
                                  We do what we can.
             Nothing can stop us,
                                   because we are the dreamers.
              Our dream is to built an INDIA,
                                                  which world will know.
              We tempted to achieve our goal,
                                                   And eager to score it.
               Everybody will know us,
                                                   because we are the dreamers.
              We dream to reach beyond the universe,
                                                  To the house of stars.
              We and our knowledge,
                                                that will make our dream true.
     We never stops,
                                              because we are the dreamers.
Categories: bikash, oksbwn, we are dreamers Tags:

Simple currency converter in JAVA

December 12th, 2013 No comments
Here goes a simple JAVA code to convert rupees by using the online yahoo exchange rates.

Code:


package com.oksbwn.currencyRate;
import java.io.IOException;

import javax.swing.JOptionPane;

import org.apache.http.client.HttpClient;
import org.apache.http.client.ResponseHandler;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.impl.client.*;

import com.oksbwn.popUp.popMe;

public class YahooCurrencyConverter
{
@SuppressWarnings({ "deprecation", "resource" })
public float convert(String currencyFrom, String currencyTo) throws IOException
{
HttpClient httpclient = new DefaultHttpClient();
HttpGet httpGet = new HttpGet("http://quote.yahoo.com/d/quotes.csv?s=" + currencyFrom + currencyTo + "=X&f=l1&e=.csv");
ResponseHandler responseHandler = new BasicResponseHandler();
String responseBody = httpclient.execute(httpGet, responseHandler);
httpclient.getConnectionManager().shutdown();
return Float.parseFloat(responseBody);
}
public void convertToRs()
{String to = null;
String amnt=JOptionPane.showInputDialog(null, "Any to rupee..","$");
//if ("$".charAt(0).(();
if(amnt.substring(0,1).compareTo("$")==0)
to="USD";

if(amnt.substring(0,1).compareTo("E")==0)
to="EUR";
double ghh=1;
try{
ghh=Double.parseDouble(amnt.substring(1));
}catch (Exception e){}
YahooCurrencyConverter df= new YahooCurrencyConverter();
try {
float x=df.convert(to,"INR");
new popMe( "Exchange rate is"+x,"From "+to+" to INR", "exp", 6, 125);

JOptionPane.showMessageDialog(null,x*ghh);
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}


JFrame that pops-up from the taskbar like notifications.

December 12th, 2013 No comments
Here i have given the JAVA code to make a popup that happens exactly like the gmail desktop application does.It uses a JFrame to make the window.

Code:

package com.oksbwn.popUp;
import java.awt.*;
import java.awt.event.*;

import javax.swing.*;

import com.oksbwn.ErrorHandling.handleExceptions;

import resources.RscLoader;

public class popMe extends JFrame {
private static final long serialVersionUID = 1L;
public static void main(String[] args) throws Exception{
new popMe("hi", "from Bikash", "ok",15, 125);
}
public popMe(String message,String header,String image, final int time,int height)
{

Runnable r = new newThreadPop(message,header,image,time,height);
new Thread(r).start();
}
}

class newThreadPop implements Runnable {
private String message;
private String header;
private String image;
private int time;
private int height;

public newThreadPop(String message1,String header1,String image1, final int time1,int height1) {
// store parameter for later user
this.message=message1;
this.header=header1;
this.image=image1;
this.time=time1;
this.height=height1;
}

public void run() {
final Runnable runnable = (Runnable) Toolkit.getDefaultToolkit().getDesktopProperty("win.sound.exclamation");
//default
if (runnable != null)
runnable.run();
final JFrame frame = new JFrame();
frame.setUndecorated(true);
frame.setType(javax.swing.JFrame.Type.UTILITY);frame.setUndecorated(true);
frame. setBackground(new Color(Color.black.getRed(), Color.black.getGreen(),Color.black.getBlue(),0));
((JComponent)frame.getContentPane()).setBorder(
BorderFactory.createMatteBorder( 2, 2, 2, 2, Color.black ) );
frame.setSize(300,height);
frame.setLayout(new GridBagLayout());
GridBagConstraints constraints = new GridBagConstraints();
constraints.gridx = 0;
constraints.gridy = 0;
constraints.weightx = 1.0f;
constraints.weighty = 1.0f;
constraints.insets = new Insets(5, 5, 5, 5);
constraints.fill = GridBagConstraints.BOTH;
JLabel headingLabel = new JLabel(header);
headingLabel.setForeground(Color.red);
ImageIcon headingIcon = new ImageIcon(RscLoader.getImage(image));
headingLabel .setIcon(headingIcon); // --- use image icon you want to be as heading image.
headingLabel.setOpaque(false);
frame.add(headingLabel, constraints);
constraints.gridx++;
constraints.weightx = 0f;
constraints.weighty = 0f;
constraints.fill = GridBagConstraints.NONE;
constraints.anchor = GridBagConstraints.NORTH;

final JLabel lblX = new JLabel("X");
lblX.setToolTipText("Closern");
lblX.addMouseListener(new MouseAdapter() {
@Override
public void mouseClicked(MouseEvent arg0) {
frame.dispose();
}
@Override
public void mouseEntered(MouseEvent e) {
lblX.setForeground(new Color(255, 0, 0));
}
public void mouseExited(MouseEvent e) {
lblX.setForeground(new Color(0, 0, 0));
}
});
lblX.setSize(10,10);
lblX.setFocusable(false);
frame.add(lblX,constraints);
constraints.gridx = 0;
constraints.gridy++;
constraints.weightx = 1.0f;
constraints.weighty = 1.0f;
constraints.insets = new Insets(5, 5, 5, 5);
constraints.fill = GridBagConstraints.BOTH;
JLabel messageLabel = new JLabel(""+message);
messageLabel.setForeground(Color.blue);
frame.add(messageLabel, constraints);
frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
frame.setVisible(true);
frame.setAlwaysOnTop(true);
Dimension scrSize = Toolkit.getDefaultToolkit().getScreenSize();// size of the screen
Insets toolHeight = Toolkit.getDefaultToolkit().getScreenInsets(frame.getGraphicsConfiguration());// height of the task bar
frame.setLocation(scrSize.width - frame.getWidth(), scrSize.height - toolHeight.bottom - frame.getHeight());
new Thread(){
@Override
public void run() {
try {
Thread.sleep(time*1000); // time after which pop up will be disappeared.
frame.dispose();
}
catch (Exception e)
{new handleExceptions(e);} };}.start();

}
}


A Transparent screen to lock the Desktop.

December 12th, 2013 No comments
In this code i am sharing the code to lock the PC screen by using a transparent JFrame so as to restrict others to use it.The frame disappears  only when the user enters the right username and password.This enables the user to let the background tasks going on and lock the screen.This has the only problem that it can be closed by the task manager.If you find a solution to it please let me know.

Code:

package com.oksbwn.systeminteraction;

import java.awt.Color;
import java.awt.Dimension;
import java.awt.Toolkit;
import java.awt.event.KeyAdapter;
import java.awt.event.KeyEvent;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.io.IOException;

import javax.microedition.io.Connection;
import javax.microedition.io.Connector;
import javax.swing.BorderFactory;
import javax.swing.JButton;
import javax.swing.JComponent;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPasswordField;
import javax.swing.JTextField;

import com.oksbwn.popUp.popMe;
import com.oksbwn.voiceEnable.Voice;

public class Hibernate
{
JFrame frame2=new JFrame();
//public static void main(String args[]) throws Exception
public void doit() throws IOException
{
try {
Connection connection = Connector.open( "btgoep://" +"04A82A5A62FB" + ":9");
connection.close();
//int x=1/0;//The condition which will trigger the frame to come up
}
catch (Exception e) {
//r.exec("shutdown -h");//s for shutdown r restart
// Runtime rt = Runtime.getRuntime();
// rt.exec("C:\Windows\System32\rundll32.exe user32.dll,LockWorkStation");

Dimension scrSize = Toolkit.getDefaultToolkit().getScreenSize();// size of the screen
frame2.setBounds(0,0,scrSize.width, scrSize.height);
frame2.getContentPane().setLayout(null);
frame2.setAlwaysOnTop(true);
frame2.setUndecorated(true);
frame2.setBackground(new Color(Color.black.getRed(), Color.black.getGreen(),Color.black.getBlue(),1));
frame2.getContentPane().setBackground(new Color(Color.black.getRed(), Color.black.getGreen(),Color.black.getBlue(),50));
((JComponent)frame2.getContentPane()).setBorder(
BorderFactory.createMatteBorder( 2, 2, 2, 2, Color.black ) );
frame2.setType(javax.swing.JFrame.Type.UTILITY);
frame2.setAlwaysOnTop(true);

final JTextField textField = new JTextField();
textField.addKeyListener(new KeyAdapter() {
@Override
public void keyPressed(KeyEvent arg0) {
frame2.repaint();
}
});
textField.setBounds(scrSize.width-150, scrSize.height-100, 140, 30);
textField.setBackground(new Color(Color.black.getRed(), Color.black.getGreen(),Color.black.getBlue(),1));
frame2.getContentPane().add(textField);
textField.setColumns(10);

final JPasswordField passwordField = new JPasswordField();
passwordField.addKeyListener(new KeyAdapter() {
@Override
public void keyPressed(KeyEvent arg0) {
frame2.repaint();
}
});
frame2.setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);
passwordField.setBounds(scrSize.width-150, scrSize.height-65,140,30);
passwordField.setBackground(new Color(Color.black.getRed(), Color.black.getGreen(),Color.black.getBlue(),1));
frame2.getContentPane().add(passwordField);

JButton btnLogIn = new JButton("login");
btnLogIn.setBounds(scrSize.width-127,scrSize.height-30,77,24);
frame2.getContentPane().add(btnLogIn);
btnLogIn.addMouseListener(new MouseAdapter() {
@Override
public void mouseClicked(MouseEvent arg0)
{
@SuppressWarnings("deprecation")
String pass=passwordField.getText();
logClicked(pass,textField.getText());
passwordField.setText(null);
textField.setText(null);
//frame2.dispose();
}
});

final JLabel Snap = new JLabel();
Snap.setForeground(Color.RED);
Snap.setBounds(scrSize.width/2-100, scrSize.height/2-100,200,200);
frame2.getContentPane().add(Snap);

frame2.addMouseListener(new MouseAdapter() {
@Override
public void mouseClicked(MouseEvent arg0) {
final Runnable runnable = (Runnable) Toolkit.getDefaultToolkit().getDesktopProperty("win.sound.exclamation");
//default
if (runnable != null)
runnable.run();
Snap.setText("OOOOps You are Not Bikash");
}
});
frame2.setVisible(true);
}
}
protected void logClicked(String pass, String user)
{
String aPass="******";//Password
String aUser="oksbwn";//Username
if (aPass.compareTo(pass) == aUser.compareTo(user)==true)
{
//sucess message
}
else {
//failure message
}
}
}

Drive space usage information in JAVA

December 12th, 2013 No comments
This JAVA code gives the dpace usage by the ‘c:’ drive you can modify it for others.

Code:

package com.oksbwn.systeminteraction;
import java.io.File;
public class DiskSpaceDetail
{
public String FreeSpaceInDrive()
{
String space="";
File file = new File("C:");
long totalSpace = file.getTotalSpace(); //total disk space in bytes.
long usableSpace = file.getUsableSpace(); ///unallocated / free disk space in bytes.
space=space+"C:";
space="T: "+ totalSpace /1024 /1024 + " MB F: "+ usableSpace /1024 /1024+" MB";
return space;
}
}

Taking a snap of the Desktop in JAVA

December 12th, 2013 No comments
Here i have gioven the code to take a snap of the desktop using JAVA.Hope you will use it in your own way.

Code:

package com.oksbwn.systeminteraction;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.MouseInfo;
import java.awt.Point;
import java.awt.Rectangle;
import java.awt.Robot;
import java.awt.Toolkit;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.awt.image.BufferedImage;
import java.io.File;

import javax.imageio.ImageIO;
import javax.swing.*;

import resources.RscLoader;

import com.oksbwn.ErrorHandling.handleExceptions;
import com.oksbwn.popUp.popMe;
public class CaptureScreen {
static JFrame frame2=new JFrame();
static Point p;
static Point R;
static Point D;
static int Finaly;
static int Startx;
static int Starty;
static int Finalx;
static JTextField jt=new JTextField();
public static void main(String[] args)
{
CaptureScreen cS=new CaptureScreen();
cS.SnapTaker();
}
public void SnapTaker()
{
Dimension scrSize = Toolkit.getDefaultToolkit().getScreenSize();// size of the screen
frame2.setBounds(0,0,scrSize.width, scrSize.height);
frame2.getContentPane().setLayout(null);
frame2.setAlwaysOnTop(true);
frame2.setUndecorated(true);
frame2.setBackground(new Color(Color.black.getRed(), Color.black.getGreen(),Color.black.getBlue(),1));
frame2.getContentPane().setBackground(new Color(Color.black.getRed(), Color.black.getGreen(),Color.black.getBlue(),50));
((JComponent)frame2.getContentPane()).setBorder(
BorderFactory.createMatteBorder( 2, 2, 2, 2, Color.black ) );
frame2.setType(javax.swing.JFrame.Type.UTILITY);
frame2.setAlwaysOnTop(true);

jt.setBounds(0,0,0,0);
jt.addMouseListener(mouseListener);
jt.setBorder(BorderFactory.createMatteBorder( 2, 2, 2, 2, Color.black ));
jt.addMouseMotionListener(mouseListener);
jt.setEditable(false);
jt.setBackground(new Color(Color.black.getRed(), Color.black.getGreen(),Color.black.getBlue(),0));
frame2.getContentPane().add(jt);

final JLabel cloesButton = new JLabel("X");
cloesButton.setForeground(Color.white);
cloesButton.setToolTipText("Close");
cloesButton.addMouseListener(new MouseAdapter() {
@Override
public void mouseClicked(MouseEvent arg0) {
frame2.dispose();
}
@Override
public void mouseEntered(MouseEvent arg0) {
cloesButton.setForeground(Color.red);
}
@Override
public void mouseExited(MouseEvent arg0) {
cloesButton.setForeground(Color.white);
}});
cloesButton.setSize(15,15);
cloesButton.setBounds(scrSize.width-15, scrSize.height-20,15,20);

final JLabel Snap = new JLabel();
Snap.setIcon(new ImageIcon(RscLoader.getImage("cam")));
Snap.setForeground(Color.white);
Snap.setToolTipText("Take Snap");
Snap.addMouseListener(new MouseAdapter() {
@Override
public void mouseClicked(MouseEvent arg0) {
takeSnap();
}
@Override
public void mouseEntered(MouseEvent arg0) {
Snap.setForeground(Color.GREEN);
}
@Override
public void mouseExited(MouseEvent arg0) {
Snap.setForeground(Color.white);
}});
Snap.setBounds(scrSize.width-100, scrSize.height-20,60,20);
frame2.getContentPane().add(Snap);

frame2.addMouseListener(new MouseAdapter() {

@Override
public void mousePressed(MouseEvent arg0) {
p= MouseInfo.getPointerInfo().getLocation();
//jt.setBounds(0,0,p.x,p.y);
}
@Override
public void mouseReleased(MouseEvent arg0) {
R= MouseInfo.getPointerInfo().getLocation();
jt.setBounds(p.x,p.y,R.x-p.x,R.y-p.y);
}});
frame2.getContentPane().add(cloesButton);
frame2.setVisible(true);

}
private final static void takeSnap()
{
try {
Robot robot = new Robot();
Rectangle area = new Rectangle(jt.getBounds());
BufferedImage bufferedImage = robot.createScreenCapture(area);
File file = new File("C:\users\oksbwn\desktop\screenshot_small.png");
boolean i=ImageIO.write(bufferedImage, "jpg", file);
if (i)
{
new popMe("Snap taken Sucessfully.","Screen Capture","ok",2,125);
}
} catch (Exception e) {new handleExceptions(e);}
}
private final static MouseAdapter mouseListener = new MouseAdapter() {
int x, y;
@Override
public void mousePressed(MouseEvent e) {
if (e.getButton() == MouseEvent.BUTTON1) {
x = e.getX();
y = e.getY();
}
}

@Override
public void mouseDragged(MouseEvent e) {
if ((e.getModifiersEx() & MouseEvent.BUTTON1_DOWN_MASK) != 0) {
jt. setLocation(e.getXOnScreen() - x, e.getYOnScreen() - y);
}
}
};

}

PC Login Duration in JAVA

December 12th, 2013 No comments
This code snippest is about getting the time duration from which the user has been logged in using JAVA.

 code:

package com.oksbwn.systeminteraction;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.text.SimpleDateFormat;
import java.util.Date;
public class OsLoginTime {
public static long getSystemUptime() throws Exception {
long uptime =0000;

Process uptimeProc = Runtime.getRuntime().exec("net stats srv");
BufferedReader in = new BufferedReader(new InputStreamReader(uptimeProc.getInputStream()));
String line;
while ((line = in.readLine()) != null) {
if (line.startsWith("Statistics since")) {
SimpleDateFormat format = new SimpleDateFormat("'Statistics since' MM/dd/yyyy hh:mm:ss a");
Date boottime = format.parse(line);
uptime = System.currentTimeMillis() - boottime.getTime();
break;
}
}
return uptime/36000;//in millisecond
}
}

Categories: bput, JAVA, java login information, login, oksbwn, pc Tags: