static PyObject * i2c_read_reg(PyObject *self, PyObject *args) { /* parameters */ struct as_i2c_device *aDev; uint8_t aReg; uint8_t aData[MAX_DATA_SIZE]; int aSize; int ret; /* Get arguments */ if (!PyArg_ParseTuple(args, "lii", (long *)&aDev, &aReg, &aSize)) { PyErr_SetString(PyExc_IOError, "Wrong parameters."); return NULL; } if (aSize > MAX_DATA_SIZE) { PyErr_SetString(PyExc_IOError, "Size too high"); return NULL; } ret = as_i2c_read_reg(aDev, aReg, aData, aSize); if (ret < 0) { PyErr_SetString(PyExc_IOError, "Can't get slave address"); return NULL; } return Py_BuildValue("s#", (unsigned char *)aData, aSize); }
long AsI2c::readReg(unsigned char aReg, unsigned char *aData, size_t aSize) const { if (mDev != NULL) { return as_i2c_read_reg(mDev, aReg, aData, aSize); } else { std::cerr<<"AsI2c device structure not allocated"<<std::endl; return -1; } }
int ApfI2cWithMd25::readRegisterbyte(struct as_i2c_device *aDev, unsigned char reg, unsigned char *data) { lock(); int ret = 0; //ret = as_i2c_read_reg(fd_, adr, reg, data, 1); //return 0 on success, -1 on write error (\e reg byte), -2 on read error. ret = as_i2c_read_reg(aDev, reg, data, 1); if (ret < 0) { //errorCount_++; if (ret == -1) std::cout << "as_i2c_read_reg_byte: reg " << (int) reg << " WRITE error!" << std::endl; if (ret == -2) std::cout << "as_i2c_read_reg_byte: reg " << (int) reg << " READ error!" << std::endl; exit(1); } else { //errorCount_ = 0; } unlock(); return ret; }