View unanswered posts | View active topics It is currently Wed Oct 17, 2018 12:27 pm

Reply to topic  [ 2 posts ] 
Communication NXT to PC 
Author Message

Joined: Thu Feb 09, 2012 1:11 pm
Posts: 4
Post Communication NXT to PC

I work on a draft resolution to a sudoku grid, a C # program detects the sudoku grid on the smartphone, solves the grid and sending data to the nxt to fill the remaining boxes.
The dailogue between the PC and the nxt is OK, but the nxt must send a command to the computer in each filled boxes.

I tried several commands but feel results :-( , the PC does not see information and yet the program in C # wait for further information.

    cCmdMessageAddToQueue(kQueueID, nXmitBuffer, kMaxSizeOfMessage);
    TFileIOResult messageOut = cCmdMessageWriteToBluetooth(0, nTransmitBuffer, kMaxSizeOfMessage, mailbox1);
    TFileIOResult nxtWriteRawBluetooth(const short nStream, ubyte *pData, const short nLength);

Has anyone ever worked on communication between the NXT and a program on a PC, especially the part sends information to the PC via a mailbox.

Thank you for your help.
Excuse me for my English is not great. :?


Sun Jun 10, 2012 5:07 am

Joined: Tue Feb 28, 2012 3:10 pm
Posts: 197
Post Re: Communication NXT to PC
in robotc to write I use
const TMailboxIDs kQueueID = mailbox1;
const int kMaxSizeOfMessage = 8;

TFileIOResult nBTCmdRdErrorStatus;
int nSizeOfMessage;
ubyte nRcvBuffer[kMaxSizeOfMessage * 5];
string resetReply = "SlamBotSlave1";
byte buf[20];

void WriteStuff() {
  memcpy(buf, resetReply, sizeof(resetReply));
  cCmdMessageWriteToBluetooth(buf, sizeof(buf), mailbox1);

to read I use
nBTCmdRdErrorStatus = cCmdMessageRead(nRcvBuffer, nSizeOfMessage, kQueueID);
    if (nBTCmdRdErrorStatus == ioRsltSuccess)

On the PC side, I use mindsqualls (
string ExpectMailReply()
            // wait a bit for an NXT reply, and return it as a string
            // timeout returns null
            const int timeOut = 1000;
            DateTime timeoutAt = DateTime.Now + new TimeSpan(0, 0, 0, 0, timeOut);

                    string reply = Brick.CommLink.MessageRead(NxtMailbox2.Box1, 0, true);
                    return reply;
                catch (NxtCommunicationProtocolException ex)
                    if (ex.errorMessage != NKH.MindSqualls.NxtErrorMessage.SpecifiedMailboxQueueIsEmpty)
            } while (DateTime.Now < timeoutAt);

            return null;

I believe this is doing similar to what you intend.

Mike aka Spiked3

Sun Jun 10, 2012 6:40 am
Display posts from previous:  Sort by  
Reply to topic   [ 2 posts ] 

Who is online

Users browsing this forum: No registered users and 2 guests

You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  

Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group.
Designed by ST Software for PTF.