public void Initialize() { var configfile = ConfigurationManager.AppSettings["ConfigurationFilePath"]; if (File.Exists(configfile)) { BasicConfiguration.Load(configfile); } else { new BasicConfiguration { Path = configfile }.FillExample(); BasicConfiguration.Save(); throw new Exception("EmptyConfigurationException, Please fill the configuration with the right information and start again."); } NCDComponent = new NCDComponent { BaudRate = 38400, PortName = BasicConfiguration.Configuration.Comport }; NCDComponent.OpenPort(); if (!NCDComponent.IsOpen) { throw new Exception("Can't open port"); } //-------Output states var outputState = NCDComponent.ProXR.RelayBanks.GetRelaysStatusInAllBanks(); for (byte bank = 0; bank < BasicConfiguration.Configuration.AvailableRelayBanks.Count; bank++) { ReportOutputStates(bank, ParseValue(outputState[bank])); } Run = new Thread(Runner); Run.Start(this); Input = new Thread(InputRunner); Input.Start(this); }
/// <summary> /// test if it is a i2cBridgeX device by reading eeprom data /// </summary> /// <param name="comport"></param> /// <returns></returns> public static bool IsI2CBridgeX(string comport) { bool bRtn = false; NCDComponent ncdObj = new NCDComponent(); try { ncdObj.PortName = comport; ncdObj.BaudRate = 115200; ncdObj.UsingComPort = true; ncdObj.OpenPort(); if (ncdObj.IsOpen) { int n = GetEE(ncdObj, 246); if ((n > 0) && (n & 32) > 0) { bRtn = true; } } } catch { bRtn = false; } finally { ncdObj.ClosePort(); } return bRtn; }
/// <summary> /// return value in specific address /// return -1 if not valid /// 0-255 for value in rom /// </summary> /// <param name="addr"></param> /// <returns></returns> private static int GetEE(NCDComponent ncdObj, byte addr) { ncdObj.WriteBytesAPI(254, 53, addr); byte[] data = ncdObj.ReadBytesApi(); if (data != null) { return data[0]; } return -1; }
public void Initialize() { var configfile = ConfigurationManager.AppSettings["ConfigurationFilePath"]; if (File.Exists(configfile)) BasicConfiguration.Load(configfile); else { new BasicConfiguration { Path = configfile }.FillExample(); BasicConfiguration.Save(); throw new Exception("EmptyConfigurationException, Please fill the configuration with the right information and start again."); } NCDComponent = new NCDComponent {BaudRate = 38400, PortName = BasicConfiguration.Configuration.Comport}; //ncdComponent.Port = 1; NCDComponent.OpenPort(); if (!NCDComponent.IsOpen) throw new HardwareInitializationException(); //On boot load all the states into the outputendpoints via the state mapper. //Select the hardware states and report those IN ORDER to the endpoint state mapper. //To get the current state. //-------Output states var outputState = NCDComponent.ProXR.RelayBanks.GetRelaysStatusInAllBanks ().Take (BasicConfiguration.Configuration.AvailableRelayBanks.Count).ToList (); for (var bank = 0; bank < outputState.Count (); bank++) { ReportOutputStates (bank + 1, ParseValue (outputState[bank])); } }
public void Initialize() { var configfile = ConfigurationManager.AppSettings["ConfigurationFilePath"]; if (File.Exists(configfile)) BasicConfiguration.Load(configfile); else { new BasicConfiguration { Path = configfile }.FillExample(); BasicConfiguration.Save(); throw new Exception("EmptyConfigurationException, Please fill the configuration with the right information and start again."); } NCDComponent = new NCDComponent { BaudRate = 38400, PortName = BasicConfiguration.Configuration.Comport }; NCDComponent.OpenPort(); if (!NCDComponent.IsOpen) throw new Exception("Can't open port"); //-------Output states var outputState = NCDComponent.ProXR.RelayBanks.GetRelaysStatusInAllBanks(); for (byte bank = 0; bank < BasicConfiguration.Configuration.AvailableRelayBanks.Count; bank++) { ReportOutputStates (bank, ParseValue (outputState[bank])); } Run = new Thread(Runner); Run.Start(this); Input = new Thread(InputRunner); Input.Start(this); }