get_error.cpp
Go to the documentation of this file.
00001 
00060 #include <utility>
00061 #include <iostream>
00062 #include <iomanip>
00063 #include "ipa_canopen_core/canopen.h"
00064 #include <sstream>
00065 
00066 int main(int argc, char *argv[])
00067 {
00068 
00069     if (argc != 4) {
00070         std::cout << "Arguments:" << std::endl
00071         << "(1) device file" << std::endl
00072         << "(2) CAN deviceID" << std::endl
00073            << "(3) Baud Rate" << std::endl
00074         << "Example: ./get_error /dev/pcan32 12 500K" << std::endl;
00075         return -1;
00076     }
00077 
00078     canopen::NMTmsg.ID = 0;
00079     canopen::NMTmsg.MSGTYPE = 0x00;
00080     canopen::NMTmsg.LEN = 2;
00081 
00082     canopen::syncMsg.ID = 0x80;
00083     canopen::syncMsg.MSGTYPE = 0x00;
00084 
00085     canopen::syncMsg.LEN = 0x00;
00086 
00087     std::string deviceFile = std::string(argv[1]);
00088     canopen::baudRate = std::string(argv[3]);
00089 
00090     if (!canopen::openConnection(deviceFile, canopen::baudRate)){
00091         std::cout << "Cannot open CAN device; aborting." << std::endl;
00092 
00093         exit(EXIT_FAILURE);
00094     }
00095     else{
00096         std::cout << "Connection to CAN bus established" << std::endl;
00097         std::cout << "Baud Rate:" << canopen::baudRate << std::endl;
00098     }
00099 
00100     uint16_t CANid = std::stoi(std::string(argv[2]));
00101 
00102     canopen::devices[ CANid ] = canopen::Device(CANid);
00103     std::this_thread::sleep_for(std::chrono::milliseconds(10));
00104     canopen::sendNMT(CANid, canopen::NMT_START_REMOTE_NODE);
00105     std::this_thread::sleep_for(std::chrono::milliseconds(10));
00106 
00107     std::this_thread::sleep_for(std::chrono::milliseconds(10));
00108 
00109 
00110     std::shared_ptr<TPCANRdMsg> m;
00111 
00112 
00113     canopen::readErrorsRegister(CANid, m);
00114 
00115     /***************************************************************/
00116     //          Manufacturer specific errors register
00117     /***************************************************************/
00118     canopen::readManErrReg(CANid, m);
00119 
00120     /**************************
00121      * Hardware and Software Information
00122     *************************/
00123 
00124     std::vector<uint16_t> vendor_id = canopen::obtainVendorID(CANid, m);
00125     uint16_t rev_number = canopen::obtainRevNr(CANid, m);
00126     std::vector<uint16_t> product_code = canopen::obtainProdCode(CANid, m);
00127     std::vector<char> manufacturer_device_name = canopen::obtainManDevName(CANid,m);
00128     std::vector<char> manufacturer_hw_version =  canopen::obtainManHWVersion(CANid, m);
00129     std::vector<char> manufacturer_sw_version =  canopen::obtainManSWVersion(CANid, m);
00130 
00131         /****
00132          *Printing the data
00133          */
00134 
00135         std::cout << "vendor_id=0x";
00136 
00137         for (auto it : vendor_id)
00138         {
00139            std::cout <<  std::hex << it;
00140         }
00141 
00142         std::cout << std::endl;
00143 
00144         std::cout << "revision_number: "<< std::hex << int(rev_number) << std::dec << std::endl;
00145         std::cout << "device_name:";
00146 
00147         for (auto it : manufacturer_device_name)
00148         {
00149            std::cout << it;
00150         }
00151 
00152         std::cout << std::endl;
00153 
00154         std::cout << "hardware_version:";
00155 
00156         for (auto it : manufacturer_hw_version)
00157         {
00158            std::cout << it;
00159         }
00160 
00161         std::cout << std::endl;
00162 
00163         std::cout << "software_version:";
00164 
00165         for (auto it : manufacturer_sw_version)
00166         {
00167            std::cout << it;
00168         }
00169 
00170         std::cout << std::endl;
00171 
00172 
00173 }


ipa_canopen_core
Author(s): Tobias Sing, Thiago de Freitas
autogenerated on Mon Oct 6 2014 00:59:25