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

Make instance of module static


  • Please log in to reply
7 replies to this topic

#1 adam8797

adam8797

    Member

  • Members
  • PipPip
  • 22 posts

Posted 24 July 2013 - 01:05 AM

I was having issues with this code:

using System;using GoBus;using Microsoft.SPOT;using Microsoft.SPOT.Hardware;using NetduinoGo;using System.Threading;using SecretLabs.NETMF.Hardware.NetduinoGo;namespace MFConsoleApplication1{    public class Program    {        //notice the static ShieldBase        static ShieldBase shieldBase = new ShieldBase(GoSockets.Socket5);        public static void Main()        {            var ledPort = new OutputPort(shieldBase.Pins.GPIO_PIN_D4, false);            while (true)            {                ledPort.Write(!ledPort.Read());                System.Threading.Thread.Sleep(250);            }        }    }}

It throws this:

An unhandled exception of type 'System.Exception' occurred in GoBusSerialTransport.dll

but this code works fine:

using System;using GoBus;using Microsoft.SPOT;using Microsoft.SPOT.Hardware;using NetduinoGo;using System.Threading;using SecretLabs.NETMF.Hardware.NetduinoGo;namespace MFConsoleApplication1{    public class Program    {        public static void Main()        {            ShieldBase shieldBase = new ShieldBase(GoSockets.Socket5);            var ledPort = new Microsoft.SPOT.Hardware.OutputPort(shieldBase.Pins.GPIO_PIN_D4, false);            while (true)            {                ledPort.Write(!ledPort.Read());                System.Threading.Thread.Sleep(250);            }        }    }}

Why can't I have a static instance of a go!bus module? 

 

A similar exception happened when I tried to use the button (making it static vs not static) except the exception occurred in a different dll (whichever one contains the button)



#2 adam8797

adam8797

    Member

  • Members
  • PipPip
  • 22 posts

Posted 24 July 2013 - 01:19 AM

Now Im having another issue. here is my new code:

using System;using GoBus;using Microsoft.SPOT;using Microsoft.SPOT.Hardware;using NetduinoGo;using System.Threading;using SecretLabs.NETMF.Hardware.NetduinoGo;namespace MFConsoleApplication1{	public class Program	{		public static void Main()		{			var shieldBase = new ShieldBase(GoSockets.Socket5);			var pot = new Potentiometer(GoSockets.Socket1);			var blue = new OutputPort(shieldBase.Pins.GPIO_PIN_A3, false);			var green = new OutputPort(shieldBase.Pins.GPIO_PIN_A4, false);			var red = new OutputPort(shieldBase.Pins.GPIO_PIN_A5, false);			int c = 0;			while (true)			{				blue.Write(false);				green.Write(false);				red.Write(false);				if (c == 0) red.Write(true);				else if (c == 1) green.Write(true);				else if (c == 2)				{					blue.Write(true);					c = 0;				}				c++;				Thread.Sleep((int)(1000 * pot.GetValue()));			}		}	}}

Now I receive this error when I create the potentiometer:

A first chance exception of type 'System.ArgumentException' occurred in NetduinoGo.Potentiometer.dll

What is going on here!



#3 adam8797

adam8797

    Member

  • Members
  • PipPip
  • 22 posts

Posted 24 July 2013 - 01:39 AM

Well, I figured out why the potentiometer didn't work, there is somthing wrong the port 1 the board. Moved to port two and no issue.

 

Any ideas, or do you think its faulty?



#4 hanzibal

hanzibal

    Advanced Member

  • Members
  • PipPipPip
  • 1287 posts
  • LocationSweden

Posted 24 July 2013 - 08:41 AM

I've never used the Go! but it sounds as if the port is broken. This can happen if you draw to much current in trying to drive too big a load. It has happened to me a couple of times and so I simply avoid using the corresponding ports anymore. Does the port work when used as an input?

#5 eplaksienko

eplaksienko

    Advanced Member

  • Members
  • PipPipPip
  • 112 posts

Posted 24 July 2013 - 02:11 PM

Try GO ports 1 and 4, it works either 1-4 or 5-8 right now, Chris can correct me If I am wrong



#6 adam8797

adam8797

    Member

  • Members
  • PipPip
  • 22 posts

Posted 24 July 2013 - 04:40 PM

Well, about the bad ports, I just tried this code

...public static void Main(){    var b = new Button(GoSockets.Socket2);    var l = new RgbLed(GoSockets.Socket1);    l.SetColor(255, 0, 0);    l.SetBrightness(1);    b.ButtonPressed += (sender, pressed) => l.SetColor(0, 255, 0);    while (true)    {        Debug.Print("done");    }}

And the button works, so there goes the idea that port one is bad (although when the go! boots up, the led on 1 and 2 only flash, they don't stay solid like the rest)

 

 

but my previous code still won't work. Im at a loss here.



#7 NooM

NooM

    Advanced Member

  • Members
  • PipPipPip
  • 490 posts
  • LocationAustria

Posted 24 July 2013 - 05:28 PM

while (true){    Debug.Print("done");}

 

wow that looks mean :D

 

add s leep 1 at least :D



#8 adam8797

adam8797

    Member

  • Members
  • PipPip
  • 22 posts

Posted 24 July 2013 - 05:36 PM

wow that looks mean :D

 

add s leep 1 at least :D

 

Yeah, I just wanted to make sure it didn't freeze!  :lol:






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.