• Join
  • Sign In with my.TI Login
Texas Instruments
  • Products
  • Applications
  • Tools & Software
  • Support & Community
  • Sample & Buy
  • About TI
Sample & Purchase Cart Sample & Purchase Cart
  • Search
  • Advanced
TI E2E™ Community
  • Support Forums
  • Blogs
  • Groups
  • Videos
  • 简体中文
  • More ...
TI Home » TI E2E Community » Support Forums » Microcontrollers » Stellaris® ARM® Microcontrollers » Stellaris® ARM® LM3S Microcontrollers Forum » C# lmusbdll.dll
Share
Stellaris® ARM® Microcontrollers
  • Forum
Options
  • Subscribe via RSS
Helpful Stellaris® LM4F Series Links
  • LM4F Series
  • Stellaris PinMux Utility
  • Stellaris® LM4F120 LaunchPad
  • LM4F MCU Applications
  • LM4F MCU Video
  • ARM Cortex-M4F Whitepaper
  • Stellaris MCU Brochure
  • LM4F232 Eval Kit
  • C# lmusbdll.dll

    C# lmusbdll.dll

    This question is not answered
    Jens M��ller
    Posted by Jens M��ller
    on Apr 03 2012 07:25 AM
    Prodigy20 points

    Hello,

    is there any  lmusbdll.dll which I can use in Microsoft Visual C# to get a USB-connection?

    Thanks

    Report Abuse
    • Reply
    You have posted to a forum that requires a moderator to approve posts before they are publicly available.
    All Replies
    • Craig Giglio94760
      Posted by Craig Giglio94760
      on Apr 03 2012 16:05 PM
      Intellectual860 points

      Hello Jens,

      The DLLs conform to the Microsoft coding standards.  We don't have anything specifically targeting C#, however, you should be able to import the dll using the standard C# methodology.  Here is an example where someone used a different DLL, but using C#.

      http://e2e.ti.com/support/microcontrollers/stellaris_arm_cortex-m3_microcontroller/f/473/t/103202.aspx

      More information about using dlls written using C/C++ and importing to C# can be found within the Microsoft forums.

      Regards,

      Craig

      Report Abuse
      • Reply
      You have posted to a forum that requires a moderator to approve posts before they are publicly available.
    • Adam Brailove
      Posted by Adam Brailove
      on Jan 06 2013 00:12 AM
      Prodigy90 points

      Please help:

      I am using the Stellaris LaunchPad (LM4F120) to prototype an embedded USB device.

      It would be SO great if someone who knows what they are doing could make a C# (CSHARP) version of the usb_bulk_example for the PC side of the code.

      C# is pretty much the language of choice for PC applications these days.

       

      I am using Visual Studio Express 2012 and C# for the PC side.

      There are bits and pieces of solutions on this forum:

      "Csharp Interfacing to LMDFU.DLL" - http://e2e.ti.com/support/microcontrollers/stellaris_arm_cortex-m3_microcontroller/f/473/t/103202.aspx

      "C#  lmusbdll.dll" http://e2e.ti.com/support/microcontrollers/stellaris_arm_cortex-m3_microcontroller/f/473/t/180076.aspx

       but nothing really seems to work.

       THANKS !

       -------------  MORE DETAIL ------------------

      I tried the code (listed below) from the second link above (using char, then byte buffers).

      I cant figure out how to resolve the following run-time debugger error

      ERROR:

      "A call to PInvoke function 'USBBulkExample!USBBulkExample.Program::InitializeDevice' has unbalanced the stack. This is likely because the managed PInvoke signature does not match the unmanaged target signature. Check that the calling convention and parameters of the PInvoke signature match the target unmanaged signature."

       A similar error is generated for call to all four lmusbdll functions:  InitializeDevice, ReadUSBPacket, WriteUSBPacket, and TerminateDevice.

      ---------------  C# CODE -----------------

      using System;

      using System.Collections.Generic;

      using System.Linq;

      using System.Text;

      using System.Threading.Tasks;

      using System.Runtime.InteropServices;

      using System.Globalization;

      using System.Security;

       

      namespace USBBulkExample

      {

          class Program

          {

              [DllImport("lmusbdll.dll", EntryPoint = "InitializeDevice", ExactSpelling = true, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]

              public static extern IntPtr InitializeDevice(ushort usVID, ushort usPID, ref System.Guid lpGUID, ref bool pbDriverInstalled);

              [DllImport("lmusbdll.dll", EntryPoint = "ReadUSBPacket", ExactSpelling = true, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]

              public static extern UInt32 ReadUSBPacket(IntPtr hHandle, [In] byte[] pcBuffer, UInt32 ulSize, ref UInt32 pulRead, UInt32 ulTimeoutMs, IntPtr hBreak);

              [DllImport("lmusbdll.dll", EntryPoint = "WriteUSBPacket", ExactSpelling = true, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]

              public static extern bool WriteUSBPacket(IntPtr hHandle, [Out] byte[] pcBuffer, UInt32 ulSize, ref UInt32 pulWritten);

              [DllImport("lmusbdll.dll", EntryPoint = "TerminateDevice", ExactSpelling = true, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]

              public static extern bool TerminateDevice(IntPtr hHandle);

       

              static void Main(string[] args)

              {

                  UInt32 dwError;

                  byte[] szBuffer = new byte[256];

                  const UInt32 INFINITE = 0xFFFFFFFF;

                  ushort BULK_VID = 0x1cbe;

                  ushort BULK_PID = 0x0003;

                  bool bDriverInstalled = false;

                  UInt32 ulRead = 0;

                  UInt32 pulWritten = 0;

                  IntPtr hBreak = IntPtr.Zero;

                  IntPtr hUSB = IntPtr.Zero;

       

                  // Create a GUID, match to what is in INF file           

                  System.Guid GUID_DEVINTERFACE_LUMINARY_BULK;

                  GUID_DEVINTERFACE_LUMINARY_BULK = new System.Guid("{6E45736A-2B1B-4078-B772-B3AF2B6FDE1C}");           

                 

                  // Init the USB device           

                  hUSB = InitializeDevice(BULK_VID, BULK_PID, ref GUID_DEVINTERFACE_LUMINARY_BULK, ref bDriverInstalled);                       

                 

                  // Load up array with useless "t"           

                  int x;           

                  for (x = 0; x<256; x++)          

                  {

                      szBuffer[x] = 3; // Convert.ToByte("t");           

                  }           

                 

                  // do this transaction 10k times for the fun of it...           

                  int y;           

                  for (y = 0; y<10000; y++)           

                  {               

                      bool ret = WriteUSBPacket(hUSB, szBuffer, 255, ref pulWritten);               

                      dwError = ReadUSBPacket(hUSB, szBuffer, 255, ref ulRead, INFINITE, hBreak);            

                  }          

                 

                  // Close the connection           

                  bool ret1 = TerminateDevice(hUSB);

              }

          }

      }

       

       

      Report Abuse
      • Reply
      You have posted to a forum that requires a moderator to approve posts before they are publicly available.
    • Anderson Castellar
      Posted by Anderson Castellar
      on Jan 22 2013 09:07 AM
      Prodigy20 points

      Hello Craig,

      I´m trying make an software to comunicate with my own board (Stellaris LM3S5632). The firmware looks ok, because I can see the device in Windows (Stellaris Bulk Devices -> Generic Bulk Device). I´m using Embarcadero Delphi XE3 to make the software. To use the dll in Delphi, I changed the function variables. The original function from lmusbdll.h is:

      LMUSB_HANDLE __stdcall InitializeDevice(unsigned short usVID,
                                              unsigned short usPID,
                                              LPGUID lpGUID,
                                              BOOL *pbDriverInstalled);

      I changed to this (without making any modification on .dll file):

      function InitializeDevice(usVID:DWORD; usPID:DWORD; lpGUID:TGUID; pbDriverInstalled:Boolean):THANDLE; stdcall; external  'lmusbdll.dll' index 1;

      The variables are:
        LMUSB_HANDLE: THANDLE;
        MyGuid: TGUID = '{6E45736A-2B1B-4078-B772-B3AF2B6FDE1C}';
        BULK_VID:DWORD= $1cbe;
        BULK_PID:DWORD= $0003

      To test, I put in a button the code:
      LMUSB_HANDLE:=InitializeDevice(BULK_VID,BULK_PID,MyGuid,true);

      When I click in the button, using the lmusbdll.dll, I get the error "Access violation at address 1001EAD5 in module 'lmusbdll.dll'. Write of address 40782B1B."

      When I use the lmusbdll64.dll, the application didn´t start.

      Could help me with this? Is a lmusbdll.dll variable convertion or value error?

      My System:
      WIndows 7 Professional SP1 64bits
      lmusbdll.dll version: 1.0.0.9107
      lmusbdll64.dll version: 1.0.0.9107

      Best Regards,

      Anderson

      Report Abuse
      • Reply
      You have posted to a forum that requires a moderator to approve posts before they are publicly available.
    • Anderson Castellar
      Posted by Anderson Castellar
      on Jan 22 2013 18:32 PM
      Prodigy20 points

      Solved

      https://forums.embarcadero.com/thread.jspa?messageID=527005#527005

      Report Abuse
      • Reply
      You have posted to a forum that requires a moderator to approve posts before they are publicly available.
    TI E2E™ Community
    • Support Forums
    • Blogs
    • Videos
    • Groups
    • Site Support & Feedback
    • Settings
    TI E2E™ Community Groups
    • TI University Program
    • Make the Switch
    • Microcontroller Projects
    • Motor Drive & Control
    Other Communities
    • Deyisupport
    • Designsomething.org
    • beagleboard.org
    • TI on Element 14
    • TI on TechXchangeSM
    Other Technical & Support Resources
    • WEBENCH® Design Center
    • Product Information Centers
    • Technical Documents
    • TI Design Network
    • TI Technical Articles
    • TI Training

    All content and materials on this site are provided "as is". TI and its respective suppliers and providers of content make no representations about the suitability of these materials for any purpose and disclaim all warranties and conditions with regard to these materials, including but not limited to all implied warranties and conditions of merchantability, fitness for a particular purpose, title and non-infringement of any third party intellectual property right. TI and its respective suppliers and providers of content make no representations about the suitability of these materials for any purpose and disclaim all warranties and conditions with respect to these materials. No license, either express or implied, by estoppel or otherwise, is granted by TI. Use of the information on this site may require a license from a third party, or a license from TI.

    Content on this site may contain or be subject to specific guidelines or limitations on use. All postings and use of the content on this site are subject to the Terms of Use of the site; third parties using this content agree to abide by any limitations or guidelines and to comply with the Terms of Use of this site. TI, its suppliers and providers of content reserve the right to make corrections, deletions, modifications, enhancements, improvements and other changes to the content and materials, its products, programs and services at any time or to move or discontinue any content, products, programs, or services without notice.

    Follow Us Texas Instruments on Facebook Texas Instruments on Twitter Texas Instruments on LinkedIn Texas Instruments on Google+
    TI Worldwide | Contact Us | my.TI Login | Site Map | Corporate Citizenship | mobile m.ti.com (Mobile Version)

    TI is a global semiconductor design and manufacturing company. Innovate with 100,000+ analog ICs and
    embedded processors, along with software, tools and the industry’s largest sales/support staff.

    © Copyright 1995-2013 Texas Instruments Incorporated. All rights reserved.
    Trademarks | Privacy Policy | Terms of Use