serial communication using RS232

Joined
Apr 14, 2010
Messages
1
Reaction score
0
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
 

Attachments

  • circuit.jpg
    circuit.jpg
    52.9 KB · Views: 328
  • circuit diagram.jpg
    circuit diagram.jpg
    45.9 KB · Views: 336
  • turn.zip
    1.4 KB · Views: 209
  • close view to microcontroller.jpg
    close view to microcontroller.jpg
    57.2 KB · Views: 328
  • computer interface.jpg
    computer interface.jpg
    65.7 KB · Views: 325

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,754
Messages
2,569,528
Members
45,000
Latest member
MurrayKeync

Latest Threads

Top