本文主要通过mfc建立一个对话框,新建个子线程读取传感器数据,在主线程中添加定时器和chartctrl控件进行动态曲线的绘制。运行效果与传感器自带软件效果如下:
1 使用控制台程序新建传感器接口的配置和数据的读写如下:
将OMD库放入根目录下
代码如下:
// ss.cpp : 定义控制台应用程序的入口点。
//
#include "stdafx.h"
#include <stdio.h>
#include <iostream>
#include <omd/opto.h>
#include <omd/sensorconfig.h>
#include <fstream>
#include<windows.h>
using namespace std;
int main(int argc, char *argv[])
{
OptoDAQ daq;
OptoPorts ports;
OPort* portlist=ports.listPorts(true);
SensorConfig sensor;
sensor.set(sensor_ok,speed_100hz,filter_15hz,mode_raw);
daq.sendConfig(sensor);
if (ports.getLastSize()>0)
{
daq.open(portlist[0]);
while (1)
{
Sleep(1000/100);
if ((daq.getVersion()!=_95) && (daq.getVersion()!=_64)) // It is a 3D sensor
{
OptoPackage pack3D;
ofstream datafile;
datafile.open("datafile.txt",ofstream::app);
int size=daq.read(pack3D,0); // Reading Sensor #0 (up to 16 Sensors)
std::cout<<"x: "<<pack3D.x<<" y: "<<pack3D.y<<" z: "<<pack3D.z<<std::endl;
datafile << "datafile.txt" << pack3D.x << "" << pack3D.y << "" << pack3D.z << endl;
}
else // It is a 6D sensor
{
OptoPackage6D pack6D;
ofstream datafile;
datafile.open("datafile.txt",ofstream::app);
int size=daq.read6D(pack6D,false);
std::cout<<"Fx: "<<pack6D.Fx<<" Fy: "<<pack6D.Fy<<" Fz: "<<pack6D.Fz<<" ";
std::cout<<"Tx: "<<pack6D.Tx<<" Ty: "<<pack6D.Ty<<" Tz: "<<pack6D.Tz<<std::endl;
datafi