Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8743663
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T11:43:05+00:00 2026-06-13T11:43:05+00:00

I have a C# .Net Winforms application, which uses LibUsbDotNet to program firmware into

  • 0

I have a C# .Net Winforms application, which uses LibUsbDotNet to program firmware into an USB-device (Atmel AVR32) using “DFU_DNLOAD” transfers, which is a special kind of control-transfers. This all works, BUT: A specific kind of transfer, which causes the device to erase its internal flash, fails to send an ACK within the correct timing.

When this happens, my LibUsbDotNet connection becomes irreparably broken, which causes everything to fail.

My code does the following:

int TransferToDevice(byte request, short value, byte[] data)
{
  var setup = new UsbSetupPacket(
                (byte)(UsbCtrlFlags.Direction_Out | UsbCtrlFlags.RequestType_Class | UsbCtrlFlags.Recipient_Interface),
                request,
                value,
                0,
                (short)data.Length);

  int n;
  IntPtr unmanagedPointer = System.Runtime.InteropServices.Marshal.AllocHGlobal(data.Length);
  System.Runtime.InteropServices.Marshal.Copy(data, 0, unmanagedPointer, data.Length);
  // UsbDevice obtained else-where
  if (!UsbDevice.ControlTransfer(ref setup, unmanagedPointer, data.Length, out n))
  {
    n = 0;
  }
  System.Runtime.InteropServices.Marshal.FreeHGlobal(unmanagedPointer);
  return n;
}

// In order to do a "DFU_DNLOAD", the method above is used as follows:
TransferToDevice(DFU_DNLOAD, Transactions++, data); // "data" is the payload
// where DFU_DNLOAD is:
private const byte DFU_DNLOAD    = 1;
// Transactions is 
short Transaction = 0;

The above code works (the device correctly receives the “DFU_DNLOAD” message), but the missing ACK is the problem. Once the error occurs, every attempt to communicate with the device (even if I try to re-initialize everything) fails, untill the device is disconnected and re-inserted…

I would like to be able to reset or re-initialize the USB-connection somehow, when this error occurs. Currently I am only able to re-establish communications with the device by exiting my application and re-starting it manually.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T11:43:05+00:00Added an answer on June 13, 2026 at 11:43 am

    Just guessing, but in case if data is array of short, than size of the buffer should be adjusted

    int numberOfValues = data.Length;
    int size = Marshal.SizeOf(typeof(short)); 
    
    IntPtr unmanagedPointer = Marshal.AllocHGlobal(numberOfValues*size);
    
    if (unmanagedPointer == IntPtr.Zero)
        throw new OutOfMemoryException("Unable allocate memory");
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a C#/.NET Winforms application which has some settings stored using A '.settings'
I am new to Microsoft Dynamic CRM. I have a .NET Winforms application which
I have a .NET C# winforms application which works great on my machine, but
I have an ASP.NET 4.0 web application which uses a third-party API for external
We have already shipped a client (.NET WinForms) application which sends customer data to
I have a C# .net winforms application with two forms which connects to sql
I have created a .NET C# WinForms application on Win 7 RTM x64, which
I got a .net WinForms application. I have a UserControl which gets instantiated based
my c#.net winforms application which uses sql server 2005 express , would be run
I want to create logins & users for my c#.net winforms application which uses

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.