Loginskip to content

Archive for May 30th, 2008

Connecting BT using NXC

Friday, May 30th, 2008

As happend several time in the past, this forum topic proved what I considered ‘impossible’ (and has been telling this “truth” over and over in the forum..) is simple… this time it is the ability to connect a BT device programatically within NXC (and the standard firmware). This ability has long been possible in alternative firmware (pbLua, RobotC etc.) by so far I allways thought it can’t be done in NXT regular firmware. As it turns out - I was wrong.
Thanks to our forum user ronmcrae for sending this code:

asm { dseg segment
args TCommExecuteFunction // define argument structure for syscall
dseg ends
set args.Cmd INTF_CONNECT // request bluetooth connection initiation
set args.Param1 0 // assumes the first entry in the table
set args.Param2 1 // connect on channel 1
syscall CommExecuteFunction,args} // and make it happen

On another site (www.mindstormsforum.de) I found an alternative code (see post here):

void connect() {
CommExecuteFunctionType args;
args.Cmd = INTF_CONNECT;
args.Param1 = 0; // device index
args.Param2 = 1; // connection index

SysCommExecuteFunction(args);
}

void disconnect() {
CommExecuteFunctionType args;
args.Cmd = INTF_DISCONNECT;
args.Param1 = 1; // connection index

SysCommExecuteFunction(args);
}

task main() {
connect();
Wait(5000);
disconnect();
}

I didn’t test this, and can’t read the post neither.. but it seems a cleaner way (no asm segement) to do the same thing.

All these have one drawback - they assume the NXT you want to attach to is in the position 0 in the stored ‘past connections’ table on the Master NXT. Now I suppose there’s no way to find an NXT by name on this list, or am I wrong again ;) ?

btw. since at the moment the LabVIEW SysCall is limited to a predefined set, I couldn’t figure out a way to do the same in LV (and then in an NXT-G block). Again - I might be wrong… but I am more confident on this one, unfortunatly.

Guy Ziv