Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > serial communication using RS232

Reply
Thread Tools

serial communication using RS232

 
 
faleni faleni is offline
Junior Member
Join Date: Apr 2010
Posts: 1
 
      04-20-2010
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 Images
File Type: jpg circuit.jpg (52.9 KB, 34 views)
File Type: jpg circuit diagram.jpg (45.9 KB, 30 views)
File Type: jpg close view to microcontroller.jpg (57.2 KB, 26 views)
File Type: jpg computer interface.jpg (65.7 KB, 29 views)
Attached Files
File Type: zip turn.zip (1.4 KB, 33 views)
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
fcntl, serial ports and serial signals on RS232. Max Kotasek Python 4 04-09-2010 06:32 PM
RS232 Communication problem deena102 VHDL 0 04-12-2009 01:05 PM
Re: RS232 communication bronby Java 10 05-17-2005 06:09 AM
JMS over a serial port (rs232) PaullyB Java 0 02-22-2005 01:19 AM
How to generate a EV_RING event in rs232 serial COM port? visual c++ 6.0 Laura Lucas C++ 4 10-08-2004 04:45 PM



Advertisments