ROBOTC.net forums
http://robotc.net/forums/

Bluetooth communication, between master and two slaves (NXT)
http://robotc.net/forums/viewtopic.php?f=1&t=10465
Page 1 of 1

Author:  asnp [ Wed Feb 04, 2015 9:19 am ]
Post subject:  Bluetooth communication, between master and two slaves (NXT)

Hello all
I have a problem with bluetooth communication, between master and two slaves (NXT bricks).
All messages from master are received only by first slave connected to stream no 1, second slave (stream no 2) receives nothing.
It seems that the parameter 'nStream' of cCmdMessageWriteToBluetooth function is ignored. Below I attach the source code.
Thanks in advance for your comments.

RobotC ver. 3.62 for Lego Mindstorms
//---------------------------------------------------------------------------
// MASTER
//---------------------------------------------------------------------------
task main()
{
char msg[20];
int val;
TFileIOResult res;

eraseDisplay();
bNxtLCDStatusDisplay = true;
val = 1;
while(1)
{
sprintf(msg, "A%d", val);
while(bBTBusy)
wait1Msec(1);
res = cCmdMessageWriteToBluetooth(1, (ubyte*)msg, strlen(msg), mailbox1);
nxtDisplayCenteredTextLine(3, "msg=%s,res=0x%02X", &msg, res);
wait1msec(5000);
//
sprintf(msg, "B%d", val);
while(bBTBusy)
wait1Msec(1);
res = cCmdMessageWriteToBluetooth(2, (ubyte*)msg, strlen(msg), mailbox1);
nxtDisplayCenteredTextLine(5, "msg=%s,res=0x%02X", &msg, res);
//
wait1msec(5000);
val++;
}
}
//---------------------------------------------------------------------------
// SLAVES
//---------------------------------------------------------------------------
task main()
{
char msg[20];
int size;

eraseDisplay();
bNxtLCDStatusDisplay = true;
while(1)
{
while(bBTBusy)
wait1Msec(1);
size = cCmdMessageGetSize(mailbox1);
if(size > 0)
{
while(bBTBusy)
wait1Msec(1);
cCmdMessageRead(msg, size, mailbox1);
msg[size] = '\0';
nxtDisplayCenteredBigTextLine(4, "%s", &msg);
}
wait1Msec(1);
}
}

Page 1 of 1 All times are UTC - 5 hours [ DST ]
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
http://www.phpbb.com/