11

我似乎无法让我非常简单的 netduino 程序写入调试控制台;VS 抛出错误

当前上下文中不存在名称“控制台”

有什么想法可能导致它不存在吗?

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);
        }

    }

}
}

编辑

Debug.Print确实有效

4

4 回答 4

12

嵌入式设备上没有控制台。因此,正如您所发现的,您必须使用 Debug.Print。

于 2013-01-10T08:17:27.003 回答
2

这是一个常见错误——控制台是您用于开发微框架应用程序的 PC 命令行,它在设备上运行,而不是 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.)

于 2015-05-31T22:22:00.417 回答
1

它在 3.0、4.0 中可用。和 System.Ext 命名空间中的 4.1(MFDpwsExtensions.dll 程序集)

MSDN:

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

于 2013-01-10T08:41:23.513 回答
1

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

Don't forget to use using System.Diagnostics;

于 2017-01-26T09:16:53.907 回答