Netduino home hardware projects downloads community

Jump to content


The Netduino forums have been replaced by new forums at community.wildernesslabs.co. This site has been preserved for archival purposes only and the ability to make new accounts or posts has been turned off.
Photo

Netduino Plus locks when using pointers


  • Please log in to reply
2 replies to this topic

#1 Baqs

Baqs

    New Member

  • Members
  • Pip
  • 5 posts

Posted 09 November 2012 - 10:12 AM

When attempting to use pointers in a Netduino Plus I have locked the device in every attempt. For example, if I try to run the following code:

public static void Main()
{
   float testNumber = 5.25f;

   byte[] numberBytes = GetBytes(testNumber);
   for (int count = 0; count < numberBytes.Length; count++)
   {
      Debug.Print("Byte[" + count + "]=" + numberBytes[count]);
   }
}

public static unsafe byte[] GetBytes(float value)
{
   byte* pointerToFirstByte = (byte*)&value;
   byte[] resultBytes = new byte[4] { *pointerToFirstByte, *(pointerToFirstByte + 1), *(pointerToFirstByte + 2), *(pointerToFirstByte + 3) };
   return resultBytes;
}


the Netduino ends up locked and I have to erase it with MFDeploy. Is there any way to use pointers in the Netduino Plus?

#2 Chris Walker

Chris Walker

    Secret Labs Staff

  • Moderators
  • 7767 posts
  • LocationNew York, NY

Posted 09 November 2012 - 10:25 AM

Hi Baqs, Unsafe code is not officially supported by .NET Micro Framework. We have used it ourselves on occasion, with the understanding that it was a curious side-effect more than an on-purpose feature. Grab a copy of the BitConverter in the GoBus source. It has a GetBytes function for floating point values. Please try it on your Netduino Plus and let me know if it works or not. Chris

#3 Baqs

Baqs

    New Member

  • Members
  • Pip
  • 5 posts

Posted 09 November 2012 - 10:50 AM

Thanks Chris, worked perfectly!




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users

home    hardware    projects    downloads    community    where to buy    contact Copyright © 2016 Wilderness Labs Inc.  |  Legal   |   CC BY-SA
This webpage is licensed under a Creative Commons Attribution-ShareAlike License.