View unanswered posts | View active topics It is currently Thu Nov 27, 2014 1:45 pm






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

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

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);
    sendMessage(nMessageID);

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. :?

Thierry


Sun Jun 10, 2012 5:07 am
Profile
Expert

Joined: Tue Feb 28, 2012 3:10 pm
Posts: 195
Post Re: Communication NXT to PC
in robotc to write I use
Code:
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
Code:
nBTCmdRdErrorStatus = cCmdMessageRead(nRcvBuffer, nSizeOfMessage, kQueueID);
    if (nBTCmdRdErrorStatus == ioRsltSuccess)
      ParseAndProcess();


On the PC side, I use mindsqualls (http://www.mindsqualls.net/).
Code:
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);

            do
            {
                try
                {
                    string reply = Brick.CommLink.MessageRead(NxtMailbox2.Box1, 0, true);
                    return reply;
                }
                catch (NxtCommunicationProtocolException ex)
                {
                    if (ex.errorMessage != NKH.MindSqualls.NxtErrorMessage.SpecifiedMailboxQueueIsEmpty)
                    {
                        //throw;
                    }
                }
                System.Threading.Thread.Sleep(50);
            } while (DateTime.Now < timeoutAt);

            return null;
        }


I believe this is doing similar to what you intend.

_________________
Mike aka Spiked3
http://www.spiked3.com


Sun Jun 10, 2012 6:40 am
Profile
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.