cml__canopen_8h-source.html
来自「美国COPLEY驱动器,程序开发工具之一.」· HTML 代码 · 共 334 行 · 第 1/3 页
HTML
334 行
<a name="l00104"></a>00104 <span class="comment">with the default settings.</span><a name="l00105"></a>00105 <span class="comment">*/</span><a name="l00106"></a>00106 <span class="comment">/***************************************************************************/</span><a name="l00107"></a><a class="code" href="classCanOpenSettings.html">00107</a> <span class="keyword">class </span><a class="code" href="classCanOpenSettings.html">CanOpenSettings</a><a name="l00108"></a>00108 {<a name="l00109"></a>00109 <span class="keyword">public</span>:<a name="l00110"></a>00110 <a class="code" href="classCanOpenSettings.html#a0">CanOpenSettings</a>();<a name="l00111"></a>00111 <span class="comment"></span><a name="l00112"></a>00112 <span class="comment"> /// Defines the read thread priority. The read thread is started</span><a name="l00113"></a>00113 <span class="comment"> /// when the CanOpen object is first opened (using CanOpen::Open()).</span><a name="l00114"></a>00114 <span class="comment"> /// This thread is responsible for reading messages from the</span><a name="l00115"></a>00115 <span class="comment"> /// CANopen network and calling the message handlers associated with</span><a name="l00116"></a>00116 <span class="comment"> /// them. It should be run at a relatively high priority.</span><a name="l00117"></a>00117 <span class="comment"> /// Default: 9</span><a name="l00118"></a><a class="code" href="classCanOpenSettings.html#o0">00118</a> <span class="comment"></span> <span class="keywordtype">int</span> <a class="code" href="classCanOpenSettings.html#o0">readThreadPriority</a>;<a name="l00119"></a>00119 };<a name="l00120"></a>00120 <a name="l00121"></a>00121 <span class="comment">/***************************************************************************/</span><span class="comment"></span><a name="l00122"></a>00122 <span class="comment">/**</span><a name="l00123"></a>00123 <span class="comment">The CanOpen class is the top level interface into the CANopen network.</span><a name="l00124"></a>00124 <span class="comment">There should be at least one object of this class in every CANopen based</span><a name="l00125"></a>00125 <span class="comment">application. Normally, only one object will be necessary, however if more</span><a name="l00126"></a>00126 <span class="comment">then one independent CANopen network is in use, then more then one object</span><a name="l00127"></a>00127 <span class="comment">will be necessary.</span><a name="l00128"></a>00128 <span class="comment"></span><a name="l00129"></a>00129 <span class="comment">On startup, a low level CAN interface object should be created. This </span><a name="l00130"></a>00130 <span class="comment">object should be passed to the CANopen object's Open() method.</span><a name="l00131"></a>00131 <span class="comment">*/</span><a name="l00132"></a>00132 <span class="comment">/***************************************************************************/</span><a name="l00133"></a><a class="code" href="classCanOpen.html">00133</a> <span class="keyword">class </span><a class="code" href="classCanOpen.html">CanOpen</a>: <span class="keyword">public</span> <a class="code" href="classThread.html">Thread</a><a name="l00134"></a>00134 {<a name="l00135"></a>00135 <span class="keyword">public</span>:<a name="l00136"></a>00136 <a class="code" href="classCanOpen.html#a0">CanOpen</a>( <span class="keywordtype">void</span> );<a name="l00137"></a>00137 <a class="code" href="classCanOpen.html#a1">~CanOpen</a>( <span class="keywordtype">void</span> );<a name="l00138"></a>00138 <span class="keyword">const</span> <a class="code" href="classError.html">Error</a> *<a class="code" href="classCanOpen.html#a2">Open</a>( <a class="code" href="classCanInterface.html">CanInterface</a> &can );<a name="l00139"></a>00139 <span class="keyword">const</span> <a class="code" href="classError.html">Error</a> *<a class="code" href="classCanOpen.html#a2">Open</a>( <a class="code" href="classCanInterface.html">CanInterface</a> &can, <a class="code" href="classCanOpenSettings.html">CanOpenSettings</a> &settings );<a name="l00140"></a>00140 <span class="keywordtype">void</span> <a class="code" href="classCanOpen.html#a4">Close</a>( <span class="keywordtype">void</span> );<a name="l00141"></a>00141 <a name="l00142"></a>00142 <span class="keyword">const</span> <a class="code" href="classError.html">Error</a> *<a class="code" href="classCanOpen.html#a5">Xmit</a>( <a class="code" href="structCanFrame.html">CanFrame</a> &frame, <a class="code" href="CML__Utils_8h.html#a9">int32</a> timeout=2000 );<a name="l00143"></a>00143 <span class="keyword">const</span> <a class="code" href="classError.html">Error</a> *<a class="code" href="classCanOpen.html#a6">ResetNode</a>( <span class="keywordtype">int</span> nodeID=0 );<a name="l00144"></a>00144 <span class="keyword">const</span> <a class="code" href="classError.html">Error</a> *<a class="code" href="classCanOpen.html#a7">ResetComm</a>( <span class="keywordtype">int</span> nodeID=0 );<a name="l00145"></a>00145 <span class="keyword">const</span> <a class="code" href="classError.html">Error</a> *<a class="code" href="classCanOpen.html#a8">PreOpNode</a>( <span class="keywordtype">int</span> nodeID=0 );<a name="l00146"></a>00146 <span class="keyword">const</span> <a class="code" href="classError.html">Error</a> *<a class="code" href="classCanOpen.html#a9">StartNode</a>( <span class="keywordtype">int</span> nodeID=0 );<a name="l00147"></a>00147 <span class="keyword">const</span> <a class="code" href="classError.html">Error</a> *<a class="code" href="classCanOpen.html#a10">StopNode</a>( <span class="keywordtype">int</span> nodeID=0 );<a name="l00148"></a>00148 <span class="comment"></span><a name="l00149"></a>00149 <span class="comment"> /// Return the node ID of the synch producer for this network.</span><a name="l00150"></a>00150 <span class="comment"> /// @return The synch producer node ID, or 0 if no synch producer</span><a name="l00151"></a>00151 <span class="comment"> /// has been registered.</span><a name="l00152"></a><a class="code" href="classCanOpen.html#a11">00152</a> <span class="comment"></span> <a class="code" href="CML__Utils_8h.html#a7">int16</a> <a class="code" href="classCanOpen.html#a11">GetSynchProducer</a>( <span class="keywordtype">void</span> ){<a name="l00153"></a>00153 <span class="keywordflow">return</span> synchProducer;<a name="l00154"></a>00154 }<a name="l00155"></a>00155 <span class="comment"></span><a name="l00156"></a>00156 <span class="comment"> /// Set the node ID of the synch producer for this network.</span><a name="l00157"></a>00157 <span class="comment"> /// @param nodeID The new synch producer node ID, or 0 for none.</span><a name="l00158"></a><a class="code" href="classCanOpen.html#a12">00158</a> <span class="comment"></span> <span class="keywordtype">void</span> <a class="code" href="classCanOpen.html#a12">SetSynchProducer</a>( <a class="code" href="CML__Utils_8h.html#a7">int16</a> nodeID ){<a name="l00159"></a>00159 synchProducer = nodeID;<a name="l00160"></a>00160 }<a name="l00161"></a>00161 <span class="comment"></span><a name="l00162"></a>00162 <span class="comment"> /// Return the number of error frames received over then CAN network</span><a name="l00163"></a>00163 <span class="comment"> /// since the last time the counter was cleared</span><a name="l00164"></a>00164 <span class="comment"> /// @return The number of error frames received since the last call</span><a name="l00165"></a>00165 <span class="comment"> /// to CanOpen::ClearErrorFrameCounter();</span><a name="l00166"></a><a class="code" href="classCanOpen.html#a13">00166</a> <span class="comment"></span> <a class="code" href="CML__Utils_8h.html#a9">int32</a> <a class="code" href="classCanOpen.html#a13">GetErrorFrameCounter</a>( <span class="keywordtype">void</span> ){<a name="l00167"></a>00167 <span class="keywordflow">return</span> errorFrameCt;<a name="l00168"></a>00168 }<a name="l00169"></a>00169 <span class="comment"></span><a name="l00170"></a>00170 <span class="comment"> /// Clear the error frame counter</span><a name="l00171"></a><a class="code" href="classCanOpen.html#a14">00171</a> <span class="comment"></span> <span class="keywordtype">void</span> <a class="code" href="classCanOpen.html#a14">ClearErrorFrameCounter</a>( <span class="keywordtype">void</span> ){<a name="l00172"></a>00172 errorFrameCt = 0;<a name="l00173"></a>00173 }<a name="l00174"></a>00174 <a name="l00175"></a>00175 <span class="keyword">private</span>:<a name="l00176"></a>00176 <span class="keyword">const</span> <a class="code" href="classError.html">Error</a> *NMT_Msg( <span class="keywordtype">int</span> code, <span class="keywordtype">int</span> nodeID );<a name="l00177"></a>00177 <a name="l00178"></a>00178 <span class="keyword">const</span> <a class="code" href="classError.html">Error</a> *EnableReceiver( <span class="keyword">class</span> <a class="code" href="classReceiver.html">Receiver</a> *receiver );<a name="l00179"></a>00179 <span class="keyword">const</span> <a class="code" href="classError.html">Error</a> *DisableReceiver( <span class="keyword">class</span> <a class="code" href="classReceiver.html">Receiver</a> *receiver );<a name="l00180"></a>00180 <a class="code" href="classReceiver.html">Receiver</a> **searchHash( <a class="code" href="CML__Utils_8h.html#a10">uint32</a> <span class="keywordtype">id</span> );<a name="l00181"></a>00181 <span class="comment"></span><a name="l00182"></a>00182 <span class="comment"> /// This hash is used to keep track of the Receiver</span><a name="l00183"></a>00183 <span class="comment"> /// objects that are enabled.</span><a name="l00184"></a>00184 <span class="comment"></span> <span class="keyword">class </span><a class="code" href="classReceiver.html">Receiver</a> *hash[ <a class="code" href="CML__Settings_8h.html#a1">CML_HASH_SIZE</a> ];<a name="l00185"></a>00185 <span class="comment"></span><a name="l00186"></a>00186 <span class="comment"> /// This mutex is used to control access to the receiver hash.</span><a name="l00187"></a>00187 <span class="comment"></span> <a class="code" href="classMutex.html">Mutex</a> hashMutex;<a name="l00188"></a>00188 <span class="comment"></span><a name="l00189"></a>00189 <span class="comment"> /// Pointer to the can interface object passed during construction</span><a name="l00190"></a>00190 <span class="comment"></span> <a class="code" href="classCanInterface.html">CanInterface</a> *can;<a name="l00191"></a>00191 <span class="comment"></span><a name="l00192"></a>00192 <span class="comment"> /// This variable is used to determine if a synch message producer</span><a name="l00193"></a>00193 <span class="comment"> /// has been assigned to this network.</span><a name="l00194"></a>00194 <span class="comment"></span> <a class="code" href="CML__Utils_8h.html#a7">int16</a> synchProducer;<a name="l00195"></a>00195 <span class="comment"></span><a name="l00196"></a>00196 <span class="comment"> /// This variable is used to keep a count of CAN error frames for</span><a name="l00197"></a>00197 <span class="comment"> /// diagnostic purposes.</span><a name="l00198"></a>00198 <span class="comment"></span> <a class="code" href="CML__Utils_8h.html#a9">int32</a> errorFrameCt;<a name="l00199"></a>00199 <a name="l00200"></a>00200 <span class="keywordtype">void</span> run( <span class="keywordtype">void</span> );<a name="l00201"></a><a class="code" href="classCanOpen.html#n0">00201</a> <span class="keyword">friend</span> <span class="keyword">class </span><a class="code" href="classReceiver.html">Receiver</a>;<a name="l00202"></a><a class="code" href="classCanOpen.html#n1">00202</a> <span class="keyword">friend</span> <span class="keyword">class </span><a class="code" href="classCanInterface.html">CanInterface</a>;<a name="l00203"></a>00203 };<a name="l00204"></a>00204 <a name="l00205"></a>00205 <span class="comment">/***************************************************************************/</span><span class="comment"></span><a name="l00206"></a>00206 <span class="comment">/**</span><a name="l00207"></a>00207 <span class="comment">CANopen receiver object. This class allows the programmer to create routines</span><a name="l00208"></a>00208 <span class="comment">that are run whenever a CAN frame with a specific ID is received. </span><a name="l00209"></a>00209 <span class="comment"></span><a name="l00210"></a>00210 <span class="comment">To run code when a message is received, create a new class that extends</span><a name="l00211"></a>00211 <span class="comment">Receiver. The Receiver::Init() function should be called with the COB-ID </span><a name="l00212"></a>00212 <span class="comment">of the frames to be received. Whenever this new class is Enabled(), the</span><a name="l00213"></a>00213 <span class="comment">member function NewFrame() will be called once for every frame received with</span><a name="l00214"></a>00214 <span class="comment">a matching ID.</span><a name="l00215"></a>00215 <span class="comment">*/</span>
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?