Netduino no "Console.WriteLine", Console does not exist in current context
Asked Answered
B

4

11

I cannot seem to get my very simple netduino program to write to the debug console; VS throws an error

The name 'Console' does not exist in the current context

Any ideas what might cause it to not exist?

using System;
using System.Text;
using System.Net;
using System.Net.Sockets;
using System.Threading;
using Microsoft.SPOT;
using Microsoft.SPOT.Hardware;
using SecretLabs.NETMF.Hardware;
using SecretLabs.NETMF.Hardware.NetduinoPlus;

namespace LumenReader
{
public class Program
{
    public static void Main()
    {

        AnalogInput photoResistor = new AnalogInput(Pins.GPIO_PIN_A0);
        int photoVolt;
        while (true)
        {
            photoVolt = photoResistor.Read();
            Console.WriteLine(photoVolt);
        }

    }

}
}

Edit

Debug.Print does work

Baucis answered 10/1, 2013 at 4:4 Comment(1)
@minitech this guy seems to get it to compile ghadzhigeorgiev.wordpress.com/2011/09/20/…Baucis
M
12

There is no Console on embedded devices. Hence, as you found, you must use Debug.Print.

Marcie answered 10/1, 2013 at 8:17 Comment(0)
B
2

This is a common error -- a Console is the command line of your PC that you are using to develop your Microframework application, which runs on the device -- not the PC.

Debug.Print works because there is a debugger running that can and does communicate with the device. The output is generally directed to the Output window of your development PC. This is accomplished through the connection to the development board from the PC (Usually USB, or Serial Port.)

It is possible to write a separate Console application to accomplish this, but -- you would have to write the communications code, as well, which is not a good task for a beginner. (If you want to try, use the SerialPort object in .NET, but -- the one provided is just as good and already written.)

Blowzed answered 31/5, 2015 at 22:22 Comment(0)
K
1

It's available in 3.0, 4.0. and 4.1 from System.Ext namespace (MFDpwsExtensions.dll assembly)

MSDN:

http://msdn.microsoft.com/en-us/library/ee432029.aspx

Koal answered 10/1, 2013 at 8:41 Comment(2)
I don't believe this assembly is available to the micro frameworkBaucis
@Baucis Actually it is. MFDpwsExtensions is a part of MicroFramework SDK. It's even available in 4.2 and no, it's not specific to any manufacturer custom MF SDK.Koal
P
1

as @kfuglsang said, I would use just Debug.WriteLine()

Don't forget to use using System.Diagnostics;

Pridemore answered 26/1, 2017 at 9:16 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.