Netduino no “Console.WriteLine”, Console does not exist in current context

两盒软妹~` 提交于 2019-12-12 09:35:51

问题


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


回答1:


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




回答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.)




回答3:


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




回答4:


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

Don't forget to use using System.Diagnostics;



来源:https://stackoverflow.com/questions/14250645/netduino-no-console-writeline-console-does-not-exist-in-current-context

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!