In wonder, will it stick after a reset/powercycle?
Yes it will.
  | ||||||||||||||
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.
Community Stats
1
Neutral
User ToolsFriendsTal Tikotzki hasn't added any friends yet. Posts I've MadeIn Topic: Change the NP2 IP from code13 February 2013 - 05:54 PM
Yes it will. In Topic: Netduino Plus 2 Firmware v4.2.2 (update 1)03 February 2013 - 01:41 AM
I had a the same problems, therefore I decided to implement it differently while checking for end of stream after each read.
ArrayList PortList = new ArrayList(); using (var reader = new StreamReader(PortFileName)) { if (reader.BaseStream.Length > 0) { do { HoldPort = new MCUPort(reader.ReadLine()); HoldPort.State = 1; HoldPort.LastState = DateTime.Now; PortList.Add(HoldPort); } while (!reader.EndOfStream); } reader.Close(); }
I hope that helps.
T In Topic: Configuration Management26 January 2013 - 09:30 PM NooM, The configuration manager should be a simple class that allows you to store at least key-value pairs in a consistent way across the application.
I wrote something myself which I believe would be useful:
using System;using System.Collections;using System.IO;namespace Utils{ public class ConfigManager : IDisposable { private bool _disposed; private StringDictionary _dataset; private string _configFilename; private readonly char _splitter = '='; public ConfigManager(string configFilename) { _dataset = new StringDictionary(); _configFilename = configFilename; Reload(); } public void Save() { using (var file = new StreamWriter(_configFilename, false)) { foreach (DictionaryEntry dataElement in _dataset) { var line = (string)dataElement.Key + _splitter + (string)dataElement.Value; file.WriteLine(line); } file.Close(); } } public void Reload() { if (!File.Exists(_configFilename)) return; _dataset.Clear(); using (var file = new StreamReader(_configFilename)) { if (file.BaseStream.Length > 0) { do { var str = file.ReadLine(); var idx = str.IndexOf(_splitter); if (idx >= 0) { var key = prepareKey(str.Substring(0, idx)); var value = str.Substring(idx + 1, str.Length - (idx + 1)); _dataset.Add(key, value); } } while (!file.EndOfStream); } file.Close(); } } public void SetValue (string key, string value) { key = prepareKey(key); if (_dataset.ContainsKey(key)) { _dataset[key] = value.Trim(); } else { _dataset.Add(key, value.Trim()); } } public string GetValue (string key) { return _dataset[prepareKey(key)]; } private string prepareKey (string key) { return key.Trim().ToLower(); } #region Implementation of IDisposable /// <summary> /// Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources. /// </summary> /// <filterpriority>2</filterpriority> public void Dispose() { Dispose(true); GC.SuppressFinalize(this); } protected virtual void Dispose (bool disposing) { if (!_disposed) { if (disposing) { _dataset.Clear(); } } _disposed = true; } ~ConfigManager() { Dispose(false); } #endregion }}
An example of how to use it: using (var cm = new ConfigManager(@"SDconfconfig.txt")) { cm.SetValue("key", "value"); // some setting example cm.SetValue("Address", "http://127.0.0.1"); // some setting example cm.Save(); } using (var cm = new ConfigManager(@"SDconfconfig.txt")) { Debug.Print("Address: " + cm.GetValue("Address")); } In Topic: Netduino Plus 2 Native OneWire Temp Sensor20 January 2013 - 02:29 PM Oh my, I didn't even notice that. In ReadTemps_Delegate, you're creating a timer. Which will then get garbage collected at some point, since its scope is limited to the function. Try creating a static variable for the timer outside of that function, and then instantiate it in that function instead. Chris Hey Chris, Why would should I instantiate a timer inside the thread delegate and not at the main thread? Doesn't the timer callback returns in a worker thread every time?
Tal In Topic: Can I tell whether the Ethernet cable is connected?19 January 2013 - 01:34 PM Thanks Chris,
The networkAvailabilityChange event is fired only if there is a change after the network established. So when starting (power up, reset etc.) I did not receive any notification, neither when the network was connected nor was it disconnected when Netduino powered-up..
For that reason I looked for a method to safely poll on the network status when the Netduino started.
I tried to open a listening socket on a port that I wasn't planning to use: using (var listenSocket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp)) { try { var bindingAddress = new IPEndPoint(IPAddress.Any, 9001); listenSocket.Bind(bindingAddress); listenSocket.Listen(1); netOkay = listenSocket.Poll(500, SelectMode.SelectError); } catch (Exception) { netOkay = false; } listenSocket.Close(); }
This is not the nicest code, but since it is being called only once, after power-up, it seems good enough.
Tal
| ||||||||||||||
|
||||||||||||||
This webpage is licensed under a Creative Commons Attribution-ShareAlike License. | ||||||||||||||