Hi Antonio,

You could remove the System.out.println()s in your code to check that
the messages are not intercepted anywhere else in some unexplored part
of the code. Even better, you could modify the System.out.println()s so
that they show an ID. This way you could find out which ones of the
messageReceived() is called.

I do spot a few problems in your code. I'm not sure they are causing the
behavior that you see, but correct them anyways:

>             public Contoller(){
>                 super();
>                 //initComponents();
>                 //mote = new MoteIF(PrintStreamMessenger.err,
> this.GROUP_ID);
>                 mote = new MoteIF();
>                 mote.registerListener(new MultiMsg(), msgRcv = new
> MessageReceive());
>                 msgRcv = new MessageReceive();
>                 initComponents();
>                 inputID.addActionListener(msgRcv);
>                 capAudio.addActionListener(msgRcv);
>                 stopCapAudio.addActionListener(msgRcv);
>             }
Here you create a new instance of MessageReceived inside the
registerListener() function call, but then immediately recreate again a
new instance. Better swap the two lines and write something like this:
>                 msgRcv = new MessageReceive();
>                 mote.registerListener(new MultiMsg(), msgRcv);

You have commented out the interface MessageListener from the main class
Controller. You should also comment out (or completely remove; you have
a backup, right?) the method messageReceived(). This makes for clearer
code and ensures that you are not modifying the wrong part of the code.

I'm surprised that the compiler doesn't complain about jTextArea1 not
being final. Normally you should not be able to access non-final
instance variable of outer classes. Do you get any warnings?

It might be overkill, but try the following code in
MessageReceive.messageReceived():
>         jTextArea1.setCaretPosition(jTextArea1.getText().length());
>         jTextArea1.append(msg.toString());
>         jTextArea1.validate();

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.

PPS:
You're the only one on the list that sends mails in this format.

antonio gonga schrieb:
> 
> Hey all,
> I'm trying without any result to solve my problem please I need your help.
> 
> I'm developing a Java Application do display the messages from the
> serial port, I'm using the Java Tool MoteIF for reciving.
> My problem is that the method messageReceived(int to, Message msg) is
> not being invoked..  the messages are being displayed on console instead
> of the JTextArea on the GUI... I'm sure that the this method is not
> being invoked and I don't know how I can put it to work..
> I'm correctly receiving all messages, but all are printed on the console
> instead of on the Graphical Interface because the method messageReceived
> is not working..
> please help me... it's connected to my Thesis...
> 
> thanks in advance...
> 
> my code is bellow.(some parts of the core were suppressed )
> public class Contoller extends javax.swing.JFrame /*implements
> MessageListener*/{
>            //     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();
>                 //initComponents();
>                 //mote = new MoteIF(PrintStreamMessenger.err,
> this.GROUP_ID);
>                 mote = new MoteIF();
>                 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());
>     }
>     /**
>      * @param id
>      * @param message
>      */
>     public void messageReceived(int Id, Message message){
>         MultiMsg msg= (MultiMsg)message;
>         //jTextArea1.append(msg.toString());
>         jTextArea1.append(message.toString());
>         if(message instanceof MultiMsg){
>             msg =(MultiMsg)message;
>             System.out.println(msg.toString());
>         }else{
>             throw new RuntimeException("Unknown type: " + message);
>         }
>     }
>     /**
>      *
>      * @author antonio gonga
>      *
>      */
>     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   
> }
_______________________________________________
Tinyos-help mailing list
[email protected]
https://mail.millennium.berkeley.edu/cgi-bin/mailman/listinfo/tinyos-help

Reply via email to