c++ - Giving device address SRF10 -
i have problem program. don't know method or function (i have problem name) "measurementsensor" good. wrote first code give address device.
class i2cconnection{ private: int fd; char* filename; int flag; int isopen; int currentaddress; public: i2cconnection(char *name,int flag = o_rdwr){ this->filename = name; this->isopen = 0; } int send(char* buf[],unsigned int size){ if((write(this->fd,buf,size)) < size){ printf("error writing i2c slave\n"); }else{ return(size); } } int recive(char* buf[],unsigned int size){ if((read(this->fd,buf,size)) <size){ printf("error writing i2c slave\n"); }else{ return(size); } } int connectto(int address){ if(ioctl(this->fd,i2c_slave,address) < 0){ printf("unable bus access talk slave\n"); return(0); }else{ this->currentaddress = address; return(1); } } int openconnection(){ if((fd = open(filename, o_rdwr)) < 0){ printf("failed open i2c port\n"); this->isopen = 0; }else{ this->isopen = 1; } return(this->isopen) } int closeconnection(){ if(close(fd)==0){ this->isopen = 0; }else{ this->isopen = 1; } return(!this->isopen); } ~i2cconnection(){ if ( this->isopen){ closeconnection(); } } } class sonicsensor{ private: int address; unsigned int units; i2cconnection* conn; unsigned int value; public: sonicsensor(i2cconnection* c,int addr){ this->address = addr; this->conn = c; } void changeunits(int u){ this->units = u; } unsigned int measurementsensor(char* buf[]){ buf[0] = 0; buf[1] = 0x51; c.send(buf,2); buf[0] = 0xa0; c.send(buf,1); buf[0] = 0xaa; c.send(buf,1); buf[0] = 0xa5; c.send(buf,1); buf[0] = 0xf2; c.send(buf,1); } ~sonicsensor(){ } };
the problem error: invalid conversion int char*. can't found solved error.
you should working arrays of bytes, not arrays of pointers-to-bytes. unless target platform uses 8-bit pointers, end writing pointer-sized values i2c device instead of single bytes intended. on 32-bit system, first command instead of sending 2 bytes (00
, 51
) send 8 bytes (00 00 00 00
, 00 00 00 51
).
your i2cconnection
methods send
, receive
should declared as:
int send(const char* buf, unsigned int size) int receive(char* buf, unsigned int size)
likewise, sonicsensor
class measurementsensor
method not appear need input argument, done as:
unsigned int measurementsensor() { char buf[2]; ...
c++
No comments:
Post a Comment