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

Casting Pins Exception


  • Please log in to reply
4 replies to this topic

#1 Bendage

Bendage

    Advanced Member

  • Members
  • PipPipPip
  • 153 posts
  • LocationIrvine, CA

Posted 12 April 2012 - 06:34 PM

When using the Microsoft.SPOT.Hardware.CPu.Pin for a general class does it cast appropriately using ((CPu.Pin)Pins.whatever) from the each of the Netduino.Pins classes? I am having some trouble determining a very general exception when doing so.

#2 gbreder

gbreder

    Advanced Member

  • Members
  • PipPipPip
  • 53 posts
  • LocationGermany

Posted 12 April 2012 - 07:51 PM

Hi, the "SecretLabs.NETMF.Hardware.Netduino.Pins" are in fact only constants with "Microsoft.SPOT.Hardware.Cpu.Pin" definitions inside. They exist only for one purpose: to give them a cool name like "Pins.GPIO_PIN_D7" instead of "Pin.GPIO_Pin3". Both names decribe the digital port 7. Only "...D7" is easier to remember than "3". There is no cast involved and each parameter in a method signature has to use "Microsoft.SPOT.Hardware.Cpu.Pin". If you use your VisualStudios IntelliSense feature on a Netduin pin definition (hover over it with your mouse) you see the Microsoft pin definition in the popup text. Regards Guido

#3 Bendage

Bendage

    Advanced Member

  • Members
  • PipPipPip
  • 153 posts
  • LocationIrvine, CA

Posted 12 April 2012 - 09:48 PM

Thanks for the reply. I think the error is coming from when I take an output port and set it to new using another pin. Do I have to dispose the current port or disable interrupt or what because its not letting me.

#4 Chris Walker

Chris Walker

    Secret Labs Staff

  • Moderators
  • 7767 posts
  • LocationNew York, NY

Posted 13 April 2012 - 12:11 AM

Hi Bendage,

Thanks for the reply. I think the error is coming from when I take an output port and set it to new using another pin. Do I have to dispose the current port or disable interrupt or what because its not letting me.

Yes, when you are done using an OutputPort/InputPort/etc., please dispose of it.

Chris

#5 BanksySan

BanksySan

    Member

  • Members
  • PipPip
  • 28 posts
  • LocationBristol, United Kingdom

Posted 18 April 2012 - 12:23 PM

All the ports inherit from the Port class, which implements IDisposable. This means that you can stick the port in a using block, e.g.:

using (OutputPort outputPort = new OutputPort(pin, false))
{
//Do Stuff
}

Dave

P.S. Are Ports 'cheap' things to create? How wary should one be one rapidly creating and destroying ports? If output and interrupt were needed?

Edited by BanksySan, 18 April 2012 - 12:36 PM.





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.