I'm trying to pass three parameters to my write() function:
write(fd, "C,1,1\r\n", 7);
This works fine. But I would like to take a parameter and pass it to the command portion to make it dynamic:
write(fd, N, 4);
I'm not familiar with c++ types, but it keeps asking for a type of "const void*" I've been able to convert my variable, N, to a couple different formats hoping one would be easier to convert. This is what I have tried:
const fmx::FixPt& outValue = dataVect.AtAsNumber(3);
const double N = outValue.AsLong();
double N = outValue.AsLong();
So double and const double(*which might be pretty much the same thing... I don't know c++ very well)
I could also leave it as just:
const fmx::FixPt& outValue = dataVect.AtAsNumber(3);
write(fd, outValue, 4);
but I thought asking everyone how to convert a double would be much better than trying to explain or figure out something as unique as type const fmx::FixPt&...
*I also tried:
write(fd, &N, 4);
which only gets rid of my error, but still doesn't work.
So, is it even possible to convert to a type of "const void*"?
Thank you very much!
Here is code:
const fmx::FixPt& outValue = dataVect.AtAsNumber(3);
double N = outValue.AsLong();
int fd;
struct termios options;
fd=open("/dev/tty.KeySerial1", O_RDWR | O_NOCTTY | O_NDELAY);
fcntl(fd, F_SETFL, 0);
tcgetattr(fd,&options);
options.c_ispeed=57600;
options.c_ospeed=57600;
options.c_cflag |= (CLOCAL | CREAD);
options.c_lflag &= ~(ICANON | ECHO | ECHOE | ISIG);
options.c_cflag &= ~CSTOPB;
options.c_lflag &= ~ECHO;
options.c_oflag &= ~ECHO;
options.c_oflag &= ~OPOST;
options.c_cflag |= CS8;
options.c_cflag |= CRTSCTS;
options.c_cc[VMIN] = 0;
options.c_cc[VTIME] =10;
tcflush(fd, TCIFLUSH);
tcsetattr(fd,TCSANOW,&options);
if( tempText->Assign("2"), *tempText == direction ) {
write(fd, "C,1,2\r\n", 7);//Direction
}else{
write(fd, "C,1,1\r\n", 7);//Direction
}
if( tempText->Assign("1"), *tempText == speed ) {
write(fd, "C,2,1\r\n", 7);//Speed
} else if( tempText->Assign("2"), *tempText == speed ) {
write(fd, "C,2,2\r\n", 7);//Speed
} else if( tempText->Assign("3"), *tempText == speed ) {
write(fd, "C,2,3\r\n", 7);//Speed
} else if( tempText->Assign("4"), *tempText == speed ) {
write(fd, "C,2,4\r\n", 7);//Speed
} else if( tempText->Assign("5"), *tempText == speed ) {
write(fd, "C,2,5\r\n", 7);//Speed
} else if( tempText->Assign("6"), *tempText == speed ) {
write(fd, "C,2,6\r\n", 7);//Speed
} else if( tempText->Assign("7"), *tempText == speed ) {
write(fd, "C,2,7\r\n", 7);//Speed
} else if( tempText->Assign("8"), *tempText == speed ) {
write(fd, "C,2,8\r\n", 7);//Speed
} else if( tempText->Assign("9"), *tempText == speed ) {
write(fd, "C,2,9\r\n", 7);//Speed
} else if( tempText->Assign("10"), *tempText == speed ) {
write(fd, "C,2,10\r\n", 8);//Speed
} else if( tempText->Assign("11"), *tempText == speed ) {
write(fd, "C,2,11\r\n", 8);//Speed
} else if( tempText->Assign("12"), *tempText == speed ) {
write(fd, "C,2,12\r\n", 8);//Speed
} else if( tempText->Assign("13"), *tempText == speed ) {
write(fd, "C,2,13\r\n", 8);//Speed
} else if( tempText->Assign("14"), *tempText == speed ) {
write(fd, "C,2,14\r\n", 8);//Speed
} else if( tempText->Assign("15"), *tempText == speed ) {
write(fd, "C,2,15\r\n", 8);//Speed
} else if( tempText->Assign("16"), *tempText == speed ) {
write(fd, "C,2,16\r\n", 8);//Speed
} else if( tempText->Assign("17"), *tempText == speed ) {
write(fd, "C,2,17\r\n", 8);//Speed
}
if(tempText->Assign("1"), *tempText == length){
write(fd, "C,3,", 4);
write(fd, "1", 1);
write(fd, "\r\n", 2);
} else if(tempText->Assign("2"), *tempText == length){
write(fd, "C,3,", 4);
write(fd, "10", 2);
write(fd, "\r\n", 2);
} else if(tempText->Assign("3"), *tempText == length){
write(fd, "C,3,", 4);
write(fd, "100", 3);
write(fd, "\r\n", 2);
} else if(tempText->Assign("4"), *tempText == length){
write(fd, "C,3,", 4);
write(fd, N, 4);
write(fd, "\r\n", 2);
}
close(fd);
error: cannot convert 'double' to 'const void*' for argument '2' to 'ssize_t write(int, const void*, size_t)'