Eiffel and Mindstorms

Discussion specific to NXT-G, NXC, NBC, RobotC, Lejos, and more.
timpattinson
Posts: 224
Joined: 30 Oct 2010, 04:10
Location: 127.0.0.1
Contact:

Re: Eiffel and Mindstorms

Post by timpattinson »

Add a try/catch block in the C++ program and use some of the code on the library's page to find out what the library says the error is
it will tell you which class threw threw the exception and what it THINKS is wrong
Commit to Lego Mindstorms StackExchange Q&A http://area51.stackexchange.com/proposals/4105
Minboards IRC Channel #mindboards on Freenode
My blog: http://timpattinson.wordpress.com/
boxer41a
Posts: 9
Joined: 13 May 2011, 10:55

Re: Eiffel and Mindstorms

Post by boxer41a »

Okay, this is the error:

Invalid COM port or COM port in use
error code: 257
error type: 3
Function "connect" in class "Bluetooth"

Now that I have the correct com port (again), it worked once and only once. Now I get this error again, with no changes to code. So, why is the port busy? Is it a bluetooth, C++, or NXT problem?
boxer41a
Posts: 9
Joined: 13 May 2011, 10:55

Re: Eiffel and Mindstorms

Post by boxer41a »

I have found several references on the net where people had similar problems (the bluetooth to NXT worked some and then quit with a "port busy" error), but no cause/solution.

Has anyone here experienced this and been able to fix it?

jjj
linusa
Posts: 228
Joined: 16 Oct 2010, 11:44
Location: Aachen, Germany
Contact:

Re: Eiffel and Mindstorms

Post by linusa »

Depends on Bluetooth hardware and drivers (and Bluetooth stack used), as well as operating system.

Usually when this happens you haven't cleaned up everything, or left it in a broken state. Depending on how you access the serial connection to the NXT, you can close and reset the serial port. That usually did the trick for me. On the other hand, I didn't use Fantom for Bluetooth, but talked to the serial ports directly...
RWTH - Mindstorms NXT Toolbox for MATLAB
state of the art in nxt remote control programming
http://www.mindstorms.rwth-aachen.de
MotorControl now also in Python, .net, and Mathematica
timpattinson
Posts: 224
Joined: 30 Oct 2010, 04:10
Location: 127.0.0.1
Contact:

Re: Eiffel and Mindstorms

Post by timpattinson »

I had the exact same error I found that you fix it by changing one line in bluetooth.cpp
Change this:

Code: Select all

handle = CreateFile(port.c_str(), GENERIC_READ | GENERIC_WRITE, 0,0,OPEN_EXISTING,0,0);
to this:

Code: Select all

handle = CreateFile(port.c_str(), GENERIC_READ | GENERIC_WRITE,  0,NULL,OPEN_EXISTING,0,NULL); 
Sorry for not replying sooner
-tim
Commit to Lego Mindstorms StackExchange Q&A http://area51.stackexchange.com/proposals/4105
Minboards IRC Channel #mindboards on Freenode
My blog: http://timpattinson.wordpress.com/
boxer41a
Posts: 9
Joined: 13 May 2011, 10:55

Re: Eiffel and Mindstorms

Post by boxer41a »

Tim,
Thanks for the answer. The visual studio 10 project seems to test okay now; but calling the library routine from Eiffel gives the same error as before. The comport seems to be the same; I've built the library with the changed file (I think).

Maybe I will try a differenct C library.

Or, if someone could tell me how to determine the byte codes to send using the fantom api, I would just use fantom directly. For example, in the following code from the nxt++ library (link in previous post):
void NXT::Motor::SetForward(Comm::NXTComm* comm, int port, int power)
{
ViUInt8 directCommandBuffer[] = { 0x04, port, power, 0x01 | 0x04, 0x01, 0, 0x20, 0, 0, 0, 0 };
comm->SendDirectCommand( false, reinterpret_cast< ViByte* >( directCommandBuffer ), sizeof( directCommandBuffer ), NULL, 0);
}
How did the author determine the values to place in the "directCommandBuffer"?

thank,
jjj
gloomyandy
Posts: 323
Joined: 29 Sep 2010, 05:03

Re: Eiffel and Mindstorms

Post by gloomyandy »

The values are in the Lego Mindstorms documentation:
http://mindstorms.lego.com/en-us/suppor ... fault.aspx
download the Bluetooth developer kit...

Andy
johnd37
Posts: 1
Joined: 13 Jan 2012, 04:44

Re: Eiffel and Mindstorms

Post by johnd37 »

timpattinson wrote:
boxer41a wrote: 2. The link to the bluetoothlibrary looks promising but I get numorous errors.
c:\program files\microsoft sdks\windows\v6.0a\include\ws2def.h(91) : warning C4005: 'AF_IPX' : macro redefinition
c:\program files\microsoft sdks\windows\v6.0a\include\winsock.h(460) : see previous definition of 'AF_IPX'
c:\program files\microsoft sdks\windows\v6.0a\include\ws2def.h(127) : warning C4005: 'AF_MAX' : macro redefinition
c:\program files\microsoft sdks\windows\v6.0a\include\winsock.h(479) : see previous definition of 'AF_MAX'
c:\program files\microsoft sdks\windows\v6.0a\include\ws2def.h(163) : warning C4005: 'SO_DONTLINGER' : macro redefinition
c:\program files\microsoft sdks\windows\v6.0a\include\winsock.h(402) : see previous definition of 'SO_DONTLINGER'
c:\program files\microsoft sdks\windows\v6.0a\include\ws2def.h(206) : error C2011: 'sockaddr' : 'struct' type redefinition
c:\program files\microsoft sdks\windows\v6.0a\include\winsock.h(485) : see declaration of 'sockaddr'
c:\program files\microsoft sdks\windows\v6.0a\include\ws2def.h(384) : error C2143: syntax error : missing '}' before 'constant'
Remove the references to network.h and network.cpp
I am using this library at the moment with VC++ - 2010 and it works fine 4 me
:D
PS.
mightor wrote: I found this C++ wrapper: http://www.norgesgade14.dk/bluetoothlibrary.php ,
I don't think it's a wrapper around the Fantom API as such.
When debugging, I found it uses the Windows API to open a comport and send bytes, no mention of any Fantom stuff
You must also edit the header nxt.h and comment out the line where it includes network.h
I was having this same trouble when I found your post. I just tried it with Visual C++ Express 10.0 and it works fine.

Sample 10 linked from Anders' Mindstorms site - http://www.norgesgade14.dk/bluetoothlibrary.php - is a good one to try (no sensors needed, etc - mine are all the way down in the basement; too far)

Before running the program, you will need to establish a BT partnership between PC and NXT - see http://staff.science.uva.nl/~toto/Work/ ... Steps.html

Finally, you will need to guess the PC's com port that is being used by the NXT.
In your main.cpp, try numbers 1, 2, 3, up to ? I don't know how many there are, but mine connected 5:

int main()
{
try{
cout << "Try to connect to the NXT" << endl;
//connection->connect(40);
connection->connect(5);
.
.
.

Finally, you should check out Anders' remote control and source code for it at bottom of this page: http://www.norgesgade14.dk/bluetoothremote.php

JD
Post Reply

Who is online

Users browsing this forum: No registered users and 7 guests