/// <summary> /// Get module identification. /// </summary> /// <param name="addr">Address of the module.</param> /// <returns>A correctly typed Module instance.</returns> private IModule GetModuleIdent(byte addr) { IModule module = null; var answer = new BICCPData(); if (Biccp.RequestToModule(addr, answer, ICCConstants.BICCP_GRP_CONF, ICCConstants.BICCP_CMD_CONF_VERSION)) { int iMajor = answer.Data[0]; int iMinor = answer.Data[1]; int iBuild = answer.Data[2]; if (Biccp.RequestToModule(addr, answer, ICCConstants.BICCP_GRP_CONF, ICCConstants.BICCP_CMD_CONF_IDENT)) { module = ModuleFactory.CreateInstance(answer.Data[1]); module.Major = iMajor; module.Minor = iMinor; module.Build = iBuild; module.Description = string.Empty; for (int i = 0; i < ICCConstants.DESCSIZE; i++) { if (answer.Data[i + 2] != 0) { module.Description += (char)answer.Data[i + 2]; } } } } Log.LogMessage((module != null), "Module identification", addr); return(module); }
static void Main(string[] args) { Modules = new Dictionary <int, Module>(); Addresses = new int[0x78]; byte[] b = new byte[0x78]; var m = new I2CManager(); int i = m.I2CScan(1, ref b); Console.WriteLine(string.Format("{0} modules detected.", i)); for (int l = 0; l < 0x78; l++) { if (b[l] != 0) { Console.WriteLine(string.Format("Module detected at address {0}.", l)); } } System.Threading.Thread.Sleep(2000); var answer = new BICCPData(); // if (_BICCPManager.RequestToModule(addr, answer, ICCConstants.BICCP_GRP_CONF, ICCConstants.BICCP_CMD_CONF_VERSION) != 0) //int fd = GetFDFromAddress(0x08); //Console.WriteLine(string.Format("File descriptor : {0}", fd)); byte[] buffer = new byte[ICCConstants.PACKETSIZE]; buffer[0] = ICCConstants.BICCP_GRP_CONF; buffer[1] = ICCConstants.BICCP_CMD_CONF_VERSION; for (int l = 2; l < ICCConstants.PACKETSIZE; l++) { buffer[l] = 0; } //for (int l = 0; l < datas.Length; i++) //{ // if (i < ICCConstants.DATASIZE) // buffer[l + 2] = datas[l]; //} PrintBuffer(buffer, "Before call"); int j = RequestToModuleFromBuffer(0x08, ref buffer); if (j == 0) { Console.WriteLine("RequestToModuleFromBuffer returned 0."); } else if (buffer[0] != ICCConstants.BICCP_GRP_CONF || buffer[1] != ICCConstants.BICCP_CMD_CONF_VERSION) { Console.WriteLine("RequestToModuleFromBuffer returned wrong group or command."); } else { Console.WriteLine("Correct return."); //for (int i = 0; i < ICCConstants.DATASIZE; i++) // data.Data[i] = buffer[i + 2]; //return -1; } buffer = new byte[ICCConstants.PACKETSIZE]; buffer[0] = ICCConstants.BICCP_GRP_CONF; buffer[1] = ICCConstants.BICCP_CMD_CONF_IDENT; for (int l = 2; l < ICCConstants.PACKETSIZE; l++) { buffer[l] = 0; } //for (int l = 0; l < datas.Length; i++) //{ // if (i < ICCConstants.DATASIZE) // buffer[l + 2] = datas[l]; //} PrintBuffer(buffer, "Before call"); j = RequestToModuleFromBuffer(0x08, ref buffer); if (j == 0) { Console.WriteLine("RequestToModuleFromBuffer returned 0."); } else if (buffer[0] != ICCConstants.BICCP_GRP_CONF || buffer[1] != ICCConstants.BICCP_CMD_CONF_IDENT) { Console.WriteLine("RequestToModuleFromBuffer returned wrong group or command."); } else { Console.WriteLine("Correct return."); //for (int i = 0; i < ICCConstants.DATASIZE; i++) // data.Data[i] = buffer[i + 2]; //return -1; } }
private static void Mod_ActionRaised(object sender, ActionEventArgs e) { var answer = new BICCPData(); e.Action.ToBICCP(Biccp, answer); }