从代码关闭IoT设备

时间:2018-03-15 21:39:24

标签: c# iot systemmanagement

我所拥有的是:VS 2017社区,C#,Raspberry 3,IoT-Extension引用。 我想从代码中关闭Raspberry。 我在网上到处发现的是: 编辑AppManifest。加   ... IgnorableNamespaces =" uap mp iot"> ( - 当我调查它时已经在那里) 然后添加:

<iot:Capability Name="systemManagement"/>

但是:&#34; iot:能力&#34;保持不足,说,它具有无效的子元素&#39;功能&#39;在命名空间&#39; http:... appX / manifest / iot / win10&#39;

我已经选择了其他2个功能

<Capability Name="internetClient" />
<Capability Name="privateNetworkClientServer" />

他们会干涉吗? 我无法在整个网络上的其他地方找到此错误。如果有人对此有解释,那就太棒了。提前谢谢!

1 个答案:

答案 0 :(得分:1)

要使用ShutdownManager管理设备关闭,您需要:

  1. 参考Windows IoT Extension SDK(v10.0.10240.0或更高版本)
  2. 将以下内容添加到应用程序Package.appmanifest:import ctypes class Array : # Creates an array with size elements. def __init__( self, size ): assert size > 0, "Array size must be > 0" self._size = size # Create the array structure using the ctypes module. PyArrayType = ctypes.py_object * size self._elements = PyArrayType() # Initialize each element. self.clear(None) # Returns the size of the array. def __len__( self ): return self._size # Gets the contents of the index element. def __getitem__( self, index ): assert index >= 0 and index < len(self), "Array subscript out of range" return self._elements[ index ] # Puts the value in the array element at index position. def __setitem__( self, index, value ): assert index >= 0 and index < len(self), "Array subscript out of range" self._elements[ index ] = value # Clears the array by setting each element to the given value. def clear( self, value ) : for i in range(len(self)) : self._elements[i] = value # Implementation of the Array2D ADT using an array of arrays. class Array2D : # Creates a 2-D array of size numRows x numCols. def __init__( self, numRows, numCols ): # Create a 1-D array to store an array reference for each row. self._theRows = Array(numRows) # Create the 1-D arrays for each row of the 2-D array. for i in range( numRows ) : self._theRows[i] = Array(numCols) # Returns the number of rows in the 2-d array. def numRows( self ): return len( self._theRows ) # Returns the number of columns in the 2-d array. def numCols( self ): return len( self._theRows[0] ) # Clears the array by setting every element to the given value. def clear( self, value ): for row in range(len(self._theRows)) : self._theRows[row].clear(value) # Get the contents of the element at position [i, j] def __getitem__( self, ndxTuple ): assert len(ndxTuple) == 2, "Invalid number of array subscripts." row = ndxTuple[0] col = ndxTuple[1] assert row >= 0 and row < self.numRows() \ and col >= 0 and col < self.numCols(), \ "Array subscript out of range." the1dArray = self._theRows[row] return the1dArray[col] # Set the contents of the element at position [i,j] to value. def __setitem__( self, ndxTuple, value ): assert len(ndxTuple) == 2, "Invalid number of array subscripts." row = ndxTuple[0] col = ndxTuple[1] assert row >= 0 and row < self.numRows() \ and col >= 0 and col < self.numCols(), \ "Array subscript out of range." the1dArray = self._theRows[row] the1dArray[col] = value
  3. 添加此名称空间:<iot:Capability Name="systemManagement"/>
  4. 有关详细信息,请参阅ShutdownManager Class