USBポート経由でデータを読み取ろうとしているIMUセンサーがあります。私はubuntu 11.10とEclipse IDEを使用しています。使用される言語は C です。これを行うには、特定のコマンド コードを IMU に送信し、結果を読み取る必要があります。私はすでにこれを行っていますが、私の問題は、無限ループで IMU からデータを読み取る (必要な回数だけデータを読み取る) ときに、書き込み関数 (コマンドを IMU に送信するために使用する) がフリーズすることです。つまり、書き込み関数でプログラムの実行が停止します。
コードは次のとおりです。
int comport = -1; // Handle COM port
struct termios options;
comport = open("/dev/ttyACM0", O_RDWR | O_NOCTTY | O_NDELAY);
fcntl(comport, F_SETFL, 0);
//Get the current options for the port...
tcgetattr(comport, &options);
cfsetispeed(&options, B115200);
cfsetospeed(&options, B115200);
options.c_cflag |= CS8;
options.c_oflag &= ~OPOST; //raw output
//Enable the receiver and set local mode...
options.c_cflag |= (CLOCAL | CREAD);
//Set the new options for the port...
tcsetattr(comport, TCSANOW, &options);
//read compass 0x23
char command[] = {0xF7, 0x23, 0x23};
while(1)
{
bytes_written = write(comport, command, 3);
if(bytes_written == -1)
{
printf("\nsending command to IMU failed!");
//...
}
else if(bytes_written == 3)
{
//sending command OK
bytes_read = read(comport, // Handle
INBUFFER, // Incoming data
12 // Number of bytes to read
);
}
} //end while(1)