To LUGNET HomepageTo LUGNET News HomepageTo LUGNET Guide Homepage
 Help on Searching
 
Post new message to lugnet.robotics.spyboticsOpen lugnet.robotics.spybotics in your NNTP NewsreaderTo LUGNET News Traffic PageSign In (Members)
 Robotics / Spybotics / 404
403  |  405
Subject: 
Re: Some beginner questions on serial communication
Newsgroups: 
lugnet.robotics.spybotics
Date: 
Mon, 26 Sep 2005 00:26:57 GMT
Viewed: 
8396 times
  
Hi,


I would like to know how to send and
receive serial data from the RCX to a Sptbot and vice versa.

Sorry, I don't have an RCX so can't really help you there.  The NQC Guide is
pretty good.  The best way to find out is to try lots of combinations.

Also, is serial the
only way to communicate between two Spybots or is there a simpler way to
communicate, if so, please let me know.

Here are a couple of programs where two Spybots send messages to each other.
Another way to send simple messages to all spybots is to use PingData().
Basically on the Spybot you SetPingData(55) which broadcasts a this data with
its ping. A good use of this is to let everyone else know what state you are in.
Make sure that PingInterval is not set to 0, though.  All the other robots can
then find Spybots which are broadcasting a particular number using
FindWorld(spybot_index, SPY_INFO, REL_EQ, 55) will find the next spybot where
the ping info equals 55.  The world relation table index will be stored in
spybot_index which you can then use to set as your target
SetTargetID(spybot_index).

Good luck!

Allen

/***********************************************************
* file: message_blue.nqc
* date: September, 2005
* auth: Allen Benter
* desc: This program broadcasts 4 messages to all spybots.
*       It also listens for any messages received and will
*       display the value on the LEDs
***********************************************************/

#define MESSAGE_EVENT 1
int MESSAGE;

task main()
{
  SetEvent(MESSAGE_EVENT, VLL(), EVENT_TYPE_MSG_RECEIVED);
  start listen;
  start talk;

  while(true)
    SetLED(LED_MODE_ON, MESSAGE);
}

task listen()
{
  while (true)
  {
    monitor (EVENT_MASK(MESSAGE_EVENT))
    {
      Wait(1000);
    }

    // message caught
    catch
    {
      MESSAGE = RxMessage(MSG_IR, MSG_COMMAND);
    }
  }
}

task talk()
{
  PlaySound(SOUND_DOUBLE_BEEP);
  SendSpybotMessage(INDEX_BROADCAST, 10, 0, 0);
  Wait(500);
  PlaySound(SOUND_DOUBLE_BEEP);
  SendSpybotMessage(INDEX_BROADCAST, 20, 0, 0);
  Wait(500);
  PlaySound(SOUND_DOUBLE_BEEP);
  SendSpybotMessage(INDEX_BROADCAST, 30, 0, 0);
  Wait(500);
  PlaySound(SOUND_DOUBLE_BEEP);
  SendSpybotMessage(INDEX_BROADCAST, 40, 0, 0);
  Wait(500);

} //end of message_blue.nqc

/***********************************************************
* file: message_red.nqc
* date: September, 2005
* auth: Allen Benter
* desc: This program listens to all messages.
*       If it receives a message with a value of 30 it
*       switches to state 1 and sends out a message
***********************************************************/

#define MESSAGE_EVENT 1
int MESSAGE;
int STATE;

task main()
{
  STATE = 0;
  SetPingInterval(1);
  SetEvent(MESSAGE_EVENT, VLL(), EVENT_TYPE_MSG_RECEIVED);
  start listen;
  start talk;

  while(true)
    SetLED(LED_MODE_ON, MESSAGE);
}

task listen()
{
  while (true)
  {
    monitor (EVENT_MASK(MESSAGE_EVENT))
    {
      Wait(1000);
    }

    // message caught
    catch
    {
      MESSAGE = RxMessage(MSG_IR, MSG_COMMAND);
      if(MESSAGE == 30)
        STATE = 1;
      else
        STATE = 0;
    }
  }
}

task talk()
{
  while(true)
  {
    switch(STATE)
    {
      case 0:
        break;

      case 1:
        SendSpybotMessage(INDEX_BROADCAST, 15, 0, 0);
        PlaySound(SOUND_DOUBLE_BEEP);
        Wait(100);
        break;
    }
  }

}// end of message_red.nqc



Message is in Reply To:
  Some beginner questions on serial communication
 
Hello everybody, This is my first post, I hope someone can help. I've recently started programming my Spybot with NQC and BricxCC. I would like to know how to send and receive serial data from the RCX to a Sptbot and vice versa. Also, is serial the (...) (19 years ago, 15-Jun-05, to lugnet.robotics.spybotics)

2 Messages in This Thread:

Entire Thread on One Page:
Nested:  All | Brief | Compact | Dots
Linear:  All | Brief | Compact
    

Custom Search

©2005 LUGNET. All rights reserved. - hosted by steinbruch.info GbR