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 / 562
561  |  563
Subject: 
Re: NBC NXT to NXT communication example
Newsgroups: 
lugnet.robotics.nxt
Date: 
Wed, 14 Mar 2007 14:38:04 GMT
Viewed: 
19430 times
  
In lugnet.robotics.nxt, Rainer Worbis wrote:
Hallo,

has anyone a simple example for an BT NXT to NXT communication?
I tried to get this working and even everyone says it works i can't get it to
work.


The exact same code that Danny B includes in the NXC Tutorial should work fine
when translated into NBC.  I have not tested this yet but here is a quick
conversion:

//MASTER
#include "NXTDefs.h"

#define BT_CONN 1
#define INBOX 1
#define OUTBOX 5

dseg segment
  btCheckconn sword
dseg ends

subroutine BTCheck
  dseg segment
    btStatusResult byte
  dseg ends
  BluetoothStatus(btCheckconn, btStatusResult)
  brtst EQ, btCheckDone, btStatusResult
    TextOut(5, LCD_LINE2, 'Error')
    wait 1000
    stop TRUE
btCheckDone:
  return
ends

thread main
  dseg segment
    in byte[]
    out byte[]
    iStr byte[]
    i sword
    res byte
  dseg ends
  set btCheckconn, BT_CONN
  call BTCheck
WhileTrueLoop:
    numtostr iStr, i
    strcat out, 'M', iStr
    TextOut(10,LCD_LINE1,'Master Test')
    TextOut(0,LCD_LINE2,'IN:')
    TextOut(0,LCD_LINE4,'OUT:')
    ReceiveRemoteString(INBOX, TRUE, in, res)
    SendRemoteString(BT_CONN, OUTBOX, out, res)
    TextOut(10,LCD_LINE3,in)
    TextOut(10,LCD_LINE5,out)
    wait 100
    add i, i, 1
  jmp WhileTrueLoop
endt


//SLAVE
#include "NXTDefs.h"

#define INBOX 5
#define OUTBOX 1

dseg segment
  btCheckconn sword
dseg ends

subroutine BTCheck
  dseg segment
    btStatusResult byte
  dseg ends
  BluetoothStatus(btCheckconn, btStatusResult)
  brtst EQ, btCheckDone, btStatusResult
    TextOut(5, LCD_LINE2, 'Error')
    wait 1000
    stop TRUE
btCheckDone:
  return
ends

thread main
  dseg segment
    in byte[]
    out byte[]
    iStr byte[]
    i sword
    res byte
  dseg ends
  set btCheckconn, 0
  call BTCheck
WhileTrueLoop:
    numtostr iStr, i
    strcat out, 'S', iStr
    TextOut(10,LCD_LINE1,'Slave Test')
    TextOut(0,LCD_LINE2,'IN:')
    TextOut(0,LCD_LINE4,'OUT:')
    ReceiveRemoteString(INBOX, TRUE, in, res)
    SendResponseString(OUTBOX, out, res)
    TextOut(10,LCD_LINE3,in)
    TextOut(10,LCD_LINE5,out)
    wait 100
    add i, i, 1
  jmp WhileTrueLoop
endt



Message has 1 Reply:
  Re: NBC NXT to NXT communication example
 
(...) Works like a charm! Thank you Rainer (18 years ago, 14-Mar-07, to lugnet.robotics.nxt)

Message is in Reply To:
  NBC NXT to NXT communication example
 
Hallo, has anyone a simple example for an BT NXT to NXT communication? I tried to get this working and even everyone says it works i can't get it to work. Thanks, Rainer (18 years ago, 14-Mar-07, to lugnet.robotics.nxt)

3 Messages in This Thread:

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

This Message and its Replies on One Page:
Nested:  All | Brief | Compact | Dots
Linear:  All | Brief | Compact
    

Custom Search

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