cml__pdo_8h-source.html

来自「美国COPLEY驱动器,程序开发工具之一.」· HTML 代码 · 共 571 行 · 第 1/5 页

HTML
571
字号
<a name="l00222"></a>00222       <span class="keywordflow">return</span> <a class="code" href="classPmap.html#a3">Pmap::Init</a>( index, <a class="code" href="classPmap.html#p1">sub</a>, 32 );<a name="l00223"></a>00223    }<a name="l00224"></a>00224 <span class="comment"></span><a name="l00225"></a>00225 <span class="comment">   /// Copy the current value of this variable into the passed</span><a name="l00226"></a>00226 <span class="comment">   /// character array.  This function is called when a receive</span><a name="l00227"></a>00227 <span class="comment">   /// PDO is about to be transmitted to a node.</span><a name="l00228"></a>00228 <span class="comment">   /// @param cptr A character pointer that references a char</span><a name="l00229"></a>00229 <span class="comment">   ///        array of at least 4 bytes.  The current value</span><a name="l00230"></a>00230 <span class="comment">   ///        of this variable will be copied there.</span><a name="l00231"></a><a class="code" href="classPmap32.html#a3">00231</a> <span class="comment"></span>   <span class="keyword">virtual</span> <span class="keywordtype">void</span> <a class="code" href="classPmap32.html#a3">Get</a>( <a class="code" href="CML__Utils_8h.html#a2">byte</a> *cptr ){<a name="l00232"></a>00232       m.<a class="code" href="classMutex.html#a2">Lock</a>();<a name="l00233"></a>00233       <a class="code" href="CML__Utils_8h.html#a9">int32</a> v = data;<a name="l00234"></a>00234       m.<a class="code" href="classMutex.html#a3">Unlock</a>();<a name="l00235"></a>00235       cptr[0] = <a class="code" href="CML__Utils_8h.html#a0">ByteCast</a>(v);<a name="l00236"></a>00236       cptr[1] = <a class="code" href="CML__Utils_8h.html#a0">ByteCast</a>(v&gt;&gt;8);<a name="l00237"></a>00237       cptr[2] = <a class="code" href="CML__Utils_8h.html#a0">ByteCast</a>(v&gt;&gt;16);<a name="l00238"></a>00238       cptr[3] = <a class="code" href="CML__Utils_8h.html#a0">ByteCast</a>(v&gt;&gt;24);<a name="l00239"></a>00239    }<a name="l00240"></a>00240 <span class="comment"></span><a name="l00241"></a>00241 <span class="comment">   /// Update the value of this variable based on the data passed</span><a name="l00242"></a>00242 <span class="comment">   /// in a character array.  This function is called when a transmit</span><a name="l00243"></a>00243 <span class="comment">   /// PDO that this variable is mapped to is received.</span><a name="l00244"></a>00244 <span class="comment">   /// @param cptr A character pointer that references a char</span><a name="l00245"></a>00245 <span class="comment">   ///        array of at least 4 bytes.  The value of this variable </span><a name="l00246"></a>00246 <span class="comment">   ///        will be updated with the data passed in this array.</span><a name="l00247"></a><a class="code" href="classPmap32.html#a4">00247</a> <span class="comment"></span>   <span class="keyword">virtual</span> <span class="keywordtype">void</span> <a class="code" href="classPmap32.html#a4">Set</a>( <a class="code" href="CML__Utils_8h.html#a2">byte</a> *cptr ){<a name="l00248"></a>00248       <a class="code" href="CML__Utils_8h.html#a9">int32</a> v = <a class="code" href="CML__Utils_8h.html#a14">bytes_to_int32</a>( cptr );<a name="l00249"></a>00249       m.<a class="code" href="classMutex.html#a2">Lock</a>();<a name="l00250"></a>00250       data = v;<a name="l00251"></a>00251       m.<a class="code" href="classMutex.html#a3">Unlock</a>();<a name="l00252"></a>00252    }<a name="l00253"></a>00253 <span class="comment"></span><a name="l00254"></a>00254 <span class="comment">   /// Read the current value of this variable</span><a name="l00255"></a>00255 <span class="comment">   /// @return The current value of this variable.</span><a name="l00256"></a><a class="code" href="classPmap32.html#a5">00256</a> <span class="comment"></span>   <span class="keyword">virtual</span> <a class="code" href="CML__Utils_8h.html#a9">int32</a> <a class="code" href="classPmap32.html#a5">Read</a>( <span class="keywordtype">void</span> ){<a name="l00257"></a>00257       m.<a class="code" href="classMutex.html#a2">Lock</a>();<a name="l00258"></a>00258       <a class="code" href="CML__Utils_8h.html#a9">int32</a> d = data;<a name="l00259"></a>00259       m.<a class="code" href="classMutex.html#a3">Unlock</a>();<a name="l00260"></a>00260       <span class="keywordflow">return</span> d;<a name="l00261"></a>00261    }<a name="l00262"></a>00262 <span class="comment"></span><a name="l00263"></a>00263 <span class="comment">   /// Write a new value to this variable.</span><a name="l00264"></a>00264 <span class="comment">   /// @param d The new value to write.</span><a name="l00265"></a><a class="code" href="classPmap32.html#a6">00265</a> <span class="comment"></span>   <span class="keyword">virtual</span> <span class="keywordtype">void</span> <a class="code" href="classPmap32.html#a6">Write</a>( <a class="code" href="CML__Utils_8h.html#a9">int32</a> d ){<a name="l00266"></a>00266       m.<a class="code" href="classMutex.html#a2">Lock</a>();<a name="l00267"></a>00267       data = d;<a name="l00268"></a>00268       m.<a class="code" href="classMutex.html#a3">Unlock</a>();<a name="l00269"></a>00269    }<a name="l00270"></a>00270 <a name="l00271"></a>00271 <span class="keyword">private</span>:<span class="comment"></span><a name="l00272"></a>00272 <span class="comment">   /// A mutex used to protect access to this variable</span><a name="l00273"></a>00273 <span class="comment"></span>   <a class="code" href="classMutex.html">Mutex</a> m;<a name="l00274"></a>00274 <span class="comment"></span><a name="l00275"></a>00275 <span class="comment">   /// The 32-bit integer associated with this mapping.</span><a name="l00276"></a>00276 <span class="comment"></span>   <a class="code" href="CML__Utils_8h.html#a9">int32</a> data;<a name="l00277"></a>00277 };<a name="l00278"></a>00278 <a name="l00279"></a>00279 <span class="comment">/***************************************************************************/</span><span class="comment"></span><a name="l00280"></a>00280 <span class="comment">/**</span><a name="l00281"></a>00281 <span class="comment">This is a PDO variable mapping class that extends the virtual Pmap class to</span><a name="l00282"></a>00282 <span class="comment">handle 24-bit integers.</span><a name="l00283"></a>00283 <span class="comment">*/</span><a name="l00284"></a>00284 <span class="comment">/***************************************************************************/</span><a name="l00285"></a><a class="code" href="classPmap24.html">00285</a> <span class="keyword">class </span><a class="code" href="classPmap24.html">Pmap24</a>: <span class="keyword">public</span> <a class="code" href="classPmap.html">Pmap</a><a name="l00286"></a>00286 {<a name="l00287"></a>00287 <span class="keyword">public</span>:<span class="comment"></span><a name="l00288"></a>00288 <span class="comment">   /// Default constructor for a 24-bit mapping object</span><a name="l00289"></a><a class="code" href="classPmap24.html#a0">00289</a> <span class="comment"></span>   <a class="code" href="classPmap24.html#a0">Pmap24</a>():data(0){}<a name="l00290"></a>00290 <span class="comment"></span><a name="l00291"></a>00291 <span class="comment">   /// Create a new 24-bit mapping object</span><a name="l00292"></a>00292 <span class="comment">   /// @param index Object index associated with this variable</span><a name="l00293"></a>00293 <span class="comment">   /// @param sub Object sub-index (defaults to 0)</span><a name="l00294"></a><a class="code" href="classPmap24.html#a1">00294</a> <span class="comment"></span>   <a class="code" href="classPmap24.html#a0">Pmap24</a>( <a class="code" href="CML__Utils_8h.html#a8">uint16</a> <a class="code" href="classPmap.html#p0">index</a>, <a class="code" href="CML__Utils_8h.html#a2">byte</a> <a class="code" href="classPmap.html#p1">sub</a>=0 ):<a class="code" href="classPmap.html">Pmap</a>(index,<a class="code" href="classPmap.html#p1">sub</a>,24), data(0){}<a name="l00295"></a>00295 <span class="comment"></span><a name="l00296"></a>00296 <span class="comment">   /// Initialize a 24-bit mapping object</span><a name="l00297"></a>00297 <span class="comment">   /// @param index Object index associated with this variable</span><a name="l00298"></a>00298 <span class="comment">   /// @param sub Object sub-index (defaults to 0)</span><a name="l00299"></a>00299 <span class="comment">   /// @return An error object</span><a name="l00300"></a><a class="code" href="classPmap24.html#a2">00300</a> <span class="comment"></span>   <span class="keyword">const</span> <a class="code" href="classError.html">Error</a> *<a class="code" href="classPmap24.html#a2">Init</a>( <a class="code" href="CML__Utils_8h.html#a8">uint16</a> <a class="code" href="classPmap.html#p0">index</a>, <a class="code" href="CML__Utils_8h.html#a2">byte</a> <a class="code" href="classPmap.html#p1">sub</a>=0 ){<a name="l00301"></a>00301       <span class="keywordflow">return</span> <a class="code" href="classPmap.html#a3">Pmap::Init</a>( index, <a class="code" href="classPmap.html#p1">sub</a>, 24 );<a name="l00302"></a>00302    }<a name="l00303"></a>00303 <span class="comment"></span><a name="l00304"></a>00304 <span class="comment">   /// Copy the current value of this variable into the passed</span><a name="l00305"></a>00305 <span class="comment">   /// character array.  This function is called when a receive</span><a name="l00306"></a>00306 <span class="comment">   /// PDO is about to be transmitted to a node.</span><a name="l00307"></a>00307 <span class="comment">   /// @param cptr A character pointer that references a char</span><a name="l00308"></a>00308 <span class="comment">   ///        array of at least 4 bytes.  The current value</span><a name="l00309"></a>00309 <span class="comment">   ///        of this variable will be copied there.</span><a name="l00310"></a><a class="code" href="classPmap24.html#a3">00310</a> <span class="comment"></span>   <span class="keyword">virtual</span> <span class="keywordtype">void</span> <a class="code" href="classPmap24.html#a3">Get</a>( <a class="code" href="CML__Utils_8h.html#a2">byte</a> *cptr ){<a name="l00311"></a>00311       m.<a class="code" href="classMutex.html#a2">Lock</a>();<a name="l00312"></a>00312       <a class="code" href="CML__Utils_8h.html#a9">int32</a> v = data;<a name="l00313"></a>00313       m.<a class="code" href="classMutex.html#a3">Unlock</a>();<a name="l00314"></a>00314       cptr[0] = <a class="code" href="CML__Utils_8h.html#a0">ByteCast</a>(v);<a name="l00315"></a>00315       cptr[1] = <a class="code" href="CML__Utils_8h.html#a0">ByteCast</a>(v&gt;&gt;8);<a name="l00316"></a>00316       cptr[2] = <a class="code" href="CML__Utils_8h.html#a0">ByteCast</a>(v&gt;&gt;16);<a name="l00317"></a>00317    }<a name="l00318"></a>00318 <span class="comment"></span><a name="l00319"></a>00319 <span class="comment">   /// Update the value of this variable based on the data passed</span><a name="l00320"></a>00320 <span class="comment">   /// in a character array.  This function is called when a transmit</span><a name="l00321"></a>00321 <span class="comment">   /// PDO that this variable is mapped to is received.</span><a name="l00322"></a>00322 <span class="comment">   /// @param cptr A character pointer that references a char</span><a name="l00323"></a>00323 <span class="comment">   ///        array of at least 4 bytes.  The value of this variable </span><a name="l00324"></a>00324 <span class="comment">   ///        will be updated with the data passed in this array.</span><a name="l00325"></a><a class="code" href="classPmap24.html#a4">00325</a> <span class="comment"></span>   <span class="keyword">virtual</span> <span class="keywordtype">void</span> <a class="code" href="classPmap24.html#a4">Set</a>( <a class="code" href="CML__Utils_8h.html#a2">byte</a> *cptr ){<a name="l00326"></a>00326       <a class="code" href="CML__Utils_8h.html#a9">int32</a> v = <a class="code" href="CML__Utils_8h.html#a14">bytes_to_int32</a>(cptr);<a name="l00327"></a>00327       v = (v&lt;&lt;8) &gt;&gt; 8;<a name="l00328"></a>00328       m.<a class="code" href="classMutex.html#a2">Lock</a>();<a name="l00329"></a>00329       data = v;<a name="l00330"></a>00330       m.<a class="code" href="classMutex.html#a3">Unlock</a>();<a name="l00331"></a>00331    }<a name="l00332"></a>00332 <span class="comment"></span><a name="l00333"></a>00333 <span class="comment">   /// Read the current value of this variable</span><a name="l00334"></a>00334 <span class="comment">   /// @return The current value of this variable.</span><a name="l00335"></a><a class="code" href="classPmap24.html#a5">00335</a> <span class="comment"></span>   <span class="keyword">virtual</span> <a class="code" href="CML__Utils_8h.html#a9">int32</a> <a class="code" href="classPmap24.html#a5">Read</a>( <span class="keywordtype">void</span> ){<a name="l00336"></a>00336       m.<a class="code" href="classMutex.html#a2">Lock</a>();

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?