|
发表于 2011-2-19 00:33:33
|
显示全部楼层
刚才看了一下函数库,在NXC中貌似是可以做到的。
有一个这样的函数:
void SysCommBTConnection ( CommBTConnectionType & args ) [inline]
它的参数args实际上是一个指向CommBTConnectionType结构的指针,定义如下:
Data Fields
unsigned int Result
byte Action
string Name
byte ConnectionSlot
其中string Name,就是提供要连接的从机的名称。
help中的示例如下:- #define CONNECTION 1
- task main()
- {
- CommBTConnectionType args;
- args.Name = "NXT2"; // whatever the slave NXT's name is
- args.ConnectionSlot = CONNECTION; // this is the desired connection slot (the above code uses 1)
- args.Action = TRUE; // could use some #define with a non-zero value to connect. 0 == disconnect
- if(!BluetoothStatus(CONNECTION)==NO_ERR)
- {
- SysCommBTConnection(args); // try to connect.
- for (int i = 0; i < 2000; i++) {
- NumOut(0, LCD_LINE3, args.Result);
- Wait(1);
- }
- // Wait(5000); // let the connection get created
- if (args.Result == LDR_SUCCESS)
- {
- // we are connected
- TextOut(0, LCD_LINE1, "success");
- }
- else {
- TextOut(0, LCD_LINE1, "failure");
- NumOut(0, LCD_LINE2, args.Result);
- }
- }
- Wait(SEC_10);
- }
复制代码 |
|