⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 lss_8cpp-source.html

📁 美国COPLEY驱动器,程序开发工具之一.
💻 HTML
📖 第 1 页 / 共 2 页
字号:
<a name="l00128"></a>00128 <span class="comment">/***************************************************************************/</span><span class="comment"></span><a name="l00129"></a>00129 <span class="comment">/**</span><a name="l00130"></a>00130 <span class="comment">  Put the specified amplifier into LSS configure mode.  All other amplifiers</span><a name="l00131"></a>00131 <span class="comment">  on the network are switched into LSS operational mode.</span><a name="l00132"></a>00132 <span class="comment">  */</span><a name="l00133"></a>00133 <span class="comment">/***************************************************************************/</span><a name="l00134"></a><a class="code" href="classLSS.html#b0">00134</a> <span class="keyword">const</span> <a class="code" href="classError.html">Error</a> *<a class="code" href="classLSS.html#b0">LSS::SelectAmp</a>( <a class="code" href="CML__Utils_8h.html#a10">uint32</a> serial )<a name="l00135"></a>00135 {<a name="l00136"></a>00136    <span class="keyword">const</span> <a class="code" href="classError.html">Error</a> *err;<a name="l00137"></a>00137 <a name="l00138"></a>00138    <span class="comment">// Switch all devices on the network out of LSS config mode</span><a name="l00139"></a>00139    err = <a class="code" href="classLSS.html#b3">Xmit</a>( 4, 0 );<a name="l00140"></a>00140 <a name="l00141"></a>00141    <span class="comment">// Put the amplifier with the specified serial number into config mode.</span><a name="l00142"></a>00142    <span class="keywordflow">if</span>( !err ) err = <a class="code" href="classLSS.html#b3">Xmit</a>( 64, 0xAB );<a name="l00143"></a>00143    <span class="keywordflow">if</span>( !err ) err = <a class="code" href="classLSS.html#b3">Xmit</a>( 65, 0 );<a name="l00144"></a>00144    <span class="keywordflow">if</span>( !err ) err = <a class="code" href="classLSS.html#b3">Xmit</a>( 66, 0 );<a name="l00145"></a>00145    <span class="keywordflow">if</span>( err ) <span class="keywordflow">return</span> err;<a name="l00146"></a>00146 <a name="l00147"></a>00147    <span class="comment">// Clear out the semaphore and transfer the serial number message.  This</span><a name="l00148"></a>00148    <span class="comment">// should cause the selected amplifier to respond</span><a name="l00149"></a>00149    <span class="keywordflow">while</span>( !sem.<a class="code" href="classSemaphore.html#a2">Get</a>(0) );<a name="l00150"></a>00150    recvCS = 68;<a name="l00151"></a>00151 <a name="l00152"></a>00152    err = <a class="code" href="classLSS.html#b3">Xmit</a>( 67, serial );<a name="l00153"></a>00153    <span class="keywordflow">if</span>( !err ) err = sem.<a class="code" href="classSemaphore.html#a2">Get</a>( timeout );<a name="l00154"></a>00154 <a name="l00155"></a>00155    recvCS = 0;<a name="l00156"></a>00156 <a name="l00157"></a>00157    <span class="keywordflow">return</span> err;<a name="l00158"></a>00158 }<a name="l00159"></a>00159 <a name="l00160"></a>00160 <span class="comment">/***************************************************************************/</span><span class="comment"></span><a name="l00161"></a>00161 <span class="comment">/**</span><a name="l00162"></a>00162 <span class="comment">  This method is called by the main CAN network listener when a new LSS </span><a name="l00163"></a>00163 <span class="comment">  response frame is received.</span><a name="l00164"></a>00164 <span class="comment">  */</span><a name="l00165"></a>00165 <span class="comment">/***************************************************************************/</span><a name="l00166"></a><a class="code" href="classLSS.html#b2">00166</a> <span class="keywordtype">int</span> <a class="code" href="classLSS.html#b2">LSS::NewFrame</a>( <a class="code" href="structCanFrame.html">CanFrame</a> &amp;frame )<a name="l00167"></a>00167 {<a name="l00168"></a>00168    <span class="comment">// Ignore any messages when not expected</span><a name="l00169"></a>00169    <span class="keywordflow">if</span>( !recvCS )<a name="l00170"></a>00170       <span class="keywordflow">return</span> 1;<a name="l00171"></a>00171 <a name="l00172"></a>00172    <span class="comment">// When an expected message is received, capture</span><a name="l00173"></a>00173    <span class="comment">// the data and post a semaphore.</span><a name="l00174"></a>00174    <span class="keywordflow">else</span> <span class="keywordflow">if</span>( frame.<a class="code" href="structCanFrame.html#o3">data</a>[0] == recvCS )<a name="l00175"></a>00175    {<a name="l00176"></a>00176       recvData = <a class="code" href="CML__Utils_8h.html#a12">bytes_to_uint32</a>( &amp;frame.<a class="code" href="structCanFrame.html#o3">data</a>[1] );<a name="l00177"></a>00177       sem.<a class="code" href="classSemaphore.html#a3">Put</a>();<a name="l00178"></a>00178    }<a name="l00179"></a>00179 <a name="l00180"></a>00180    <span class="keywordflow">return</span> 1;<a name="l00181"></a>00181 }<a name="l00182"></a>00182 <a name="l00183"></a>00183 <span class="comment">/***************************************************************************/</span><span class="comment"></span><a name="l00184"></a>00184 <span class="comment">/**</span><a name="l00185"></a>00185 <span class="comment">  Find the serial number of the first amplifier in the passed range.</span><a name="l00186"></a>00186 <span class="comment">  @return the serial number, or zero if no amp found.</span><a name="l00187"></a>00187 <span class="comment">  */</span><a name="l00188"></a>00188 <span class="comment">/***************************************************************************/</span><a name="l00189"></a><a class="code" href="classLSS.html#b1">00189</a> <a class="code" href="CML__Utils_8h.html#a10">uint32</a> <a class="code" href="classLSS.html#b1">LSS::FindAmpSerial</a>( <a class="code" href="CML__Utils_8h.html#a10">uint32</a> low, <a class="code" href="CML__Utils_8h.html#a10">uint32</a> high )<a name="l00190"></a>00190 {<a name="l00191"></a>00191    <span class="comment">// Clear out my semaphore</span><a name="l00192"></a>00192    <span class="keywordflow">while</span>( !sem.<a class="code" href="classSemaphore.html#a2">Get</a>(0) );<a name="l00193"></a>00193 <a name="l00194"></a>00194    <span class="comment">// Send the serial number range</span><a name="l00195"></a>00195    recvCS = 79;<a name="l00196"></a>00196    <span class="keywordflow">if</span>( <a class="code" href="classLSS.html#b3">Xmit</a>( 74, low ) ) <span class="keywordflow">return</span> 0;<a name="l00197"></a>00197    <span class="keywordflow">if</span>( <a class="code" href="classLSS.html#b3">Xmit</a>( 75, high ) ) <span class="keywordflow">return</span> 0;<a name="l00198"></a>00198 <a name="l00199"></a>00199    <span class="comment">// Wait for any amplifiers in this range to respond.</span><a name="l00200"></a>00200    <span class="keyword">const</span> <a class="code" href="classError.html">Error</a> *err;<a name="l00201"></a>00201    <span class="keywordtype">int</span> ct = 0;<a name="l00202"></a>00202 <a name="l00203"></a>00203    <span class="keywordflow">while</span>( 1 )<a name="l00204"></a>00204    {<a name="l00205"></a>00205       err = sem.<a class="code" href="classSemaphore.html#a2">Get</a>( timeout );<a name="l00206"></a>00206       <span class="keywordflow">if</span>( err )<a name="l00207"></a>00207     <span class="keywordflow">break</span>;<a name="l00208"></a>00208       ct++;<a name="l00209"></a>00209    }<a name="l00210"></a>00210 <a name="l00211"></a>00211    recvCS = 0;<a name="l00212"></a>00212    <span class="keywordflow">if</span>( !ct ) <span class="keywordflow">return</span> 0;<a name="l00213"></a>00213 <a name="l00214"></a>00214    <span class="keywordflow">if</span>( low == high )<a name="l00215"></a>00215    {<a name="l00216"></a>00216       <span class="keywordflow">if</span>( tot &lt; max )<a name="l00217"></a>00217     serial[tot++] = low;<a name="l00218"></a>00218       <span class="keywordflow">return</span> 1;<a name="l00219"></a>00219    }<a name="l00220"></a>00220 <a name="l00221"></a>00221    <a class="code" href="CML__Utils_8h.html#a10">uint32</a> mid = low + (high-low)/2;<a name="l00222"></a>00222 <a name="l00223"></a>00223    <span class="keywordflow">return</span> <a class="code" href="classLSS.html#b1">FindAmpSerial</a>( low, mid ) + <a name="l00224"></a>00224       <a class="code" href="classLSS.html#b1">FindAmpSerial</a>( mid+1, high );<a name="l00225"></a>00225 }<a name="l00226"></a>00226 <a name="l00227"></a>00227 <span class="comment">/***************************************************************************/</span><span class="comment"></span><a name="l00228"></a>00228 <span class="comment">/**</span><a name="l00229"></a>00229 <span class="comment">  Transmit a LSS CAN frame </span><a name="l00230"></a>00230 <span class="comment">  @param cs The command specifier for this frame.</span><a name="l00231"></a>00231 <span class="comment">  @param data The data passed with the frame.</span><a name="l00232"></a>00232 <span class="comment">  */</span><a name="l00233"></a>00233 <span class="comment">/***************************************************************************/</span><a name="l00234"></a><a class="code" href="classLSS.html#b3">00234</a> <span class="keyword">const</span> <a class="code" href="classError.html">Error</a> *<a class="code" href="classLSS.html#b3">LSS::Xmit</a>( <a class="code" href="CML__Utils_8h.html#a2">byte</a> cs, <a class="code" href="CML__Utils_8h.html#a10">uint32</a> data )<a name="l00235"></a>00235 {<a name="l00236"></a>00236    <a class="code" href="structCanFrame.html">CanFrame</a> frame;<a name="l00237"></a>00237    frame.<a class="code" href="structCanFrame.html#o1">id</a> = 2021;<a name="l00238"></a>00238    frame.<a class="code" href="structCanFrame.html#o0">type</a> = <a class="code" href="CML__Can_8h.html#a3a0">CAN_FRAME_DATA</a>;<a name="l00239"></a>00239    frame.<a class="code" href="structCanFrame.html#o2">length</a> = 8;<a name="l00240"></a>00240    frame.<a class="code" href="structCanFrame.html#o3">data</a>[0] = cs;<a name="l00241"></a>00241    frame.<a class="code" href="structCanFrame.html#o3">data</a>[1] = <a class="code" href="CML__Utils_8h.html#a0">ByteCast</a>(data);<a name="l00242"></a>00242    frame.<a class="code" href="structCanFrame.html#o3">data</a>[2] = <a class="code" href="CML__Utils_8h.html#a0">ByteCast</a>(data&gt;&gt;8);<a name="l00243"></a>00243    frame.<a class="code" href="structCanFrame.html#o3">data</a>[3] = <a class="code" href="CML__Utils_8h.html#a0">ByteCast</a>(data&gt;&gt;16);<a name="l00244"></a>00244    frame.<a class="code" href="structCanFrame.html#o3">data</a>[4] = <a class="code" href="CML__Utils_8h.html#a0">ByteCast</a>(data&gt;&gt;24);<a name="l00245"></a>00245    frame.<a class="code" href="structCanFrame.html#o3">data</a>[5] = 0;<a name="l00246"></a>00246    frame.<a class="code" href="structCanFrame.html#o3">data</a>[6] = 0;<a name="l00247"></a>00247    frame.<a class="code" href="structCanFrame.html#o3">data</a>[7] = 0;<a name="l00248"></a>00248 <a name="l00249"></a>00249    <span class="keywordflow">return</span> <a class="code" href="classReceiver.html#p0">co</a>-&gt;<a class="code" href="classCanOpen.html#a5">Xmit</a>( frame );<a name="l00250"></a>00250 }<a name="l00251"></a>00251 </pre></div><hr><address style="align: right;"><small>Copley Motion Library, Copyright (c) 2002-2003<a href="http://www.copleycontrols.com"><img src="CCC_logo.gif" alt="Copley Controls Corp." align="middle" border=0 ></a></small></address></body></html>

⌨️ 快捷键说明

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