Netduino home hardware projects downloads community

Jump to content

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


Member Since 18 Nov 2010
Offline Last Active Dec 03 2012 02:32 PM

Topics I've Started

Convert double to integer?

10 January 2012 - 03:56 PM

I've got an RGB LED plugged into 3 of the PWM outputs. I want to cross-fade between colours.

I thought this would be trivial but apparently not. I've simplified this to just be a single output for now.

    Dim Start As UInteger = 0
    Dim [End] As UInteger = 255
    Dim Steps = 100

    For x = 1 To Steps
        Dim Temp = ([End] - Start) / Steps * x + Start
        Dim R = CUInt(Temp)

        Debug.Print(x.ToString & ": Temp: " & Temp.ToString & ", R:" & R.ToString)
        LedR.SetPulse(255, R)

This outputs:
1: Temp: 2.5500, R:196608
2: Temp: 5.1000, R:327680
3: Temp: 7.6500, R:524288
4: Temp: 10.2000, R:655360
5: Temp: 12.7499, R:851968
95: Temp: 242.2488, R:15859712
96: Temp: 244.7988, R:16056320
97: Temp: 247.3488, R:16187392
98: Temp: 249.8988, R:16384000
99: Temp: 252.4488, R:16515072
100: Temp: 254.9988, R:16711680

As you can see the actual calculation works perfectly but I can't find ANY way to shoe-horn the resulting double into a UInt.

NB: In this scenario, I don't care at all about precision so Ceil/Floor/Truncate are all perfectly acceptable.

I've tried:
        Dim R = CUInt(Temp) 'Odd output - maybe reading memory and just treating it as a UInt
        Dim R = CType(Temp, UInteger) 'Throws: An unhandled exception of type 'System.Exception' occurred in Netduino_VBTest.exe
        Dim R = Convert.ToUInteger(Temp) 'Doesn't have an overload for Double (or anything except string!)
        Dim R = Convert.ToUInteger(Temp.ToString) 'Throws an exception

Any suggestions appreciated.

VS2010 Crash on debug

07 January 2012 - 05:01 PM

I've recently rebuilt my system and dusted off my netduino to have another go. (Standard netduino, not plus, mini, etc.)

As I prefer VB, I've installed:

Microsoft .Net Micro Framework SDK 4.2 (RTM)
Netduino SDK v4.2.0 (June 2011 Beta)

The OS is Windows 7 x64, Dev Env: Visual Studio 2010 Ultimate

I've created a new Micro Framework netduino application which contains the following 2 files:

Imports Microsoft.SPOT
Imports Microsoft.SPOT.Hardware
Imports SecretLabs.NETMF.Hardware
Imports SecretLabs.NETMF.Hardware.Netduino

Module Main
    Sub Main()
        Led0.Write(True) ''<<< Breakpoint Here
        Dim Value = 0.0
    End Sub
End Module

Imports Microsoft.SPOT
Imports Microsoft.SPOT.Hardware
Imports SecretLabs.NETMF.Hardware
Imports SecretLabs.NETMF.Hardware.Netduino

Module HardwareMapping

    Public Led0 As OutputPort = New OutputPort(Pins.GPIO_PIN_D11, False)
    Public Led1 As OutputPort = New OutputPort(Pins.GPIO_PIN_D4, False)
    Public Led2 As OutputPort = New OutputPort(Pins.GPIO_PIN_D13, False)
    Public Led3 As OutputPort = New OutputPort(Pins.GPIO_PIN_D3, False)

    Public LedR As OutputPort = New OutputPort(Pins.GPIO_PIN_D5, False)
    Public LedG As OutputPort = New OutputPort(Pins.GPIO_PIN_D6, False)
    Public LedB As OutputPort = New OutputPort(Pins.GPIO_PIN_D10, False)

End Module

I can run the app and it will turn on/off the LEDs as desired (I'm using this shield: http://ruggedcircuit...AS010/as010.pdf which provides a number of LEDs and Pots as well as some other things to test).

If I add a breakpoint or pause execution at any point, Visual Studio throws a fatal exception:

The problem signature in the "VS has crashed" Dialog is as follows:
Problem signature:
  Problem Event Name:	APPCRASH
  Application Name:	devenv.exe
  Application Version:	10.0.40219.1
  Application Timestamp:	4d5f2a73
  Fault Module Name:	vbdebug.dll
  Fault Module Version:	10.0.40219.1
  Fault Module Timestamp:	4d5f2fc9
  Exception Code:	c0000005
  Exception Offset:	000a0ceb
  OS Version:	6.1.7601.
  Locale ID:	2057

Additional information about the problem:
  LCID:	1033

Read our privacy statement online:

If the online privacy statement is not available, please read our privacy statement offline:

If I debug VS itself, I get (in the "choose debugger dialog"):
An unhandled win32 exception occured in devenv.exe [121988].

After opening a new instance of VS as a debugger, I'm told:
Unhandled exception at 0x77d515ee in devenv.exe: 0xC0000005: Access violation reading location 0x00000000

Disassembly is as follows:

77D515AD  mov         ecx,0Ah  
77D515B2  lea         edx,[esp+4]  
77D515B6  call        dword ptr fs:[0C0h]  
77D515BD  add         esp,4  
77D515C0  ret         0Ch  
77D515C3  nop  
77D515C4  mov         eax,12Eh  
77D515C9  xor         ecx,ecx  
77D515CB  lea         edx,[esp+4]  
77D515CF  call        dword ptr fs:[0C0h]  
77D515D6  add         esp,4  
77D515D9  ret         18h  
77D515DC  mov         eax,12Fh  
77D515E1  xor         ecx,ecx  
77D515E3  lea         edx,[esp+4]  
77D515E7  call        dword ptr fs:[0C0h]  
77D515EE  add         esp,4  <<<<<<<< EXCEPTION HERE <<<<<<<<
77D515F1  ret         0Ch  
77D515F4  mov         eax,130h  
77D515F9  xor         ecx,ecx  
77D515FB  lea         edx,[esp+4]  
77D515FF  call        dword ptr fs:[0C0h]  
77D51606  add         esp,4  
77D51609  ret         18h  
77D5160C  mov         eax,131h  
77D51611  xor         ecx,ecx  
77D51613  lea         edx,[esp+4]  
77D51617  call        dword ptr fs:[0C0h]  
77D5161E  add         esp,4  
77D51621  ret         8  
77D51624  mov         eax,132h  
77D51629  xor         ecx,ecx  
77D5162B  lea         edx,[esp+4]  
77D5162F  call        dword ptr fs:[0C0h]  

As it's been a while since I used the netduino and haven't ever used it on this PC, I'm not sure how to go about tracking down the problem especially using Beta drivers. Can someone please suggest a workaround / further places for investigation?

Many thanks

Edit: I've attached the project in question. I've also tried running the simple "Blinky" example which DOES allow debugging so it must be an issue with my very short code

Another Edit: It seems that the problem is caused if the variable for the LED is defined in a different file. To test, take the Blinky example, move the led definition to a different module with a Public scope and run it again. The app will still run but debugging fails.

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.