修复连续采集时没有时间间隔导致通讯失败从而导致无有法正常连续采集的问题 修改如下
This commit is contained in:
120
myis11/project/is3/testmain.cpp
Normal file
120
myis11/project/is3/testmain.cpp
Normal file
@ -0,0 +1,120 @@
|
||||
/**
|
||||
******************************************************************************
|
||||
* @file : testmain.cpp
|
||||
* @author : xin
|
||||
* @brief : None
|
||||
* @attention : None
|
||||
* @date : 2024/8/14
|
||||
******************************************************************************
|
||||
*/
|
||||
#include "IS3_INST.h"
|
||||
#include "CSerialPort/SerialPort.h"
|
||||
#include "CSerialPort/SerialPortInfo.h"
|
||||
#include "stdio.h"
|
||||
#include "vector"
|
||||
using namespace itas109;
|
||||
CSerialPort *serialport;
|
||||
|
||||
size_t SerialWrite(u_char* data,size_t lenth)
|
||||
{
|
||||
printf("write data:");
|
||||
for (int i = 0; i < lenth; ++i) {
|
||||
printf("%02x ",data[i]);
|
||||
}
|
||||
printf("\n");
|
||||
fflush(stdout);
|
||||
|
||||
serialport->flushReadBuffers();
|
||||
return serialport->writeData(data,lenth);
|
||||
|
||||
|
||||
|
||||
}
|
||||
size_t SerailRead(u_char* data,size_t lenth)
|
||||
{
|
||||
|
||||
|
||||
size_t lenthread=serialport->readData(data,lenth);
|
||||
// printf("read data:");
|
||||
// for (int i = 0; i < lenthread; ++i)
|
||||
// {
|
||||
// printf("%02x ",data[i]);
|
||||
// }
|
||||
// printf("\n");
|
||||
|
||||
|
||||
|
||||
// printf("read data: %d\n",lenthread);
|
||||
// int indexnow=serialport->getReadBufferUsedLen();
|
||||
|
||||
// printf("read data index: %d\n",indexnow);
|
||||
//fflush(stdout);
|
||||
|
||||
return lenthread;
|
||||
}
|
||||
|
||||
|
||||
|
||||
int main() {
|
||||
serialport = new CSerialPort();
|
||||
//获取串口列表
|
||||
|
||||
std::vector<SerialPortInfo> portNameList = CSerialPortInfo::availablePortInfos();
|
||||
for (int i = 0; i < portNameList.size(); ++i) {
|
||||
printf("portName:%s\n",portNameList[i].portName);
|
||||
}
|
||||
std::string portname="COM20";
|
||||
serialport->init(portname.c_str(),BaudRate921600 ,ParityNone,DataBits8,StopOne,FlowNone,512*512);
|
||||
serialport->setOperateMode(SynchronousOperate);
|
||||
//serialport->setReadIntervalTimeout(10000);
|
||||
if (serialport->open())
|
||||
{ printf("open success\n");
|
||||
}else {
|
||||
printf("open fail \n may be port: %s is busy or not exist\n",portname.c_str());
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
// IS11SensorInit();
|
||||
printf("Hello World\n");
|
||||
IS3Set_Serial_FUN(SerialWrite,SerailRead);
|
||||
IS3SensorInit();
|
||||
uint16_t *buffforread=new uint16_t[1000];
|
||||
STRsensorinfo_C info= IS3Get_SensorInfo();
|
||||
//输出info
|
||||
printf("--------------------------------------\nSensorName:%s\n",info.SensorName);
|
||||
printf("serialnumber:%s\n",info.serialnumber);
|
||||
printf("maxValue:%d\n",info.maxValue);
|
||||
printf("a1:%f\n",info.a1);
|
||||
printf("a2:%f\n",info.a2);
|
||||
printf("a3:%f\n",info.a3);
|
||||
printf("a4:%f\n",info.a4 );
|
||||
double a[4]={0.0,0.001,1,350};
|
||||
IS3SetWeaveLenthCoeff(a,4);
|
||||
info= IS3Get_SensorInfo();
|
||||
//输出info
|
||||
printf("SensorName:%s\n",info.SensorName);
|
||||
printf("serialnumber:%s\n",info.serialnumber);
|
||||
printf("maxValue:%d\n",info.maxValue);
|
||||
printf("a1:%f\n",info.a1);
|
||||
printf("a2:%f\n",info.a2);
|
||||
printf("a3:%f\n",info.a3);
|
||||
printf("a4:%f\n",info.a4 );
|
||||
|
||||
// IS3OptSnenser(80);
|
||||
while (1) {
|
||||
IS3GetData(buffforread,200);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
//
|
||||
// Created by xin on 2024/8/14.
|
||||
//
|
Reference in New Issue
Block a user