/// <summary> /// Gets the module type, module version number, and manufacturer for the DaisyLink module at a particular position on the chain. /// This throws an exception if the socket number is invalid or if the socket does not support DaisyLink. /// </summary> /// <param name="socketNumber">The socket number with the DaisyLink chain of devices.</param> /// <param name="position">The position on the chain of the module to query (first module is at position one).</param> /// <param name="manufacturer">Out parameter that returns the module manufacturer.</param> /// <param name="type">Out parameter that returns the type of the module.</param> /// <param name="version">Out parameter that returns the module version number.</param> protected static void GetModuleParameters(int socketNumber, uint position, out byte manufacturer, out byte type, out byte version) { Socket socket = Socket.GetSocket(socketNumber, true, null, null); if (position >= 1) { position--; } DaisyLink.GetDaisyLinkForSocket(socket, null).GetModuleParameters(position, out manufacturer, out type, out version); }
/// <summary> /// Returns the DaisyLink instance for a given DaisyLink compatible socket. /// If this is the first call to this method for a given socket, it creates a new DaisyLink instance, /// which causes the chain to be initialised using the DaisyLink protocol. /// </summary> /// <param name="socket">The socket where the DaisyLink chain of modules is plugged in.</param> /// <param name="module">The daisylink module.</param> /// <returns>The DaisyLink instance for that socket</returns> public static DaisyLink GetDaisyLinkForSocket(Socket socket, DaisyLinkModule module) { lock (portLock) { for (int i = 0; i < daisyLinkList.Count; i++) { if (((DaisyLink)daisyLinkList[i]).Socket == socket) { return((DaisyLink)daisyLinkList[i]); } } DaisyLink daisylink; daisylink = new DaisyLink(socket, module); daisyLinkList.Add(daisylink); daisylink.Initialize(); return(daisylink); } }
/// <summary> /// Returns the DaisyLink instance for a given DaisyLink compatible socket. /// If this is the first call to this method for a given socket, it creates a new DaisyLink instance, /// which causes the chain to be initialised using the DaisyLink protocol. /// </summary> /// <param name="socket">The socket where the DaisyLink chain of modules is plugged in.</param> /// <param name="module">The daisylink module.</param> /// <returns>The DaisyLink instance for that socket</returns> public static DaisyLink GetDaisyLinkForSocket(Socket socket, DaisyLinkModule module) { lock (portLock) { foreach (DaisyLink dl in daisyLinkList) { if (dl.Socket == socket) { return(dl); } } DaisyLink daisylink; daisylink = new DaisyLink(socket, module); daisyLinkList.Add(daisylink); daisylink.Initialize(); return(daisylink); } }
// Note: A constructor summary is auto-generated by the doc builder. /// <summary></summary> /// <param name="socketNumber">The socket that has this module plugged into it.</param> /// <param name="manufacturer">The manufacturer of the module.</param> /// <param name="moduleType">The manufacturer-specific type code of the module.</param> /// <param name="minModuleVersionSupported">The minimum acceptable firmware version for the module.</param> /// <param name="maxModuleVersionSupported">The maximum acceptable firmware version for the module.</param> /// <param name="clockRateKhz">The clock rate of the module.</param> /// <param name="moduleName">The module name.</param> /// <exception cref="T:System.Exception"> /// <list type="bullet"> /// <item>The daisy link version of the module on the chain is an unsupported version.</item> /// <item>The module type specified by <paramref name="moduleType"/> does not match the type found on the chain.</item> /// <item>The firmware version is not supported; it is less than <paramref name="minModuleVersionSupported"/> or greater than <paramref name="maxModuleVersionSupported"/>.</item> /// </list> /// </exception> protected DaisyLinkModule(int socketNumber, byte manufacturer, byte moduleType, byte minModuleVersionSupported, byte maxModuleVersionSupported, int clockRateKhz, String moduleName) { Socket socket = Socket.GetSocket(socketNumber, true, this, null); daisylink = DaisyLink.GetDaisyLinkForSocket(socket, this); if (daisylink.NodeCount == 0) { throw new Socket.InvalidSocketException("No DaisyLink modules are detected on socket " + socket + ". Please check that the DaisyLink module " + this + " is plugged in to the correct socket."); } if (daisylink.ReservedCount >= daisylink.NodeCount) { throw new Socket.InvalidSocketException("Problem initializing " + this + ": attempting to initialize " + (daisylink.ReservedCount + 1) + " DaisyLink modules on socket " + socket + " but only " + daisylink.NodeCount + " modules were found."); } // NOTE: PositionOnChain will be invalid until the end of the constructor (it is dependent on DeviceAddress) so daisylink.ReservedCount is used until then DaisyLinkVersion = daisylink.GetDaisyLinkVersion(daisylink.ReservedCount); if (DaisyLinkVersion != DaisyLinkVersionImplemented) { throw new ApplicationException("DaisyLink module " + this + " on Socket " + socket + " position " + (daisylink.ReservedCount + 1) + " uses unsupported DaisyLink version " + DaisyLinkVersion + " (expected " + DaisyLinkVersionImplemented + ")"); } daisylink.GetModuleParameters(daisylink.ReservedCount, out Manufacturer, out ModuleType, out ModuleVersion); if (manufacturer != Manufacturer) { throw new ApplicationException("Problem initializing " + this + ": unexpected DaisyLink module on Socket " + socket + " position " + (daisylink.ReservedCount + 1) + ". (Has manufacturer code " + Manufacturer + ", but expected " + manufacturer + ")"); } if (moduleType != ModuleType) { throw new ApplicationException("Problem initializing " + this + ": unexpected DaisyLink module on Socket " + socket + " position " + (daisylink.ReservedCount + 1) + ". (Has type " + ModuleType + ", but expected " + moduleType + ")"); } if (ModuleVersion < minModuleVersionSupported || ModuleVersion > maxModuleVersionSupported) { throw new ApplicationException("Problem initializing " + this + ": daisyLink module " + moduleName + " on Socket " + socket + " position " + (daisylink.ReservedCount + 1) + " has unsupported PSoC firmware version of " + ModuleVersion + " (expected min " + minModuleVersionSupported + " max " + maxModuleVersionSupported + ")"); } ModuleAddress = daisylink.ReserveNextDaisyLinkNodeAddress(this); }
/// <summary> /// Gets the number of DaisyLink modules on the chain at the specified socket number. /// This throws an exception if the socket number is invalid or if the socket does not support DaisyLink. /// If the socket is valid but there are no DaisyLink modules on the chain, it does not throw an exception but instead returns zero. /// </summary> /// <param name="socketNumber">The socket number.</param> /// <returns>The number of DaisyLink modules attached to the chain from the specified socket number.</returns> protected static int GetLengthOfChain(int socketNumber) { Socket socket = Socket.GetSocket(socketNumber, true, null, null); return(DaisyLink.GetDaisyLinkForSocket(socket, null).NodeCount); }
/// <summary> /// Returns the DaisyLink instance for a given DaisyLink compatible socket. /// If this is the first call to this method for a given socket, it creates a new DaisyLink instance, /// which causes the chain to be initialised using the DaisyLink protocol. /// </summary> /// <param name="socket">The socket where the DaisyLink chain of modules is plugged in.</param> /// <param name="module">The daisylink module.</param> /// <returns>The DaisyLink instance for that socket</returns> public static DaisyLink GetDaisyLinkForSocket(Socket socket, DaisyLinkModule module) { lock (portLock) { for (int i = 0; i < daisyLinkList.Count; i++) { if (((DaisyLink)daisyLinkList[i]).Socket == socket) return (DaisyLink)daisyLinkList[i]; } DaisyLink daisylink; daisylink = new DaisyLink(socket, module); daisyLinkList.Add(daisylink); daisylink.Initialize(); return daisylink; } }
/// <summary> /// Returns the DaisyLink instance for a given DaisyLink compatible socket. /// If this is the first call to this method for a given socket, it creates a new DaisyLink instance, /// which causes the chain to be initialised using the DaisyLink protocol. /// </summary> /// <param name="socket">The socket where the DaisyLink chain of modules is plugged in.</param> /// <param name="module">The daisylink module.</param> /// <returns>The DaisyLink instance for that socket</returns> public static DaisyLink GetDaisyLinkForSocket(Socket socket, DaisyLinkModule module) { lock (portLock) { foreach (DaisyLink dl in daisyLinkList) { if (dl.Socket == socket) { return dl; } } DaisyLink daisylink; daisylink = new DaisyLink(socket, module); daisyLinkList.Add(daisylink); daisylink.Initialize(); return daisylink; } }