To LUGNET HomepageTo LUGNET News HomepageTo LUGNET Guide Homepage
 Help on Searching
 
Post new message to lugnet.robotics.nxtOpen lugnet.robotics.nxt in your NNTP NewsreaderTo LUGNET News Traffic PageSign In (Members)
 Robotics / NXT / 604
603  |  605
Subject: 
Logging from NXT to PC via Bluetooth
Newsgroups: 
lugnet.robotics.nxt
Date: 
Fri, 6 Apr 2007 15:58:14 GMT
Viewed: 
18796 times
  
I have been working for some time on an advanced NBC application that sends/logs
data over Bluetooth from the NXT to a PC. The header for the file explains, in
detail, how it works, so I'll just paste it here.

It is compiled with a pre-released version of John Hansen's NBC (1.0.1.b28)
which should be coming out soon. This version is needed due to some
preprocessing enhancements that are used in this application.

Additionally John is adding the capability to include NBC applications in NXC,
so you should be able to use this application in NXC as well when the new
version comes out.

I don't have a web page to put this on, so if you would like a copy, just send
me an email.

Here's the header:

////////////////////////////////////////////////////////////////////////////////
//
// NxtBtLogger.nbc
//
//  Written by: David Wallace
//  Created: 6 April 2007
//
//  Overview
//  --------
//  This program allows you to send (log) strings and numbers over BT to a PC.
//  I have written a Perl script to receive the data, but you can use Hyperterm
//  or some other terminal program if you don't mind seeing the '<' symbol
//  potentially followed by a NULL character which is the two-byte packet
//  length. Or, you can write your own program. The packet is described later.
//
//  Modes
//  -----
//  There are three modes of logging that are controlled via compile flags.
//  These modes are mutually exclusive. They are:
//
//    Stop On Full mode (NBL_STOP_ON_FULL)
//    Overwrite mode (NBL_OVERWRITE)
//    Continuous mode (NBL_CONTINUOUS_DUMP)
//
//  Stop On Full Mode
//  -----------------
//  Stop On Full mode will stop logging when the buffer is full. In this mode,
//  you can either set a compile flag to dump as soon as the buffer is full,
//  or you can call BT_Dump at any time to dump the data. Dumping is done
//  in a thread so that your threads are not blocked for a long time.
//
//  Overwrite Mode
//  --------------
//  Overwrite mode will continue logging when the end of the buffer is reached
//  and wrap to the beginning of the buffer, overwriting old data. A tilde (~)
//  character is inserted in the buffer at the wrap point so you can see where
//  the wrap occurred. This character can be changed in a compile flag.
//  Again, BT_Dump can be called at any time to dump the buffer.
//
//  Continuous Mode
//  ---------------
//  Continuous mode will continually dump data to BT in real time via a thread.
//  All data is logged in this mode (i.e. no data is lost). If the buffer
//  becomes full, logging will be BLOCKED and dumping will continue until the
//  level is below a user-defined point (NBL_BFR_DUMP_LEVEL). Since your thread
//  can be blocked in this mode, it is recommended to set the level to a point
//  that is near the end of the buffer. This way, the blocking time will be
//  minimized. If you find that the buffer becomes full frequently, you may
//  want to increase the size. The default size is 4K bytes.
//
//  Other Features
//  --------------
//  1. You can enable/disable logging on-the-fly via subroutine calls.
//
//  2. Button control of logging enable/disable and dumping. Press the
//     center button to enable/disable logging (it toggles) and press the
//     right button to dump. You can change the buttons used through
//     compile flags. If you enable button control, you must have the
//     button.nbc program in the include path.
//
//  3. Special characters.
//
//    Strings can contain:
//      \r - carriage return
//      \n - line feed
//      \t - tab
//      \b - backspace
//      \0 - Null
//      \Q - double quote
//      \q - single quote
//      \s - semicolon (normally a comment character)
//
//    Note: If you are using a terminal program to monitor output, use \r\n
//          to get a new line.
//
//  Packet Format
//  -------------
//
//  +------------+------------+-----------------------------+
//  |            |            |                             |
//  | LSB Length | MSB Length | Data bytes ...              |
//  |            |            |                             |
//  +------------+------------+-----------------------------+
//
//  How to Use
//  ----------
//  1. Put this program and button.nbc in the same folder.
//  2. #include this program file in your program.
//  3. Call NBL_Init at your program startup.
//  4. Call BT_WRITE_STR and BT_WRITE_NUM to log your strings/numbers.
//  5. Start the monitoring program on the device which will capture the data.
//  6. Initiate a BT connection in the NXT menu to the device which will
//     capture the data. This program assumes that connection #1 is used on
//     the NXT. This can be changed via the constant NBL_NXT_BT_CONNECTION.
//  7. Start your program on the NXT. If you created the BT connection properly
//     on the NXT, you will see "BT OK" displayed on the NXT screen.
//     If not, you will see "BT not ready".
//
//    Example usage can be seen in the main thread below.
//    Just uncomment the #define NBL_TEST if you want to test the example code.
//
//    The receiving program may be stopped and then restarted and the data will
//    still be flowing from the NXT.
//
///////////////////////////////////////////////////////////////////////////////



1 Message 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