Dexter NXTBee (NXC)

Discussion specific to the intelligent brick, sensors, motors, and more.
HaWe
Posts: 2500
Joined: 04 Nov 2014, 19:00

Dexter NXTBee (NXC)

Post by HaWe »

hi,
Looking through the following code (provided by Dexter) I am curious about a few things.
First, the receive program:
- at the start the variable byte mlen is declared but never used: what was it intended for?
- how can the receiver know how long the recieved string is, or does the code work with all strings of all lengths (which would be very convenient)?
- what is the maximum string length? 128? 256? 32767?
- a baud rate of 9600 has been used; is it possible to use a faster one? How much is possible?


Code: Select all

///////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////
////
////  NXTBEE RAW RECEIVE PROGRAM
////  NXTBee receiver program
////  For use with the NXTBee and Mindstorms NXT
////  www.dexterindustries.com
////  Use the latest release of NXC (1.2.1 r4 or later).
////  You can find it at http://bricxcc.sourceforge.net/nbc/
////
////  John Hansen helped adapt this code to NXC.
////  http://bricxcc.sourceforge.net/
////
////  More information on the NXTBee can be found at
////  http://www.dexterindustries.com/NXTBee.html
////
////  3/21/2011
///////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////


task main()
{
  byte mlen;
  string buffer;
  
  // configure the S4 port as RS485
  UseRS485(); 

  // make sure the RS485 system is turned on
  RS485Enable(); 
  
  // initialize the UART to default values
  RS485Initialize(); 
  RS485Uart(HS_BAUD_9600, HS_MODE_DEFAULT); // use 9600 baud rather than default rate

  Wait(MS_10);
  while (true) {

    // wait for a message to arrive.
    until(RS485DataAvailable());
    RS485Read(buffer);

    // display message
    TextOut(0, LCD_LINE2, buffer);
    Wait(SEC_1);
  }

  // shut down the RS485 system
  RS485Disable();
  bool sendingData, dataAvail;

  // check RS485 status
  RS485Status(sendingData, dataAvail); 

  // turn the system back on (this is equivalent to RS485Enable)
  RS485Control(HS_CTRL_INIT, HS_BAUD_DEFAULT, HS_MODE_DEFAULT);

  // configure the UART (this is equivalent to RS485Initialize)
  RS485Uart(HS_BAUD_DEFAULT, HS_MODE_DEFAULT);
 
}
for completion, this is the sender program (which I don't understand already completely by all details):

Code: Select all

///////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////
////
////  NXTBEE RAW SEND 4.0
////  NXTBee Sender program
////  For use with the NXTBee and Mindstorms NXT
////  www.dexterindustries.com
////  Use the latest release of NXC (1.2.1 r4 or later).
////  You can find it at http://bricxcc.sourceforge.net/nbc/
////
////  John Hansen helped adapt this code to NXC.
////  http://bricxcc.sourceforge.net/
////
////  More information on the NXTBee can be found at
////  http://www.dexterindustries.com/NXTBee.html
////
////  3/21/2011
///////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////



void SendRS485Bool1(const bool value)
{
  byte msg[];
  ArrayBuild(msg, value, 0);
  SetHSOutputBuffer(0, 2, msg);
  SetHSOutputBufferOutPtr(0);
  SetHSOutputBufferInPtr(2);
  SetHSState(HS_SEND_DATA);
  SetHSFlags(HS_UPDATE); //send it
}

void SendRS485Number1(const int value)
{
  string msg = Flatten(value);
  SetHSOutputBuffer(0, 5, msg);
  SetHSOutputBufferOutPtr(0);
  SetHSOutputBufferInPtr(5);
  SetHSState(HS_SEND_DATA);
  SetHSFlags(HS_UPDATE); //send it
}

void SendRS485String1(const string msg)
{
  byte mlen = ArrayLen(msg);
  SetHSOutputBuffer(0, mlen, msg);
  SetHSOutputBufferOutPtr(0);
  SetHSOutputBufferInPtr(mlen);
  SetHSState(HS_SEND_DATA);
  SetHSFlags(HS_UPDATE); //send it
}


inline void WaitForMessageToBeSent()
{
  // use hi level API functions (preferred)
  while (RS485SendingData())
    Wait(MS_1);
}

task main()
{
  // configure the S4 port as RS485
  UseRS485();

  // make sure the RS485 system is turned on
  // hi level API function call
  RS485Enable();

  // initialize the UART to default values
  // hi level API function call
  RS485Uart(HS_BAUD_9600, HS_MODE_DEFAULT); // use 9600 baud rather than default rate

  Wait(MS_10);
  int i;
  while (true) {
    string msg;
    //msg = "9";
    msg = "goofy ";
    msg += NumToStr(i);
    TextOut(0, LCD_LINE1, msg);
    SendRS485String(msg); // this is exactly the same as RS485Write but takes a string instead of a byte array
    WaitForMessageToBeSent();
    i++;
    Wait(SEC_1);
  }
  // disable RS485 (not usually needed)
  RS485Disable();
}
ps
will now be afk for 2 weeks!
HaWe
Posts: 2500
Joined: 04 Nov 2014, 19:00

Re: Dexter NXTBee (NXC)

Post by HaWe »

no ideas...?
mightor
Site Admin
Posts: 1079
Joined: 25 Sep 2010, 15:02
Location: Rotterdam, Netherlands
Contact:

Re: Dexter NXTBee (NXC)

Post by mightor »

You should consider contacting Dexter Industries or perhaps dropping them a note to let them know there's a question on these forums.

- Xander
| My Blog: I'd Rather Be Building Robots (http://botbench.com)
| RobotC 3rd Party Driver Suite: (http://rdpartyrobotcdr.sourceforge.net)
| Some people, when confronted with a problem, think, "I know, I'll use threads,"
| and then two they hav erpoblesms. (@nedbat)
HaWe
Posts: 2500
Joined: 04 Nov 2014, 19:00

Re: Dexter NXTBee (NXC)

Post by HaWe »

thank you, I did so.
Maybe there already is a better, newer version available.
I don't understand that "goofy" thing by the sender, and I wonder if there are meanwhile more advanced commands for controlling remote motors and polling remote sensors and other values of interest by nxtBee - and how to comunicate with more than 3 or 4 NXTs by each other.
jdc2106
Posts: 12
Joined: 13 Oct 2010, 12:41

Re: Dexter NXTBee (NXC)

Post by jdc2106 »

Hello,

I'll try to answer these questions, but it has been some time since I've played around with the NXC code. I believe John Hansen originally wrote these, but I can't remember.


- at the start the variable byte mlen is declared but never used: what was it intended for?
Your guess is as good as mine. If you can take it out and it can compile, it might be either a typo, or artifact from a previous coding mission.


- how can the receiver know how long the recieved string is, or does the code work with all strings of all lengths (which would be very convenient)?
If I remember correctly the RS485 buffer is 128 bytes. This code works, I believe, by reading everything in the buffer and putting it into a string. The buffer is read, no matter what size, into string.

- what is the maximum string length? 128? 256? 32767?
In this example, the string can be as long as strings are allowed; I would check with John about this, but I think it is limited by the size of the RS485 serial buffer, which again, if I recall correctly is 128 bytes.

- a baud rate of 9600 has been used; is it possible to use a faster one? How much is possible?
The max supported baud rate of the NXTBee is 115200; The NXTBee can support the following baud rates: 1200, 2400, 4800, 9600, 19200, 38400, 57600, 115200

You can see more about baud rates in NXC here:
http://bricxcc.sourceforge.net/nbc/nxcd ... tants.html



Hope this helps!
John Cole

Dexter Industries
http://www.dexterindustries.com
HaWe
Posts: 2500
Joined: 04 Nov 2014, 19:00

Re: Dexter NXTBee (NXC)

Post by HaWe »

Thank you for your reply!
For buying those quite expensive nxtBees it would be very important to have more advanced commands:
- for controlling remote motors
- polling remote sensors
- polling other values of interest by nxtBee
- and to know how to comunicate with more than 3 or 4 NXTs by each other.
mightor
Site Admin
Posts: 1079
Joined: 25 Sep 2010, 15:02
Location: Rotterdam, Netherlands
Contact:

Re: Dexter NXTBee (NXC)

Post by mightor »

The NXTBees are merely conduits for your own protocol. Think of them as RS485 extenders.

- Xander
| My Blog: I'd Rather Be Building Robots (http://botbench.com)
| RobotC 3rd Party Driver Suite: (http://rdpartyrobotcdr.sourceforge.net)
| Some people, when confronted with a problem, think, "I know, I'll use threads,"
| and then two they hav erpoblesms. (@nedbat)
HaWe
Posts: 2500
Joined: 04 Nov 2014, 19:00

Re: Dexter NXTBee (NXC)

Post by HaWe »

yes, but it's too expensive (280$ for 4 nxtBees) if there are just some raw rs485 commands - there should be some extended rs485 commands (how I roughly described) so that it's worth while to buy them (IMO). E.g., I still don't use rs485 because those raw cmds are far too complicated to handle.
A rs485 network communication protocol would be appreciated for r/w remote IOs and values with 4,5,6 or even more NXTs.
jdc2106
Posts: 12
Joined: 13 Oct 2010, 12:41

Re: Dexter NXTBee (NXC)

Post by jdc2106 »

Mark Crosbie has done a fantastic job of putting together a communications library that handles many of these functions. He does not handle all of them, but the library is pretty advanced. It is, however, for RobotC. You can see more on it here:
http://dexterindustries.com/blog/2012/0 ... e-library/
John Cole

Dexter Industries
http://www.dexterindustries.com
HaWe
Posts: 2500
Joined: 04 Nov 2014, 19:00

Re: Dexter NXTBee (NXC)

Post by HaWe »

at first sight: that's really awsome, just what I've expected since a long time - indeed, I see some of my own rough concepts implemented.

But I personally am no low level programmer, so I never would get that built up a/o translated to NXC (which is different to RobotC or Java, often just in important details - but I use neither).

Wish we could have that for NXC users, too!

BTW, this is one of the reasons why I very much regret that both RobotC and NXC do not go by the rules of ANSI C.
If both did then there wouldn't exist any problems of code portability from the RobotC platform to the NXC platform.
Of course, the ANSI committee made those rules (e.g., ANSI C 99) just for such compatibility reasons - I wonder why no one cares (and "jeder kocht sein eigenes Süppchen", as we say...) :evil:
So after all, who would take the effort and transposes the RobotC code into NXC code?
Post Reply

Who is online

Users browsing this forum: No registered users and 3 guests