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
There is no Console on embedded devices. Hence, as you found, you must use Debug.Print.
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.)
It's available in 3.0, 4.0. and 4.1 from System.Ext namespace (MFDpwsExtensions.dll assembly)
MSDN:
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