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.

Uberhund's Content

There have been 2 items by Uberhund (Search limited from 18-September 20)


By content type

See this member's

Sort by                Order  

#30178 Assgining the same IO pin to multiple instances?

Posted by Uberhund on 04 June 2012 - 03:10 PM in Netduino 2 (and Netduino 1)

Hi Uberhund and welcome to the forums.

The .NET Micro Framework makes it impossible to assign a pin twice, to prevent some issues. Also, the garbage collector doesn't free up the pins.
Therefor you can use the Dispose() method on the OutputPort class.

You could also make the ledOnBoard static, or a global member of your class. I have the feeling that's what you want to do.


Thanks for the welcome and excellent response, Stefan. Many thanks.



#30173 Assgining the same IO pin to multiple instances?

Posted by Uberhund on 04 June 2012 - 01:56 PM in Netduino 2 (and Netduino 1)

I wish to create a multiple instances of a class to control the Netduino onboard LED.

With only one instance of this class, my code executes perfectly. However, with more than one instance, execution stops with a "System Exception" error at the point where the Netduino hardware resource is allocated for the second time.

Consider the working example below of a single instance being created for the class, which I'll call "Morse"
Morse morse16 = new Morse(16);

The constructor for the class itself is defined as illustrated below:
public Morse(int iWPM)
        {
            iDotLength = 1200 / iWPM;
            iDashLength = 3 * iDotLength;
            ledOnBoard = new OutputPort(Pins.ONBOARD_LED, false); 
        }

Now, consider the example below of two instances being created for the class "Morse," which compiles fine, but which terminates with an execution error at the line where ledOnBoard is being defined for the second instance:
Morse morse16 = new Morse(16);
Morse morse24 = new Morse(24);
Execution stops here:
ledOnBoard = new OutputPort(Pins.ONBOARD_LED, false); //System exception occurs here with more than one instance

Is there a rule about assigning Netduino hardware resources to more than one instance that I have overlooked?




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.