can_8cpp-source.html
来自「美国COPLEY驱动器,程序开发工具之一.」· HTML 代码 · 共 168 行 · 第 1/2 页
HTML
168 行
<!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: Can.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 Page</a> | <a class="qindex" href="hierarchy.html">Class Hierarchy</a> | <a class="qindex" href="classes.html">Alphabetical List</a> | <a class="qindex" href="annotated.html">Class List</a> | <a class="qindex" href="dirs.html">Directories</a> | <a class="qindex" href="files.html">File List</a> | <a class="qindex" href="functions.html">Class Members</a> | <a class="qindex" href="globals.html">File Members</a></div><div class="nav"><a class="el" href="dir_000000.html">c</a></div><h1>Can.cpp</h1><a href="Can_8cpp.html">Go to the documentation of this file.</a><div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 <span class="comment">/************************************************************/</span><a name="l00002"></a>00002 <span class="comment">/* */</span><a name="l00003"></a>00003 <span class="comment">/* Copley Motion Libraries */</span><a name="l00004"></a>00004 <span class="comment">/* */</span><a name="l00005"></a>00005 <span class="comment">/* Author: Stephen Glow */</span><a name="l00006"></a>00006 <span class="comment">/* */</span><a name="l00007"></a>00007 <span class="comment">/* Copyright (c) 2002-2005 Copley Controls Corp. */</span><a name="l00008"></a>00008 <span class="comment">/* http://www.copleycontrols.com */</span><a name="l00009"></a>00009 <span class="comment">/* */</span><a name="l00010"></a>00010 <span class="comment">/************************************************************/</span><a name="l00011"></a>00011 <span class="comment"></span><a name="l00012"></a>00012 <span class="comment">/**</span><a name="l00013"></a>00013 <span class="comment">\file</span><a name="l00014"></a>00014 <span class="comment">This file handles the initialization of the static variables (error codes)</span><a name="l00015"></a>00015 <span class="comment">used by the CanError and CanInterface classes.</span><a name="l00016"></a>00016 <span class="comment">*/</span><a name="l00017"></a>00017 <a name="l00018"></a>00018 <span class="preprocessor">#include "<a class="code" href="CML_8h.html">CML.h</a>"</span><a name="l00019"></a>00019 <a name="l00020"></a>00020 <a class="code" href="CML__Settings_8h.html#a13">CML_NAMESPACE_USE</a>();<a name="l00021"></a>00021 <a name="l00022"></a>00022 <a class="code" href="CML__Error_8h.html#a0">CML_NEW_ERROR</a>( <a class="code" href="classCanError.html">CanError</a>, BadPortName, <span class="stringliteral">"The CAN port name specified is unknown."</span> );<a name="l00023"></a>00023 <a class="code" href="CML__Error_8h.html#a0">CML_NEW_ERROR</a>( <a class="code" href="classCanError.html">CanError</a>, NotOpen, <span class="stringliteral">"The CAN interface is not open."</span> );<a name="l00024"></a>00024 <a class="code" href="CML__Error_8h.html#a0">CML_NEW_ERROR</a>( <a class="code" href="classCanError.html">CanError</a>, AlreadyOpen, <span class="stringliteral">"Attempt to open an interface that's already open."</span> );<a name="l00025"></a>00025 <a class="code" href="CML__Error_8h.html#a0">CML_NEW_ERROR</a>( <a class="code" href="classCanError.html">CanError</a>, BadParam, <span class="stringliteral">"One of the passed parameters is unacceptable."</span> );<a name="l00026"></a>00026 <a class="code" href="CML__Error_8h.html#a0">CML_NEW_ERROR</a>( <a class="code" href="classCanError.html">CanError</a>, Driver, <span class="stringliteral">"Generic CAN driver level error."</span> );<a name="l00027"></a>00027 <a class="code" href="CML__Error_8h.html#a0">CML_NEW_ERROR</a>( <a class="code" href="classCanError.html">CanError</a>, BadBaud, <span class="stringliteral">"Illegal CAN baud rate specified."</span> );<a name="l00028"></a>00028 <a class="code" href="CML__Error_8h.html#a0">CML_NEW_ERROR</a>( <a class="code" href="classCanError.html">CanError</a>, Timeout, <span class="stringliteral">"Timeout waiting on read/write."</span> );<a name="l00029"></a>00029 <a class="code" href="CML__Error_8h.html#a0">CML_NEW_ERROR</a>( <a class="code" href="classCanError.html">CanError</a>, Overflow, <span class="stringliteral">"CAN bus data overflow."</span> );<a name="l00030"></a>00030 <a class="code" href="CML__Error_8h.html#a0">CML_NEW_ERROR</a>( <a class="code" href="classCanError.html">CanError</a>, BusOff, <span class="stringliteral">"CAN bus off."</span> );<a name="l00031"></a>00031 <a class="code" href="CML__Error_8h.html#a0">CML_NEW_ERROR</a>( <a class="code" href="classCanError.html">CanError</a>, InvalidID, <span class="stringliteral">"The CAN ID is not valid."</span> );<a name="l00032"></a>00032 <a class="code" href="CML__Error_8h.html#a0">CML_NEW_ERROR</a>( <a class="code" href="classCanError.html">CanError</a>, Unknown, <span class="stringliteral">"Unknown / unspecified CAN error."</span> );<a name="l00033"></a>00033 <a class="code" href="CML__Error_8h.html#a0">CML_NEW_ERROR</a>( <a class="code" href="classCanError.html">CanError</a>, NoDriver, <span class="stringliteral">"Unable to open CAN driver, or missing dll file"</span> );<a name="l00034"></a>00034 <a class="code" href="CML__Error_8h.html#a0">CML_NEW_ERROR</a>( <a class="code" href="classCanError.html">CanError</a>, Alloc, <span class="stringliteral">"CAN driver memory allocation error"</span> );<a name="l00035"></a>00035 <a class="code" href="CML__Error_8h.html#a0">CML_NEW_ERROR</a>( <a class="code" href="classCanError.html">CanError</a>, Permission, <span class="stringliteral">"Permission error opening CAN port"</span> );<a name="l00036"></a>00036 <a name="l00037"></a>00037 <span class="comment">/***************************************************************************/</span><span class="comment"></span><a name="l00038"></a>00038 <span class="comment">/**</span><a name="l00039"></a>00039 <span class="comment">Receive the next CAN frame. This is the public function used to read CAN</span><a name="l00040"></a>00040 <span class="comment">messages from the network.</span><a name="l00041"></a>00041 <span class="comment"></span><a name="l00042"></a>00042 <span class="comment">@param frame A reference to the frame object that will be filled by the read.</span><a name="l00043"></a>00043 <span class="comment">@param timeout The timeout (ms) to wait for the frame. A timeout of 0 will</span><a name="l00044"></a>00044 <span class="comment"> return immediately if no data is available. A timeout of < 0 will </span><a name="l00045"></a>00045 <span class="comment"> wait forever.</span><a name="l00046"></a>00046 <span class="comment">@return A pointer to an error object, or NULL on success.</span><a name="l00047"></a>00047 <span class="comment">*/</span><a name="l00048"></a>00048 <span class="comment">/***************************************************************************/</span><a name="l00049"></a><a class="code" href="classCanInterface.html#a7">00049</a> <span class="keyword">const</span> <a class="code" href="classError.html">Error</a> *<a class="code" href="classCanInterface.html#a7">CanInterface::Recv</a>( <a class="code" href="structCanFrame.html">CanFrame</a> &frame, <a class="code" href="CML__Utils_8h.html#a9">int32</a> timeout )<a name="l00050"></a>00050 {<a name="l00051"></a>00051 <span class="keyword">const</span> <a class="code" href="classError.html">Error</a> *err = <a class="code" href="classCanInterface.html#b0">RecvFrame</a>( frame, timeout );<a name="l00052"></a>00052 <span class="keywordflow">if</span>( !err ) <a name="l00053"></a>00053 <a class="code" href="CML_8h.html#a0">cml</a>.<a class="code" href="classCopleyMotionLibrary.html#a11">LogCAN</a>( <span class="keyword">true</span>, frame );<a name="l00054"></a>00054 <span class="keywordflow">return</span> err;<a name="l00055"></a>00055 }<a name="l00056"></a>00056 <a name="l00057"></a>00057 <span class="comment">/***************************************************************************/</span><span class="comment"></span><a name="l00058"></a>00058 <span class="comment">/**</span><a name="l00059"></a>00059 <span class="comment">Write a CAN frame to the CAN network.</span><a name="l00060"></a>00060 <span class="comment">@param frame A reference to the frame to write.</span><a name="l00061"></a>00061 <span class="comment">@param timeout The time to wait for the frame to be successfully sent.</span><a name="l00062"></a>00062 <span class="comment"> If the timeout is 0, the frame is written to the output queue and</span><a name="l00063"></a>00063 <span class="comment"> the function returns without waiting for it to be sent. If the </span><a name="l00064"></a>00064 <span class="comment"> timeout is <0 then the function will delay forever.</span><a name="l00065"></a>00065 <span class="comment">@return A pointer to an error object, or NULL on success.</span><a name="l00066"></a>00066 <span class="comment">*/</span><a name="l00067"></a>00067 <span class="comment">/***************************************************************************/</span><a name="l00068"></a><a class="code" href="classCanInterface.html#a8">00068</a> <span class="keyword">const</span> <a class="code" href="classError.html">Error</a> *<a class="code" href="classCanInterface.html#a8">CanInterface::Xmit</a>( <a class="code" href="structCanFrame.html">CanFrame</a> &frame, <a class="code" href="CML__Utils_8h.html#a9">int32</a> timeout )<a name="l00069"></a>00069 {<a name="l00070"></a>00070 <a class="code" href="CML_8h.html#a0">cml</a>.<a class="code" href="classCopleyMotionLibrary.html#a11">LogCAN</a>( <span class="keyword">false</span>, frame );<a name="l00071"></a>00071 <span class="keywordflow">return</span> <a class="code" href="classCanInterface.html#b1">XmitFrame</a>( frame, timeout );<a name="l00072"></a>00072 }<a name="l00073"></a>00073 <a name="l00074"></a>00074 <span class="comment">/***************************************************************************/</span><span class="comment"></span><a name="l00075"></a>00075 <span class="comment">/**</span>
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?