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.

OneManDo

Member Since 05 Mar 2012
Offline Last Active Jan 09 2013 09:05 AM
-----

Topics I've Started

dual real RS-232 port with netduino ( not TTL )

01 January 2013 - 10:59 AM

Hello,

 

I have a need to create a mini 'buffer for serial messages'  using the netduino, SD and COM1 & COM2

I need a dual RS-232 serial port shield.

 

 

it's look somthing like this:

 

COM1 -> SD micro -> COM2

 

 

Any one ever use 2 RS-232 port with netduino?

 

NAD


Can't find System.Net.Sockets.dll on v4.1

25 November 2012 - 08:07 PM

Hello, I want to use a TCP socket to connect to other PC but the 'using System.Net' and the 'using System.Net.Sockets' have a compile error... I have try to add the System.Net.dll or the System.Net.Sockets.dll but didn;t find them on my PC.... any one have this problem before? NAD

Reading & Wriring INI file from SD Micro

05 March 2012 - 04:05 PM

Here is a class for reading & writing INI file from/to Micro SD
It is very simple one... but does the work just fine ;-)
Any feedback will be nice to have.

Here is the source code:


using System;
using System.IO;
using System.Collections;
using System.Threading;

namespace NetduinoPlusMonitor
{
  public class CIni
  {
    public CIni()
    {
      _Sections = new Hashtable();
    }

    /// <summary>
    /// Loads the Reads the data in the ini file into the IniFile object
    /// </summary>
    /// <param name="filename"></param>
    public void Load(string FileName, bool append)
    {
      if (!append)
        DeleteSections();

      string Section = "";
      string[] keyvaluepair;

      using (FileStream inFileStream = new FileStream(Path.Combine("\\SD",FileName), FileMode.Open))
      {
        using (StreamReader inStreamReader = new StreamReader(inFileStream))
        {
          string[] lines = inStreamReader.ReadToEnd().ToLower().Split(new char[] { '\n', '\r' });

          foreach(string line in lines)
          {
            if (line == string.Empty)
              continue;
            if (';' == line[0])
              continue;

            if ('[' == line[0] && ']' == line[line.Length - 1])
              Section = line.Substring(1, line.Length - 2);

            else if (-1 != line.IndexOf("="))
            {
              keyvaluepair = line.Split(new char[] { '=' });
              SetValue(Section, keyvaluepair[0], keyvaluepair[1]);
            }
          }
          inStreamReader.Close();
          inFileStream.Close();
        }
      }

    }

    /// <summary>
    /// Used to save the data back to the file or your choice
    /// </summary>
    /// <param name="FileName"></param>
    public void Save(string FileName)
    {
      using (FileStream outFileStream = new FileStream(Path.Combine("\\SD",FileName), FileMode.Create))
      {
        using (StreamWriter outStreamWriter = new StreamWriter(outFileStream))
        {
          foreach (object Sections in _Sections.Keys)
          {
            outStreamWriter.WriteLine("[" + Sections.ToString() + "]");
            Hashtable keyvalpair = (Hashtable)_Sections[Sections];

            foreach (object key in keyvalpair.Keys)
              outStreamWriter.WriteLine(key.ToString() + "=" + keyvalpair[key].ToString());
          }

          outStreamWriter.Close();
          outFileStream.Close();
        }
      }

    }

    public string GetValue(string Section, string key, string defkey = "")
    {
      key = key.ToLower();
      Section = Section.ToLower();

      Hashtable keyvalpair = (Hashtable)_Sections[Section];

      if ((null != keyvalpair) && (keyvalpair.Contains(key)))
        defkey = keyvalpair[key].ToString();

      return defkey;
    }
    public float GetValue(string Section, string key, float defkey)
    {
      try { defkey = (float)double.Parse(GetValue(Section, key, defkey.ToString())); }
      catch (Exception) { }
      return defkey;
    }
    public double GetValue(string Section, string key, double defkey)
    {
      try { defkey = double.Parse(GetValue(Section, key, defkey.ToString())); }
      catch (Exception) { }
      return defkey;
    }
    public UInt64 GetValue(string Section, string key, UInt64 defkey)
    {
      try { defkey = UInt64.Parse(GetValue(Section, key, defkey.ToString())); }
      catch (Exception) { }
      return defkey;
    }
    public UInt32 GetValue(string Section, string key, UInt32 defkey)
    {
      try { defkey = UInt32.Parse(GetValue(Section, key, defkey.ToString())); }
      catch (Exception) { }
      return defkey;
    }
    public UInt16 GetValue(string Section, string key, UInt16 defkey)
    {
      try { defkey = UInt16.Parse(GetValue(Section, key, defkey.ToString())); }
      catch (Exception) { }
      return defkey;
    }
    public byte GetValue(string Section, string key, byte defkey)
    {
      try { defkey = byte.Parse(GetValue(Section, key, defkey.ToString())); }
      catch (Exception) { }
      return defkey;
    }
    public Int64 GetValue(string Section, string key, Int64 defkey)
    {
      try { defkey = Int64.Parse(GetValue(Section, key, defkey.ToString())); }
      catch (Exception) { }
      return defkey;
    }
    public Int32 GetValue(string Section, string key, Int32 defkey)
    {
      try { defkey = Int32.Parse(GetValue(Section, key, defkey.ToString())); }
      catch (Exception) { }
      return defkey;
    }
    public Int16 GetValue(string Section, string key, Int16 defkey)
    {
      try { defkey = Int16.Parse(GetValue(Section, key, defkey.ToString())); }
      catch (Exception) { }
      return defkey;
    }

    public void SetValue(string Section, string key, string value)
    {
      key = key.ToLower();
      Section = Section.ToLower();

      if (!_Sections.Contains(Section))
        _Sections.Add(Section, new Hashtable());

      Hashtable keyvalpair = (Hashtable)_Sections[Section];

      if (keyvalpair.Contains(key))
        keyvalpair[key] = value;
      else
        keyvalpair.Add(key, value);
    }
    public void SetValue(string Section, string key, float value)
    {
      SetValue(Section, key, value.ToString());
    }
    public void SetValue(string Section, string key, double value)
    {
      SetValue(Section, key, value.ToString());
    }
    public void SetValue(string Section, string key, byte value)
    {
      SetValue(Section, key, value.ToString());
    }
    public void SetValue(string Section, string key, Int16 value)
    {
      SetValue(Section, key, value.ToString());
    }
    public void SetValue(string Section, string key, Int32 value)
    {
      SetValue(Section, key, value.ToString());
    }
    public void SetValue(string Section, string key, Int64 value)
    {
      SetValue(Section, key, value.ToString());
    }
    public void SetValue(string Section, string key, char value)
    {
      SetValue(Section, key, value.ToString());
    }
    public void SetValue(string Section, string key, UInt16 value)
    {
      SetValue(Section, key, value.ToString());
    }
    public void SetValue(string Section, string key, UInt32 value)
    {
      SetValue(Section, key, value.ToString());
    }
    public void SetValue(string Section, string key, UInt64 value)
    {
      SetValue(Section, key, value.ToString());
    }

    public void DeleteSection(string Section)
    {
      Section = Section.ToLower();

      if (_Sections.Contains(Section))
        _Sections.Remove(Section);
    }
    public void DeleteSections()
    {
      _Sections.Clear();
    }

    private Hashtable _Sections = null;

  }
}

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.