Hi Antonio,
It seems the code you're interested in is in the method
messageReceived(..). You're actually printing the message to the
console. I guess that code should look like this:
public void messageReceived(int Id, Message message){
MultiMsg msg = (MultiMsg)message;
jTextArea1.append(msg.toString());
}
The instanceof test for MultiMsg is unnecessary since you already to an
explicit cast before that. I haven't checked the whole code, but most
likely you will ever get Messages of type MultiMsg if you have
registered your message handler only for MultiMsg message types.
Cheers,
Urs
PS:
I use a thunderbird as a mail client and by default I set it to display
messages as text only. For some unknown reason your mail client sends
HTML messages that don't show properly in text-only mode. It would help
me a lot to read your mails if you could change this behavior.
antonio gonga schrieb:
> Hey Urs,
> I'm trying to develop a Java application that receives messages from serial
> port,
> my problem is that When starting the program the messages are displayed on
> the
> console instead of on the GUI of the Java Application that I developed.My
> code is stated bellow.
> I supressed the GUI code because is too long...
>
> Please help me
>
> import java.awt.event.ActionEvent;
> import java.awt.event.ActionListener;
>
>
> //import net.tinyos.message.Message;
> //import net.tinyos.message.MessageListener;
> //import net.tinyos.message.MoteIF;
> //import net.tinyos.message.MultiMsg;
> import net.tinyos.message.*;
> import net.tinyos.packet.*;
> import net.tinyos.util.*;
> import net.tinyos.util.PrintStreamMessenger;
> public class Contoller extends javax.swing.JFrame{
> // Variables declaration - do not modify
> private javax.swing.JPanel ACSPanel;
> private javax.swing.JPanel IRSPanel;
> private javax.swing.JPanel MainPanel;
> private javax.swing.JLabel QueryLabel;
> private javax.swing.JPanel QueryPanel;
> private javax.swing.JLabel acsLabel;
> private javax.swing.JLabel acsSenderID;
> private javax.swing.JLabel acsState;
> private javax.swing.JButton capAudio;
> private javax.swing.JTextField inputID;
> private javax.swing.JLabel irsLabel;
> private javax.swing.JLabel irsSenderID;
> private javax.swing.JLabel irsState;
> private javax.swing.JLabel jLabel1;
> private javax.swing.JScrollPane jScrollPane1;
> private javax.swing.JSeparator jSeparator1;
> private javax.swing.JTextArea jTextArea1;
> private javax.swing.JLabel queryMoteLabel;
> private javax.swing.JLabel queryStatus;
> private javax.swing.JButton stopCapAudio;
> // End of variables declaration
>
> /** TOS_Msg Fields **/
> private static final int TYPE_IR_SENSOR = 0;
> private static final int TYPE_AC_SENSOR = 1;
> private static final int TYPE_KEEP_ALIVE = 2;
> private static final int TYPE_NOISE_REQUEST = 3;
> private static final int TYPE_SYNC = 4;
> private static final int TINYOS_BAUD_RATE = 57600;
> private static final int MULTIHOP_DATA_LENGTH = 22;
> private static final int GROUP_ID = 136;
>
> private static final int SYNC_BYTE = 0x7e;
> private static final int ESCAPE_BYTE = 0x7d;
> private static final int MTU = 256;
> private static final String defaultPort = "COM5";
> private static final int TOSH_DATA_LENGTH = 29;
> private MessageReceive msgRcv;
> private MoteIF mote;
> protected boolean noiseStatus = false;
> protected boolean buttonPressed = false;
>
> public Contoller(){
> super();
> mote = new MoteIF(PrintStreamMessenger.err, this.GROUP_ID);
> mote.registerListener(new MultiMsg(), msgRcv = new
> MessageReceive());
> //msgRcv = new MessageReceive();
> initComponents();
> inputID.addActionListener(msgRcv);
> capAudio.addActionListener(msgRcv);
> stopCapAudio.addActionListener(msgRcv);
> }
>
> /**
> * @param args
> */
> public static void main(String[] args) {
> // TODO Auto-generated method stub
> java.awt.EventQueue.invokeLater(new Runnable() {
> public void run() {
> new Contoller().setVisible(true);
> }
> });
> }
> public void fillJTextArea(){
> if(buttonPressed){
> if(noiseStatus){
> jTextArea1.append("Sending Noise Capture Query to
> MoteID: ");
> jTextArea1.append(inputID.getText()+"\n");
> }else if(!noiseStatus){
> jTextArea1.append("Sending Noise Capture Stop Query to
> MoteID: ");
> jTextArea1.append(inputID.getText()+"\n");
> }
> }
> buttonPressed = false;
> jTextArea1.setCaretPosition(jTextArea1.getText().length());
> }
>
> class MessageReceive implements MessageListener, ActionListener{
> /**
> * @param id
> * @param message
> */
> public void messageReceived(int Id, Message message){
> MultiMsg msg= (MultiMsg)message;
> //jTextArea1.append(msg.toString());
> if(message instanceof MultiMsg){
> msg =(MultiMsg)message;
> System.out.println(msg.toString());
> }else{
> throw new RuntimeException("Unknown type: " + message);
> }
> }
> /**
> * @param ae
> */
> public void actionPerformed(ActionEvent ae){
> if(ae.getSource() == capAudio &&
> (inputID.getText().length()>= 1)){
> if(!noiseStatus){
> noiseStatus = true;
> buttonPressed = true;
> queryStatus.setForeground(new java.awt.Color(255,
> 0, 51));
> queryStatus.setText("STATUS:"+"QUERYING NOISE FROM
> MOTE_ID["+inputID.getText()+"]");
> fillJTextArea();
> inputID.setText("");
> }
> }else if((ae.getSource() == stopCapAudio) &&
> (inputID.getText().length()>= 1)){
> if(noiseStatus){
> noiseStatus = false;
> buttonPressed = true;
> queryStatus.setForeground(new java.awt.Color(0, 0,
> 204));
> queryStatus.setText("STATUS:"+" IDDLE");
> fillJTextArea();
> inputID.setText("");
> }
> }
> }
> } //end of class MessageReceive
> } //end of main Class
_______________________________________________
Tinyos-help mailing list
[email protected]
https://mail.millennium.berkeley.edu/cgi-bin/mailman/listinfo/tinyos-help