serial communication using RS232

Discussion in 'Java' started by faleni, Apr 20, 2010.

  1. faleni

    faleni

    Joined:
    Apr 14, 2010
    Messages:
    1
    The aim of my project is to turn LED on/off using computer. Whereby the computer and microcontroller are connected by RS232. I have created computer interface using Jframebuilder and save the file as turn.java. The interface have two buttons (LED on) and (LED off)

    If the user press button (LED on), then LED must be on and if the user press the button (LED off) then LED must be off.

    Looking at zipped file turn.java on the attachment, when opening the file turn.java using Jcreator the following code appears.
    Code:
    /****************************************************************/
    /*                      turn	                            */
    /*                                                              */
    /****************************************************************/
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    /**
     * Summary description for turn
     *
     */
    public class turn extends JFrame
    {
    	// Variables declaration
    	private JButton jButton1;
    	private JButton jButton2;
    	private JPanel contentPane;
    	// End of variables declaration
    
    
    	public turn()
    	{
    		super();
    		initializeComponent();
    		//
    		// TODO: Add any constructor code after initializeComponent call
    		//
    
    		this.setVisible(true);
    	}
    
    	/**
    	 * This method is called from within the constructor to initialize the form.
    	 * WARNING: Do NOT modify this code. The content of this method is always regenerated
    	 * by the Windows Form Designer. Otherwise, retrieving design might not work properly.
    	 * Tip: If you must revise this method, please backup this GUI file for JFrameBuilder
    	 * to retrieve your design properly in future, before revising this method.
    	 */
    	private void initializeComponent()
    	{
    		jButton1 = new JButton();
    		jButton2 = new JButton();
    		contentPane = (JPanel)this.getContentPane();
    
    		//
    		// jButton1
    		//
    		jButton1.setText("LED on");
    		jButton1.addActionListener(new ActionListener() {
    			public void actionPerformed(ActionEvent e)
    			{
    				jButton1_actionPerformed(e);
    			}
    
    		});
    		//
    		// jButton2
    		//
    		jButton2.setText("LED off");
    		jButton2.setMaximumSize(new Dimension(151, 25));
    		jButton2.addActionListener(new ActionListener() {
    			public void actionPerformed(ActionEvent e)
    			{
    				jButton2_actionPerformed(e);
    			}
    
    		});
    		//
    		// contentPane
    		//
    		contentPane.setLayout(null);
    		addComponent(contentPane, jButton1, 26,32,83,28);
    		addComponent(contentPane, jButton2, 194,38,108,28);
    		//
    		// turn
    		//
    		this.setTitle("turn - extends JFrame");
    		this.setLocation(new Point(76, 59));
    		this.setSize(new Dimension(390, 300));
    	}
    
    	/** Add Component Without a Layout Manager (Absolute Positioning) */
    	private void addComponent(Container container,Component c,int x,int y,int width,int height)
    	{
    		c.setBounds(x,y,width,height);
    		container.add(c);
    	}
    
    	//
    	// TODO: Add any appropriate code in the following Event Handling Methods
    	//
    	private void jButton1_actionPerformed(ActionEvent e)
    	{
    		System.out.println("\njButton1_actionPerformed(ActionEvent e) called.");
    		// TODO: Add any handling code here
    
    	}
    
    	private void jButton2_actionPerformed(ActionEvent e)
    	{
    		System.out.println("\njButton2_actionPerformed(ActionEvent e) called.");
    		// TODO: Add any handling code here
    
    	}
    
    	//
    	// TODO: Add any method code to meet your needs in the following area
    	//
    
    
    
    //============================= Testing ================================//
    //=                                                                    =//
    //= The following main method is just for testing this class you built.=//
    //= After testing,you may simply delete it.                            =//
    //======================================================================//
    	public static void main(String[] args)
    	{
    		JFrame.setDefaultLookAndFeelDecorated(true);
    		JDialog.setDefaultLookAndFeelDecorated(true);
    		try
    		{
    			UIManager.setLookAndFeel("com.sun.java.swing.plaf.windows.WindowsLookAndFeel");
    		}
    		catch (Exception ex)
    		{
    			System.out.println("Failed loading L&F: ");
    			System.out.println(ex);
    		}
    		new turn();
    	}
    //= End of Testing =
    
    
    }
    
    
    
    when running the project the interface is created. From the interface, I want binary 0 to be send/transmitted through RS232 cable to microcontroller, when the button (LED off) is pressed and when microcontroller receive binary 0 then, I can write assembly code that turns off LED. If button (LED on) is pressed then binary 1 must be transmitted through RS232 cable to microcontroller and I can write assembly code that would turn on LED when binary 1 is received at the microcontroller.

    From the code above, Could you please insert the instructions/code that would make it be possible for binary 1 to be send when button (LED on) is pressed, under this class
    Code:
    private void jButton1_actionPerformed(ActionEvent e)
    	{
    		System.out.println("\njButton1_actionPerformed(ActionEvent e) called.");
    		// TODO: Add any handling code here
    
                   }
    
    
    and also the code that would make binary 0 to be send through RS232 to microcontroller when button (LED off) is pressed, under this class.
    Code:
    
    private void jButton2_actionPerformed(ActionEvent e)
    	{
    		System.out.println("\njButton2_actionPerformed(ActionEvent e) called.");
    		// TODO: Add any handling code here
    
    	}
    
    
    Circuit diagram, computer interface and the circuit i have build are shown on the attachment. I would be very happy if any one could help me. Thank you

    Attached Files:

    faleni, Apr 20, 2010
    #1
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. PaullyB

    JMS over a serial port (rs232)

    PaullyB, Feb 22, 2005, in forum: Java
    Replies:
    0
    Views:
    471
    PaullyB
    Feb 22, 2005
  2. bronby

    Re: RS232 communication

    bronby, Apr 14, 2005, in forum: Java
    Replies:
    10
    Views:
    3,441
    bronby
    May 17, 2005
  3. Laura Lucas
    Replies:
    4
    Views:
    994
    Alf P. Steinbach
    Oct 8, 2004
  4. deena102

    RS232 Communication problem

    deena102, Apr 12, 2009, in forum: VHDL
    Replies:
    0
    Views:
    503
    deena102
    Apr 12, 2009
  5. Max Kotasek
    Replies:
    4
    Views:
    978
    Max Kotasek
    Apr 9, 2010
Loading...

Share This Page