Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

RS232 Communication

Status
Not open for further replies.
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, interface and the circuit i have build are shown on the attachment. YOUR help would make me love electronics more and I would build more complicated projects. Thank you very much.
 

Attachments

  • circuit..jpg
    circuit..jpg
    52.9 KB · Views: 160
  • circuit diagram..jpg
    circuit diagram..jpg
    45.9 KB · Views: 158
  • close view to mi&#99.jpg
    close view to mi&#99.jpg
    57.2 KB · Views: 144
  • interface..jpg
    interface..jpg
    65.7 KB · Views: 142
  • turn..zip
    1.4 KB · Views: 107
Last edited:
The attachments aren't here. They are in your crosspost to the MICROCONTROLLER forum.
 
Somebody will probably try to help you after they have spent the time to check your other thread to see other answers. Myself, I don't usually waste the time.

Such is the "benefit" of cross posting. You sometimes get fewer answers instead of more.
 
It was not my aim to cross post, as you can see all my post are on micro controller forum. After posting the thread serial communication, I realised that, the post suit electronic project forum because the thread is a small electronic project thats why I reposted the thread RS232 communication. I did not cross point intensionally and I have never done it before. I would be pleased if you can help me
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top