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 / 488
487  |  489
Subject: 
Re: Bluetooth Comm Problem
Newsgroups: 
lugnet.robotics.nxt
Date: 
Fri, 16 Feb 2007 03:09:22 GMT
Viewed: 
14228 times
  
Dick,

Thanks! I tried it out tonight and got consistent messages from the PC. You
were correct about having to continually do message reads until I get
something. I didn't have to do the wait for a second STAT_COMM_PENDING (32)
or the 200 ms wait. I just had to keep reading until I got a NO_ERR (0) and
then there was always a message received. I printed out the result when I
didn't get a NO_ERR or STAT_COMM_PENDING to see what would show up and, as
expected, I always got STAT_MSG_EMPTY_MAILBOX (64). I would get about 100 of
these before actually receiving each message. Here is the entire program:

#include "NXTDefs.h"

dseg segment
  msg_out byte[] 'Hi.'
  msg_in byte[]
  count1 uword 0
  count2 uword 0
  result uword
dseg ends

thread main

  strtoarr msg_out, msg_out
  replace msg_out, msg_out, 2, 0  // Null terminate

Forever:
  RemoteMessageWrite(1, 0, msg_out, result) // Send via BT (conn=1, queue=0)
WaitMsgWrite:
  BluetoothStatus(1, result) // check status
  brcmp EQ, WaitMsgWrite, result, STAT_COMM_PENDING // Gone out yet?

// Now read response (response from PC is "OKn"
// where n is incremented each time Hi is sent)
WaitMsgRead:
  ReceiveMessage(0, 1, msg_in, result) // queue=0
  brcmp EQ, MsgReceived, result, NO_ERR // Received Message
  brcmp EQ, WaitMsgRead, result, STAT_COMM_PENDING // Gone out yet?

  // If we get here, no message received
  // See what the result code was
  TextOut(0,LCD_LINE1,0,'result=')
  NumOut(50,LCD_LINE1,0,result)

  // See how many times we get here
  add count1, count1, 1
  TextOut(0,LCD_LINE2,0,'count=')
  NumOut(50,LCD_LINE2,0,count1)

  jmp WaitMsgRead // Wait some more

MsgReceived:
  // Got a message, print it and the count
  // to see if it matches count from PC
  TextOut(50,LCD_LINE4,0,msg_in)
  add count2, count2, 1
  TextOut(0,LCD_LINE5,0,'count=')
  NumOut(50,LCD_LINE5,0,count2)
  wait 1000 // Just so it doesn't go so fast
  jmp Forever

endt



Message has 1 Reply:
  Re: Bluetooth Comm Problem
 
(...) Dick and David, Thanks for posting this conversation here. Even though I'm not participating directly, I am reading it and as I'm touching up the Bluetooth support for pbLua right now, this has given me invaluable insight into how the (...) (18 years ago, 16-Feb-07, to lugnet.robotics.nxt)

Message is in Reply To:
  RE: Bluetooth Comm Problem
 
The NXT-G firmware implementation for mailbox messaging is extremely funky. I don't think your code is working properly for this implementation. You need to be continuously calling "ReadMessage" and only check for "a message was found" error code. (...) (18 years ago, 14-Feb-07, to lugnet.robotics.nxt)

8 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
    
Active threads in NXT programmable brick

 
Verified and Trusted Team of Hackers
4 hours ago
Custom Search

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