tcwan wrote:lizard381 wrote:
The problem is I'm not able to select NXT, it just stays there with the Select button grayed out. Has anyone had a similar experience? I called Lego tech support and they said it was because it's one of the new Macbooks with an incompatible bluetooth chipset, but after hanging up I realised that this doesn't make sense since NeXT Tools can connect...
Kami
I see the dialog box as well, but I can select the NXT on my Mac.
Interestingly NeXT Tool does not bring up the dialog. I'm trying to understand why there is a difference.
Ok. I've finally managed to recreate the main.cpp example in XCode 3.2.6, Mac OSX 10.6.7. In the Edit Project Settings Dialog, I *MUST* configure the SDK for Architecture "32-bit Intel", Base SDK "Mac OSX 10.5". Selecting 32/64 or 10.6 will cause the linker to fail to link the VISA framework.
The project can be created as an empty C++ project in XCode, and then populated with the following:
- 1. All Fantom *.h include files
2. The visatype.h include file
3. The Fantom and VISA frameworks (Add Framework, choose Other... and navigate to the correct path /Library/Frameworks/...)
4. The main.cpp example file from the Fantom SDK documentation
There are some missing pieces to the main.cpp example for execution on the Mac. If you compile it as a straight C++ program, you'll see the NSAutoreleasePool leaks as Kami (lizard381) mentioned, and the BT dialog box does not allow selection. To solve this, the XCode project must be contain an Objective-C++ main.mm instead. Everything else is pretty much identical to the C++ only project, except that main.cpp is now main.mm, and the code is modified as follows:
- 1. The C++ main() is renamed (I used maincpp())
2. Add FoundationKit and AppKit Frameworks (these are default frameworks)
3. There must be an Objective-C++ main() which does the following:
(a) Initialize NSApplication
(b) Create the NSAutoreleasePool and manage its disposal after the maincpp() exits.
For more information, look for the NSApplication Class Reference in the XCode Documentation, and also create an empty Cocoa project and an empty iOS project to inspect the main.m contents.
Code: Select all
//
// main.mm
// FantomTest2
//
// Created by tcmac on 18/05/2011.
// Copyright 2011 __MyCompanyName__. All rights reserved.
//
#import <Cocoa/Cocoa.h>
#include "fantom/iNXT.h"
#include "fantom/iNXTIterator.h"
#include "fantom/tStatus.h"
#include <string.h>
#include <iostream>
int maincpp(int argc, char *argv[]);
int main(int argc, char *argv[]) {
[NSApplication sharedApplication];
NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
int retVal = maincpp(argc, argv);
[pool release];
return retVal;
}
/*
© Copyright 2006,
National Instruments Corporation.
All rights reserved.
Originated: 10 March 2006
*/
// includes...
// globally-scoped globals...
// private globals...
// methods...
int _VI_FUNCC maincpp( int argc, char** argv )
{
nFANTOM100::tStatus status;
nFANTOM100::iNXTIterator* nxtIteratorPtr = NULL;
nFANTOM100::iNXT* nxtPtr = NULL;
nFANTOM100::iFile* filePtr = NULL;
nFANTOM100::iFileIterator* fileIteratorPtr = NULL;
// Create an NXT iterator object which is used to find all accessible NXT devices.
nxtIteratorPtr = nFANTOM100::iNXT::createNXTIterator(
true /* don't search for NXTs over Bluetooth (only search USB) */,
0 /* timeout for Bluetooth discovery ignored */, status );
// Creating the NXT iterator object could fail, better check status before dereferencing a
// potentially NULL pointer.
if( status.isNotFatal())
{
// Create an NXT object for the first NXT that was found. Note that if a NXT is found
// over BT, the computer and the NXT must be paired before an NXT object can be
// created. This can be done programatically using the iNXT::pairBluetooth method.
nxtPtr = nxtIteratorPtr->getNXT( status );
// Destroy the NXT iterator object which we no longer need
nFANTOM100::iNXT::destroyNXTIterator( nxtIteratorPtr );
}
// Creating the NXT object could fail, better check status before dereferencing a potentially
// NULL pointer.
if( status.isNotFatal())
{
ViUInt8 protocolVersionMajor = 0;
ViUInt8 protocolVersionMinor = 0;
ViUInt8 firmwareVersionMajor = 0;
ViUInt8 firmwareVersionMinor = 0;
// Query the version numbers for the protocol and firmware installed on the NXT.
nxtPtr->getFirmwareVersion( protocolVersionMajor, protocolVersionMinor,
firmwareVersionMajor, firmwareVersionMinor, status );
// This is a direct command to play a tone.
ViUInt8 directCommandBuffer[] = { 0x03, 0x00, 0x18, 0x10, 0x00 };
// Send the direct command to the NXT.
nxtPtr->sendDirectCommand( false /* a response is not required for this direct command */,
reinterpret_cast< ViByte* >( directCommandBuffer ), sizeof( directCommandBuffer ),
NULL /* no response buffer */, 0 /* no response buffer, specify 0 for size */, status );
// Create a file object
filePtr = nxtPtr->createFile( "example.log", status );
}
// Creating the file object could fail, better check status before dereferencing a
// potentially NULL pointer.
if( status.isNotFatal())
{
ViUInt8 fileBuffer[100] = {};
ViUInt32 fileSizeInBytes = 100;
for( ViUInt8 index = 0; index < fileSizeInBytes; ++index )
{
fileBuffer[index] = index;
}
// Open the file for writing, this will also create this file on the NXT.
filePtr->openForWrite( fileSizeInBytes, status );
// Write the file contents.
filePtr->write( fileBuffer, fileSizeInBytes, status );
// Close the file.
filePtr->close( status );
// Destroy the file object. Note that this does not affect the file on the NXT.
nxtPtr->destroyFile( filePtr );
// Create a file iterator object which is used to find files on the NXT.
fileIteratorPtr = nxtPtr->createFileIterator( "*.*" /* find all files on the NXT */,
status );
}
// Creating the file iterator object could fail, better check status before dereferencing a
// potentially NULL pointer.
if( status.isNotFatal())
{
ViChar fileName[20];
// Iterate through all of the files on the NXT until we find our log file. Obviously,
// this isn't necessary in this simple example but is for illustrative purposes.
while( status.isNotFatal())
{
fileIteratorPtr->getName( fileName, status );
if( 0 == ::strcmp( fileName, "example.log" ))
{
break;
}
fileIteratorPtr->advance( status );
}
// Now that we have found our log file, create a file object that corresponds to it.
filePtr = fileIteratorPtr->getFile( status );
// Destroy the file iterator.
nxtPtr->destroyFileIterator( fileIteratorPtr );
}
// Creating the file object could fail, better check status before dereferencing a
// potentially NULL pointer.
if( status.isNotFatal())
{
ViUInt8 fileBuffer[100] = {};
ViUInt32 fileSizeInBytes = 100;
// Open the file for reading.
filePtr->openForRead( status );
// Read the file contents.
filePtr->read( fileBuffer, fileSizeInBytes, status );
// Close the file.
filePtr->close( status );
// Remove the file. This deletes the file from the NXT.
filePtr->remove( status );
// Destroy the file object.
nxtPtr->destroyFile( filePtr );
}
// Destroy the NXT object.
nFANTOM100::iNXT::destroyNXT( nxtPtr );
return 0;
}