15#include <yarp/dev/CanBusInterface.h>
16#include <yarp/os/Bottle.h>
19using namespace yarp::os;
23 handle =
new PLXCAN_HANDLE;
34 printf(
"PlxCan::canSetBaudRate not yet implemented\n");
40 printf(
"PlxCan::canSetBaudRate not yet implemented\n");
47 int res=plxCanIdAdd(*handle,
id);
48 if (res!=NTCAN_SUCCESS)
56 printf(
"PlxCan::canIdDelete not yet implemented\n");
67 PLXCAN_MSG *tmp=
reinterpret_cast<PLXCAN_MSG *
>(msgs[0].getPointer());
69 res=plxCanRead(*handle, tmp, read);
71 res=plxCanTake(*handle, tmp, read);
73 if(res!=NTCAN_SUCCESS)
87 CanBuffer &buffer=
const_cast<CanBuffer &
>(msgs);
88 const PLXCAN_MSG *tmp=
reinterpret_cast<const PLXCAN_MSG *
>(buffer[0].getPointer());
91 res=plxCanWrite(*handle,
const_cast<PLXCAN_MSG *
>(tmp), sent);
93 res=plxCanSend(*handle,
const_cast<PLXCAN_MSG *
>(tmp), sent);
95 if (res!=NTCAN_SUCCESS)
109 netId=par.check(
"CanDeviceNum", Value(-1),
"numeric identifier of the can device").asInt32();
110 if (netId == -1) netId=par.check(
"canDeviceNum", Value(-1),
"numeric identifier of the can device").asInt32();
112 txTimeout=par.check(
"CanTxTimeout", Value(0),
"timeout on transmission [ms]").asInt32();
113 if (txTimeout == 0) txTimeout=par.check(
"canTxTimeout", Value(0),
"timeout on transmission [ms]").asInt32();
115 rxTimeout=par.check(
"CanRxTimeout", Value(0),
"timeout on receive when calling blocking read [ms]").asInt32() ;
116 if (rxTimeout == 0) rxTimeout=par.check(
"canRxTimeout", Value(0),
"timeout on receive when calling blocking read [ms]").asInt32() ;
118 int res = plxCanOpen (netId, txQueueSize, rxQueueSize, txTimeout, rxTimeout, handle);
119 if (res != NTCAN_SUCCESS)
121 fprintf(stderr,
"PlxCan::open() returning false\n");
134 res=plxCanClose (*handle);
136 if (res!=NTCAN_SUCCESS)
147 if (plxCanErrors(*handle, &
error)!=NTCAN_SUCCESS)
150 err.busoff=
error.busoff;
151 err.txCanErrors=
error.errors;
152 err.rxCanErrors=
error.canOvr;
153 err.rxCanFifoOvr=
error.canOvr;
154 err.txCanFifoOvr=
error.inputBuffOvr;
155 err.rxBufferOvr=
error.inputBuffOvr;
156 err.txBufferOvr=
error.outputBuffOvr;
virtual bool canRead(CanBuffer &msgs, unsigned int size, unsigned int *read, bool wait=false)
virtual bool open(yarp::os::Searchable &par)
virtual bool canSetBaudRate(unsigned int rate)
virtual bool canIdDelete(unsigned int id)
virtual bool canGetErrors(CanErrors &errs)
virtual bool canIdAdd(unsigned int id)
virtual bool canGetBaudRate(unsigned int *rate)
virtual bool canWrite(const CanBuffer &msgs, unsigned int size, unsigned int *sent, bool wait=false)