1994 1995 1996 1997 1998 1999 2000 2001 2002 2003 2004 2005 2006 2007 2008 2009 2010 2011 2012 2013 2014 2015 2016 <2017> 2018 2019 2020 2021 2022 2023 2024 | Index | 1994 1995 1996 1997 1998 1999 2000 2001 2002 2003 2004 2005 2006 2007 2008 2009 2010 2011 2012 2013 2014 2015 2016 <2017> 2018 2019 2020 2021 2022 2023 2024 |
<== Date ==> | <== Thread ==> |
---|
Subject: | Problem compiling EPICS ioc with libusb |
From: | Sam de Jong <[email protected]> |
To: | [email protected] |
Date: | Thu, 22 Jun 2017 16:16:47 -0700 |
Hello EPICS tech-talk, I am trying to compile an EPICS IOC with libusb included (I
am on a linux platform running ubuntu 14.04 and EPICS base
3.14-3.14.12.3 ). I created the ioc using makeBaseApp.pl -t example test and was able to run make with no issues. I added the header files for a class I created which interfaces with a usb device (these are included in this email) by adding this line to /testAPP/src/testMain.cpp: #include "DI-2108-P.cpp" when I try to make, I get this output: make -C ./configure install
Do you have any idea what might be causing this issue? I've tried googling around and haven't found anything helpful. Thank you for your assistance, |
#include <bitset> #include <iostream> #include <stdio.h> #include <string.h> #include <sstream> #include <unistd.h> #include <vector> #include </usr/include/libusb-1.0/libusb.h> #include "DI-2108-P.h" using namespace std; DI_2108_P::DI_2108_P(){ nChan=1; ranges.resize(nChan); multiplier.resize(nChan); divisor.resize(nChan); } DI_2108_P::DI_2108_P(int nChannels){ nChan=nChannels; ranges.resize(nChan); multiplier.resize(nChan); divisor.resize(nChan); } void DI_2108_P::Initialize(){ libusb_device **devs; //pointer to pointer of device, used to retrieve a list of devices //libusb_device_handle *dev_handle; //a device handle ctx = NULL; //a libusb session int r; //for return values ssize_t cnt; //holding number of devices in list r = libusb_init(&ctx); //initialize the library for the session we just declared if(r < 0) { cout<<"Init Error "<<r<<endl; //there was an error //return error; } libusb_set_debug(ctx, 3); //set verbosity level to 3, as suggested in the documentation cnt = libusb_get_device_list(ctx, &devs); //get the list of devices if(cnt < 0) { cout<<"Get Device Error"<<endl; //there was an error //return error; } cout<<cnt<<" Devices in list."<<endl; dev_handle = libusb_open_device_with_vid_pid(ctx, vID, pID); //these are vendorID and productID I found for my usb device if(dev_handle == NULL) cout<<"Cannot open device"<<endl; else cout<<"Device Opened"<<endl; libusb_free_device_list(devs, 1); //free the list, unref the devices in it if(libusb_kernel_driver_active(dev_handle, 0) == 1) { //find out if kernel driver is attached cout<<"Kernel Driver Active"<<endl; if(libusb_detach_kernel_driver(dev_handle, 0) == 0) //detach it cout<<"Kernel Driver Detached!"<<endl; } r = libusb_claim_interface(dev_handle, 0); //claim interface 0 (the first) of device (mine had jsut 1) if(r < 0) { cout<<"Cannot Claim Interface"<<endl; } cout<<"Claimed Interface"<<endl; } void DI_2108_P::reset(){ libusb_reset_device(dev_handle); } void DI_2108_P::close(){ int r; //libusb_context *ctx = NULL; //a libusb session r = libusb_release_interface(dev_handle, 0); //release the claimed interface if(r!=0) { cout<<"Cannot Release Interface"<<endl; return; } cout<<"Released Interface"<<endl; libusb_close(dev_handle); //close the device we opened libusb_exit(ctx); //needs to be called to end the } string DI_2108_P::sendMessage(string message){ //libusb_context *ctx = NULL; //a libusb session int r; //for return values string error = "error"; message = message+"\r"; unsigned char recieved[1000000]; unsigned char sent[50]; strcpy((char*) sent, message.c_str()); int actual; //used to find out how many bytes were written //cout<<"Data->"<<message<<"<-"<<endl; //just to see the data we want to write : abcd cout<<"Writing Data..."<<endl; r = libusb_bulk_transfer(dev_handle, (1 | LIBUSB_ENDPOINT_OUT), sent, sizeof(sent), &actual, 0); //my device's out endpoint was 1, found with trial- the device had 2 endpoints: 2 and 129 if(r == 0 && actual == sizeof(sent)){ //we wrote the 4 bytes successfully cout<<"Writing Successful!"<<endl; sleep(0.1); r = libusb_bulk_transfer(dev_handle, (1 | LIBUSB_ENDPOINT_IN), recieved, sizeof(recieved), &actual, 0); cout<<actual<<endl; cout<<libusb_strerror((libusb_error)r)<<endl; }else cout<<"Write Error"<<endl; std::string sName(reinterpret_cast<char*>(recieved)); return sName; } void DI_2108_P::setNChannels(int nChannels){ nChan = nChannels; ranges.resize(nChan); multiplier.resize(nChan); divisor.resize(nChan); } void DI_2108_P::setRange(int channel, int range){ if(channel>nChan) return; if(range>4) return; ranges[channel] = range; if(range==0){ multiplier[channel]=10; divisor[channel] = 1./32768; }else if(range==1){ multiplier[channel]=5; divisor[channel] = 1./32768; }else if(range==2){ multiplier[channel]=2.5; divisor[channel] = 1./32768; }else if(range==3){ multiplier[channel]=10; divisor[channel] = 1./65536; }else if(range==4){ multiplier[channel]=5; divisor[channel] = 1./65536; } } void DI_2108_P::startScan(){ this->sendMessage("ps 1"); stringstream ss; for(int i=0; i<nChan; i++){ ss<<i; string slistString = "slist "+ss.str()+" ";; ss.str(""); int b=ranges[i]<<8; int channelMask = i+b; ss<<channelMask; slistString = slistString+ss.str(); ss.str(""); this->sendMessage(slistString); cout<<slistString<<endl; } this->sendMessage("start 0"); } void DI_2108_P::stopScan(){ this->sendMessage("stop 0"); } vector<double> DI_2108_P::getReadings(){ vector<double> readings; readings.resize(nChan); int r; //for return values unsigned char recieved[1000000]; int actual; //used to find out how many bytes were written r = libusb_bulk_transfer(dev_handle, (1 | LIBUSB_ENDPOINT_IN), recieved, 1000000, &actual, 0); for(int i=0; i<nChan; i++){ short combined = (recieved[2*i+1] << 8 ) | (recieved[2*i] & 0xff); double add = 0; if(ranges[i]>2) add=multiplier[i]/2; readings[i] = multiplier[i]*(double)combined*divisor[i]+add; } return readings; }
#include <bitset> #include <iostream> #include <stdio.h> #include <string.h> #include <sstream> #include <unistd.h> #include <vector> #include </usr/include/libusb-1.0/libusb.h> //#include "DI-2108-P.cpp" using namespace std; class DI_2108_P{ public: DI_2108_P(); DI_2108_P(int nChannels); // DI_2108_P(int vendorID, int productID); void Initialize(); void close(); string sendMessage(string message); void startScan(); void stopScan(); void reset(); vector<double> getReadings(); void setNChannels(int nChannels); void setRange(int channel, int range); private: static const int vID = 0x0683; static const int pID = 0x2109; libusb_context *ctx; libusb_device_handle *dev_handle; vector<int> ranges; vector<double> multiplier; vector<double> divisor; int nChan; };