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

C# console to NetDuino help?


  • Please log in to reply
3 replies to this topic

#1 frito

frito

    New Member

  • Members
  • Pip
  • 1 posts

Posted 25 January 2012 - 08:13 AM

I'm new to coding for the Netduino and C# for that matter. However one thing I'm trying to get working is being able to get all the packets a server is sending back to my client when I connect. I've managed to get it working on a console C# app, but I am unable to get it working using the micro framework on a netduino plus application.

The code is posted over at http://pastebin.com/MKcP1KYV

The 2 errors I'm getting are:
'System.Text.Encoding' does not contain a definition for 'ASCII' for line
string stringData = Encoding.ASCII.GetString(data, 0, receivedDataLength);
and
'string' does not contain a definition for 'Format' for line
hex += String.Format("{0:x2}", (uint)System.Convert.ToUInt32(tmp.ToString()));

Does anyone know what else I could do? Also I know the "Console.Write...." won't work, I plan to replace it with Debug.Print if I can get past the 2 errors mentioned above.

#2 Teets

Teets

    Member

  • Members
  • PipPip
  • 16 posts

Posted 21 February 2012 - 03:34 PM

When an error states "... does not contain a definition for ..." that means it's not declared anywhere. In this case, it means the .NET MF doesn't contain the "System.Text.Encoding.ASCII" static class or the "string.format()" static function.

What environment are you developing in? Your intellisense should have told you this...

I'm new to coding for the Netduino and C# for that matter. However one thing I'm trying to get working is being able to get all the packets a server is sending back to my client when I connect. I've managed to get it working on a console C# app, but I am unable to get it working using the micro framework on a netduino plus application.

The code is posted over at http://pastebin.com/MKcP1KYV

The 2 errors I'm getting are:

'System.Text.Encoding' does not contain a definition for 'ASCII' for line
string stringData = Encoding.ASCII.GetString(data, 0, receivedDataLength);
and
'string' does not contain a definition for 'Format' for line
hex += String.Format("{0:x2}", (uint)System.Convert.ToUInt32(tmp.ToString()));

Does anyone know what else I could do? Also I know the "Console.Write...." won't work, I plan to replace it with Debug.Print if I can get past the 2 errors mentioned above.



#3 Stefan

Stefan

    Moderator

  • Members
  • PipPipPip
  • 1965 posts
  • LocationBreda, the Netherlands

Posted 21 February 2012 - 03:44 PM

.NETMF only has UTF-8 support for some strange reason (as if GPS/RFID units etc. use UTF-8...). The UTF-8 implementation isn't lightweight so I try not to use it.

For myself, I just use two methods I wrote which convert byte arrays to char arrays and back.
  • Bytes2Chars(Input) Converts a byte array to a character array
  • Chars2Bytes(Input) Converts a character array to a byte array
http://netmftoolbox....box.NETMF.Tools

Otherwise, you can just use UTF-8 conversion methods in .NETMF
"Fact that I'm a moderator doesn't make me an expert in things." Stefan, the eternal newb!
My .NETMF projects: .NETMF Toolbox / Gadgeteer Light / Some PCB designs

#4 Bendage

Bendage

    Advanced Member

  • Members
  • PipPipPip
  • 153 posts
  • LocationIrvine, CA

Posted 30 September 2012 - 07:24 AM

The first error appears to be coming from your serialPort_DataReceived event. Use this instead... string stringData = objSerialPort.ReadExisting();




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.