Jump to content
View in the app

A better way to browse. Learn more.

Tinkerunity

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Featured Replies

Geschrieben

I am creating a C++/MFC program to run the stepper motor.  I have included "ws2_32.lib" and "advapi32.lib" in the project properties (linker additional dependencies).

 

I am using the following defines:

 

#define HOST "localhost"

#define PORT 4223

#define UID "5W5jBJ" // Obtained from running brick viewer

I am using the following code, taken from the example code:

 

// Create IP connection

IPConnection ipcon;

ipcon_create(&ipcon);

 

// Create device object

Stepper stepper;

stepper_create(&stepper, UID, &ipcon);

 

// Connect to brickd

if (ipcon_connect(&ipcon, HOST, PORT) < 0)

{

  //returns -4

}

Everything compiles fine, but I can't connect.  I have loaded the brickd drivers for the stepper motor, and I can connect and run the stepper motor using brick viewer.

 

Any clues as to what I may be doing wrong?  Thanks.

 

Geschrieben

The modified version of ip_connection.c I gave you can resolve "localhost" to its IPv6 address, but brickd doesn't bind to an IPv6 address by default.

 

To make ip_connection.c resolve "localhost" to its IPv4 address you need to replace AF_UNSPEC with AF_INET in your ip_connection.c.

Geschrieben
  • Autor

Can I ask a follow up question?  Your suggestion worked and we are now able to run the stepper motor.  However, when execution of the following test block is finished, I have memory leaks.  Obviously, this block doesn't do anything except connect and release, but I wanted to isolate the memory leak problem:

 

---------------------

IPConnection ipcon;

ipcon_create(&ipcon);

 

Stepper stepper;

stepper_create(&stepper, UID, &ipcon);

 

stepper_disable(&stepper);

ipcon_destroy(&ipcon);

---------------------

 

My output windows shows:

 

Detected memory leaks!

Dumping objects ->

{586} normal block at 0x006E50C0, 4248 bytes long.

Data: <    5  6n    > 01 00 00 00 20 35 F6 C0 E0 36 6E 00 02 00 00 CD

Object dump complete.

 

Thank you for any advice.

Geschrieben

The code does more than connect and release. You're calling stepper_disable which disables the stepper motor driver. You should call stepper_destroy instead. The memory leak comes from not calling stepper_destroy.

 

It seems that these destroy calls are missing in all our C/C++ examples. I'm going to fix that now.

Geschrieben
  • Autor

Fantastic, thanks very much.  I thought the disable instruction was not enough, and I even looked for a destroy command but somehow missed it.  My fault.  All's well now and we are off and running.  At least until the next question!

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Gast
Reply to this topic...

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.