Discussion specific to NXT-G, NXC, NBC, RobotC, Lejos, and more.
muntoo
Posts: 834 Joined: 01 Oct 2010, 02:54
Location: Your Worst Nightmare
Contact:
Post
by muntoo » 17 Oct 2010, 23:04
Is there any function that allows you find BlueTooth Devices?
Here's what I got so far:
Code: Select all
/*
byte BTDevicesEnum(string &devnames[])
Lists the names of the devices in devnames.
Returns the array length of devnames.
*/
byte BTDevicesEnum(string &devnames[])
{
byte btdc = BTDeviceCount();
ArrayInit(devnames, "", btdc);
for(/*unsigned int*/ byte devidx = 0; devidx < btdc; devidx++)
devnames[devidx] = BTDeviceName(devidx);
return(btdc);
}
Last edited by
muntoo on 05 Mar 2011, 06:17, edited 2 times in total.
Commit to LEGO Mindstorms Robotics Stack Exchange:
bit.ly/MindstormsSE
Commit to LEGO Stack Exchange:
bit.ly/Area51LEGOcommit
afanofosc
Site Admin
Posts: 1256 Joined: 26 Sep 2010, 19:36
Location: Nashville, TN
Contact:
Post
by afanofosc » 18 Oct 2010, 02:02
I'm not sure what you mean by "allows you to find BlueTooth Devices". I would not copy the names from the Comm module's IOMap structure into a separate array since that just puts the data in two places. Are you wanting to just list the names of known devices from the BTDevice table? Or are you wanting to programmatically connect to a known device?
John Hansen
muntoo
Posts: 834 Joined: 01 Oct 2010, 02:54
Location: Your Worst Nightmare
Contact:
Post
by muntoo » 18 Oct 2010, 02:24
Yeah, I'm trying to connect BT devices inside the program. I just realized that those BTDevice() functions are listing the devices in the table...
Know anything equivalent to doing NXT->Bluetooth->Search, but in a program, of course?
Commit to LEGO Mindstorms Robotics Stack Exchange:
bit.ly/MindstormsSE
Commit to LEGO Stack Exchange:
bit.ly/Area51LEGOcommit
afanofosc
Site Admin
Posts: 1256 Joined: 26 Sep 2010, 19:36
Location: Nashville, TN
Contact:
Post
by afanofosc » 18 Oct 2010, 02:32
Maybe using CommExecuteFunction but in theory you would just get all the devices you may need in your device table before you start running your program and then you can connect/disconnect to one of those devices from within your program.
Code: Select all
VarsUi.BTCommand = (UBYTE)SEARCH;
VarsUi.BTPar1 = (UBYTE)1;
VarsUi.BTPar2 = (UBYTE)0;
if (pMapComm->pFunc(VarsUi.BTCommand,VarsUi.BTPar1,VarsUi.BTPar2,0,NULL,&(VarsUi.BTResult)) == SUCCESS)
You can do that same kind of thing, iirc, using SysCommExecuteFunction with the CommExecuteFunctionType structure.
John Hansen
muntoo
Posts: 834 Joined: 01 Oct 2010, 02:54
Location: Your Worst Nightmare
Contact:
Post
by muntoo » 18 Oct 2010, 05:15
Still can't figure it out.
Code: Select all
/*
byte BTDevicesEnum(string &devnames[])
Lists the names of the devices in devnames.
Returns the array length of devnames.
*/
byte BTDevicesEnum(string &devnames[])
{
CommExecuteFunctionType ceftArgs;
ceftArgs.Cmd = INTF_SEARCH;
for(ceftArgs.RetVal = LDR_BTBUSY; ceftArgs.RetVal != LDR_SUCCESS; SysCommExecuteFunction(ceftArgs))
{
NumOut(0, LCD_LINE7, ceftArgs.RetVal, 1);
Wait(1000);
}
Wait(2000);
/*
Wait(1000);
ceftArgs.Cmd = INTF_STOPSEARCH;
SysCommExecuteFunction(ceftArgs);
Wait(1000);
*/
byte btdc = BTDeviceCount();
ArrayInit(devnames, "", btdc);
for(/*unsigned int*/ byte devidx = 0; devidx < btdc; devidx++)
devnames[devidx] = BTDeviceName(devidx);
return(btdc);
}
Is the "table" supposed to be "My Contacts"?
Commit to LEGO Mindstorms Robotics Stack Exchange:
bit.ly/MindstormsSE
Commit to LEGO Stack Exchange:
bit.ly/Area51LEGOcommit
muntoo
Posts: 834 Joined: 01 Oct 2010, 02:54
Location: Your Worst Nightmare
Contact:
Post
by muntoo » 23 Oct 2010, 18:54
*bump*
[Isn't there supposed to be a "bump" button on these forums?]
Commit to LEGO Mindstorms Robotics Stack Exchange:
bit.ly/MindstormsSE
Commit to LEGO Stack Exchange:
bit.ly/Area51LEGOcommit
muntoo
Posts: 834 Joined: 01 Oct 2010, 02:54
Location: Your Worst Nightmare
Contact:
Post
by muntoo » 31 Oct 2010, 00:27
How can I search for, and add devices to the BlueTooth device table?
Here's what I got so far:
Code: Select all
/*
byte BTDevicesEnum(string &devnames[])
Lists the names of the devices in devnames.
Returns the array length of devnames.
*/
byte BTDevicesEnum(string &devnames[])
{
// INTF_STOPSEARCH INTF_CONNECT INTF_CONNECTBYNAME INTF_REMOVEDEVICE INTF_SETCMDMODE
// LDR_INPROGRESS == 0x0001 == 1
// LDR_BTBUSY == 0x9400 == 37888
//BTDataMode()
//BTDeviceStatus()
unsigned long timer = 0;
CommExecuteFunctionType ceftArgs;
ceftArgs.Cmd = INTF_SEARCH;
SysCommExecuteFunction(ceftArgs);
timer = CurrentTick();
while(((timer + 20000) > CurrentTick()) && (!ButtonPressed(BTNCENTER, 0)))
{
ClearLine(LCD_LINE4);
ClearLine(LCD_LINE5);
NumOut(0, LCD_LINE4, ceftArgs.RetVal, 0);
NumOut(0, LCD_LINE5, ceftArgs.Result, 0);
}
while(ButtonPressed(BTNCENTER, 0));
ceftArgs.Cmd = INTF_STOPSEARCH;
SysCommExecuteFunction(ceftArgs);
timer = CurrentTick();
while(((timer + 20000) > CurrentTick()) && (!ButtonPressed(BTNCENTER, 0)))
{
ClearLine(LCD_LINE6);
ClearLine(LCD_LINE7);
NumOut(0, LCD_LINE6, ceftArgs.RetVal, 0);
NumOut(0, LCD_LINE7, ceftArgs.Result, 0);
}
while(ButtonPressed(BTNCENTER, 0));
byte btdc = BTDeviceCount();
ArrayInit(devnames, "", btdc);
for(/*unsigned int*/ byte devidx = 0; devidx < btdc; devidx++)
devnames[devidx] = BTDeviceName(devidx);
return(btdc);
}
Commit to LEGO Mindstorms Robotics Stack Exchange:
bit.ly/MindstormsSE
Commit to LEGO Stack Exchange:
bit.ly/Area51LEGOcommit
afanofosc
Site Admin
Posts: 1256 Joined: 26 Sep 2010, 19:36
Location: Nashville, TN
Contact:
Post
by afanofosc » 31 Oct 2010, 19:28
As I mentioned already, I just don't see the point to searching for other bluetooth devices while your program is running. Just get all the devices you want/need into the device table before you start your program by using the NXT menu system.
John Hansen
Users browsing this forum: No registered users and 4 guests