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

📄 lss_8cpp-source.html

📁 美国COPLEY驱动器,程序开发工具之一.
💻 HTML
📖 第 1 页 / 共 2 页
字号:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"><html><head><meta http-equiv="Content-Type" content="text/html;charset=iso-8859-1"><title>Copley Motion Library: LSS.cpp Source File</title><link href="doxygen.css" rel="stylesheet" type="text/css"></head><body><!-- Generated by Doxygen 1.4.4 --><div class="qindex"><a class="qindex" href="main.html">Main&nbsp;Page</a> | <a class="qindex" href="hierarchy.html">Class&nbsp;Hierarchy</a> | <a class="qindex" href="classes.html">Alphabetical&nbsp;List</a> | <a class="qindex" href="annotated.html">Class&nbsp;List</a> | <a class="qindex" href="dirs.html">Directories</a> | <a class="qindex" href="files.html">File&nbsp;List</a> | <a class="qindex" href="functions.html">Class&nbsp;Members</a> | <a class="qindex" href="globals.html">File&nbsp;Members</a></div><div class="nav"><a class="el" href="dir_000000.html">c</a></div><h1>LSS.cpp</h1><div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 <span class="preprocessor">#include "<a class="code" href="CML_8h.html">CML.h</a>"</span><a name="l00002"></a>00002 <a name="l00003"></a>00003 <a class="code" href="CML__Settings_8h.html#a13">CML_NAMESPACE_USE</a>();<a name="l00004"></a>00004 <a name="l00005"></a>00005 <span class="comment">/***************************************************************************/</span><span class="comment"></span><a name="l00006"></a>00006 <span class="comment">/**</span><a name="l00007"></a>00007 <span class="comment">  Default constructor for the LSS object.</span><a name="l00008"></a>00008 <span class="comment">  @param co A reference to the CANopen network object over which this </span><a name="l00009"></a>00009 <span class="comment">  protocol will run.</span><a name="l00010"></a>00010 <span class="comment">  */</span><a name="l00011"></a>00011 <span class="comment">/***************************************************************************/</span><a name="l00012"></a><a class="code" href="classLSS.html#a0">00012</a> <a class="code" href="classLSS.html#a0">LSS::LSS</a>( <a class="code" href="classCanOpen.html">CanOpen</a> &amp;co )<a name="l00013"></a>00013 {<a name="l00014"></a>00014    recvCS = 0;<a name="l00015"></a>00015    timeout = 15;<a name="l00016"></a>00016    <a class="code" href="classReceiver.html#a3">Init</a>( co, 2020 );<a name="l00017"></a>00017    <a class="code" href="classReceiver.html#a7">EnableReceiver</a>();<a name="l00018"></a>00018 }<a name="l00019"></a>00019 <a name="l00020"></a>00020 <span class="comment">/***************************************************************************/</span><span class="comment"></span><a name="l00021"></a>00021 <span class="comment">/**</span><a name="l00022"></a>00022 <span class="comment">  Search the CANopen network for Copley amplifiers.  This function uses the</span><a name="l00023"></a>00023 <span class="comment">  CANopen Layer Setting Services (LSS) protocol to find amplifiers</span><a name="l00024"></a>00024 <span class="comment">  on the network.  All Copley amplifiers on the CANopen network can be</span><a name="l00025"></a>00025 <span class="comment">  identified using this protocol, even if they do not have a valid CANopen </span><a name="l00026"></a>00026 <span class="comment">  node ID number configured.</span><a name="l00027"></a>00027 <span class="comment"></span><a name="l00028"></a>00028 <span class="comment">  On return from this function, the passed array will have been filled with</span><a name="l00029"></a>00029 <span class="comment">  the serial numbers of all the amplifiers found.  These serial numbers may</span><a name="l00030"></a>00030 <span class="comment">  then be passed to LSS::SetAmpNodeID to assign a node ID number to the </span><a name="l00031"></a>00031 <span class="comment">  amplifier.</span><a name="l00032"></a>00032 <span class="comment"></span><a name="l00033"></a>00033 <span class="comment">  Note that firmware support for the LSS protocol was added starting with </span><a name="l00034"></a>00034 <span class="comment">  version 4.04.  Any amplifier on the network with earlier firmware will not</span><a name="l00035"></a>00035 <span class="comment">  be discovered using this technique.</span><a name="l00036"></a>00036 <span class="comment"></span><a name="l00037"></a>00037 <span class="comment">  @param max     The maximum number of amplifier serial numbers to be returned.</span><a name="l00038"></a>00038 <span class="comment">  @param serial  An array where the amplifier serial numbers will be returned.</span><a name="l00039"></a>00039 <span class="comment">  This array must be at least max elements long. </span><a name="l00040"></a>00040 <span class="comment"></span><a name="l00041"></a>00041 <span class="comment">  @return The number of amplifiers actually found.  This is not limited to the</span><a name="l00042"></a>00042 <span class="comment">  max parameter value</span><a name="l00043"></a>00043 <span class="comment">  */</span><a name="l00044"></a>00044 <span class="comment">/***************************************************************************/</span><a name="l00045"></a><a class="code" href="classLSS.html#a1">00045</a> <span class="keywordtype">int</span> <a class="code" href="classLSS.html#a1">LSS::FindAmplifiers</a>( <span class="keywordtype">int</span> max, <a class="code" href="CML__Utils_8h.html#a10">uint32</a> serial[] )<a name="l00046"></a>00046 {<a name="l00047"></a>00047    <span class="keyword">const</span> <a class="code" href="classError.html">Error</a> *err;<a name="l00048"></a>00048 <a name="l00049"></a>00049    <span class="comment">// Switch all devices on the network to LSS configure mode</span><a name="l00050"></a>00050    err = <a class="code" href="classLSS.html#b3">Xmit</a>( 4, 1 );<a name="l00051"></a>00051 <a name="l00052"></a>00052    <span class="comment">// Pass the vendor and product codes to search</span><a name="l00053"></a>00053    <span class="keywordflow">if</span>( !err ) err = <a class="code" href="classLSS.html#b3">Xmit</a>( 70, 0xAB );<a name="l00054"></a>00054    <span class="keywordflow">if</span>( !err ) err = <a class="code" href="classLSS.html#b3">Xmit</a>( 71, 0 );<a name="l00055"></a>00055 <a name="l00056"></a>00056    <span class="comment">// Search for any product revision number</span><a name="l00057"></a>00057    <span class="keywordflow">if</span>( !err ) err = <a class="code" href="classLSS.html#b3">Xmit</a>( 72, 0 );<a name="l00058"></a>00058    <span class="keywordflow">if</span>( !err ) err = <a class="code" href="classLSS.html#b3">Xmit</a>( 73, 0xFFFFFFFF );<a name="l00059"></a>00059 <a name="l00060"></a>00060    <span class="keywordflow">if</span>( err ) <span class="keywordflow">return</span> 0;<a name="l00061"></a>00061 <a name="l00062"></a>00062    tot = 0;<a name="l00063"></a>00063    this-&gt;max = max;<a name="l00064"></a>00064    this-&gt;serial = serial;<a name="l00065"></a>00065 <a name="l00066"></a>00066    <span class="keywordflow">return</span> <a class="code" href="classLSS.html#b1">FindAmpSerial</a>( 0, 0xFFFFFFFF );<a name="l00067"></a>00067 }<a name="l00068"></a>00068 <a name="l00069"></a>00069 <span class="comment">/***************************************************************************/</span><span class="comment"></span><a name="l00070"></a>00070 <span class="comment">/**</span><a name="l00071"></a>00071 <span class="comment">  Get the current CANopen node ID of the specified amplifier.</span><a name="l00072"></a>00072 <span class="comment">  @param serial The serial number of the amplifier to query.</span><a name="l00073"></a>00073 <span class="comment">  @param nodeID The node ID will be returned here.</span><a name="l00074"></a>00074 <span class="comment">  @return A pointer to an error object, or NULL on success.</span><a name="l00075"></a>00075 <span class="comment">  */</span><a name="l00076"></a>00076 <span class="comment">/***************************************************************************/</span><a name="l00077"></a><a class="code" href="classLSS.html#a4">00077</a> <span class="keyword">const</span> <a class="code" href="classError.html">Error</a> *<a class="code" href="classLSS.html#a4">LSS::GetAmpNodeID</a>( <a class="code" href="CML__Utils_8h.html#a10">uint32</a> serial, <a class="code" href="CML__Utils_8h.html#a2">byte</a> &amp;nodeID )<a name="l00078"></a>00078 {<a name="l00079"></a>00079    <span class="comment">// Select just the specified amplifier</span><a name="l00080"></a>00080    <span class="keyword">const</span> <a class="code" href="classError.html">Error</a> *err = <a class="code" href="classLSS.html#b0">SelectAmp</a>( serial );<a name="l00081"></a>00081    <span class="keywordflow">if</span>( err ) <span class="keywordflow">return</span> err;<a name="l00082"></a>00082 <a name="l00083"></a>00083    <span class="comment">// Get the node ID</span><a name="l00084"></a>00084    <span class="keywordflow">while</span>( !sem.<a class="code" href="classSemaphore.html#a2">Get</a>(0) );<a name="l00085"></a>00085    recvCS = 94;<a name="l00086"></a>00086    err = <a class="code" href="classLSS.html#b3">Xmit</a>( 94 );<a name="l00087"></a>00087    <span class="keywordflow">if</span>( !err ) err = sem.<a class="code" href="classSemaphore.html#a2">Get</a>( timeout );<a name="l00088"></a>00088    recvCS = 0;<a name="l00089"></a>00089    <span class="keywordflow">if</span>( err ) <span class="keywordflow">return</span> err;<a name="l00090"></a>00090 <a name="l00091"></a>00091    nodeID = recvData &amp; 0xFF;<a name="l00092"></a>00092    <span class="keywordflow">return</span> 0;<a name="l00093"></a>00093 }<a name="l00094"></a>00094 <a name="l00095"></a>00095 <span class="comment">/***************************************************************************/</span><span class="comment"></span><a name="l00096"></a>00096 <span class="comment">/**</span><a name="l00097"></a>00097 <span class="comment">  Set the CANopen node ID of the specified amplifier.</span><a name="l00098"></a>00098 <span class="comment">  @param serial The serial number of the amplifier to update.</span><a name="l00099"></a>00099 <span class="comment">  @param nodeID The CANopen node ID to assign to this amplifier.</span><a name="l00100"></a>00100 <span class="comment">  @return A pointer to an error object, or NULL on success.</span><a name="l00101"></a>00101 <span class="comment">  */</span><a name="l00102"></a>00102 <span class="comment">/***************************************************************************/</span><a name="l00103"></a><a class="code" href="classLSS.html#a5">00103</a> <span class="keyword">const</span> <a class="code" href="classError.html">Error</a> *<a class="code" href="classLSS.html#a5">LSS::SetAmpNodeID</a>( <a class="code" href="CML__Utils_8h.html#a10">uint32</a> serial, <a class="code" href="CML__Utils_8h.html#a2">byte</a> nodeID )<a name="l00104"></a>00104 {<a name="l00105"></a>00105    <span class="keywordflow">if</span>( nodeID &lt; 1 || nodeID &gt; 127 )<a name="l00106"></a>00106       <span class="keywordflow">return</span> &amp;<a class="code" href="classCanOpenError.html#s7">CanOpenError::BadNodeID</a>;<a name="l00107"></a>00107 <a name="l00108"></a>00108    <span class="comment">// Select just the specified amplifier</span><a name="l00109"></a>00109    <span class="keyword">const</span> <a class="code" href="classError.html">Error</a> *err = <a class="code" href="classLSS.html#b0">SelectAmp</a>( serial );<a name="l00110"></a>00110    <span class="keywordflow">if</span>( err ) <span class="keywordflow">return</span> err;<a name="l00111"></a>00111 <a name="l00112"></a>00112    <span class="comment">// Set the node ID</span><a name="l00113"></a>00113    <span class="keywordflow">while</span>( !sem.<a class="code" href="classSemaphore.html#a2">Get</a>(0) );<a name="l00114"></a>00114    recvCS = 17;<a name="l00115"></a>00115    err = <a class="code" href="classLSS.html#b3">Xmit</a>( 17, nodeID );<a name="l00116"></a>00116    <span class="keywordflow">if</span>( !err ) err = sem.<a class="code" href="classSemaphore.html#a2">Get</a>( timeout );<a name="l00117"></a>00117    recvCS = 0;<a name="l00118"></a>00118    <span class="keywordflow">if</span>( err ) <span class="keywordflow">return</span> err;<a name="l00119"></a>00119 <a name="l00120"></a>00120    <span class="keywordflow">if</span>( recvData &amp; 0xFF )<a name="l00121"></a>00121       <span class="keywordflow">return</span> &amp;<a class="code" href="classCanOpenError.html#s7">CanOpenError::BadNodeID</a>;<a name="l00122"></a>00122 <a name="l00123"></a>00123    <span class="comment">// Deselect the amplifier which causes it to start using</span><a name="l00124"></a>00124    <span class="comment">// the new node ID.</span><a name="l00125"></a>00125    <span class="keywordflow">return</span> <a class="code" href="classLSS.html#b3">Xmit</a>( 4, 0 );<a name="l00126"></a>00126 }<a name="l00127"></a>00127 

⌨️ 快捷键说明

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