我在控制台应用程序中有以下代码,我使用 TCP/IP 连接连接到扫描设备,在建立连接后,我不断获得扫描测量结果。但我需要用户随时停止测量.
我正在考虑在控制台应用程序本身中完成它。我需要为此使用线程吗?如果用户在扫描进行时停止,我想完成特定扫描并在此之后退出(类似于锁)。我只是在学习 c++ 和 c++/cli ..任何建议都会有所帮助..谢谢
if (sopas.GetScanData(soScan) == true)
{
printf("Continuous Scanning Measurement \n");
processcounter = ProcessScan(soScan,processcounter,gp,Background);
}
进程扫描的这个骨架是
unsigned int ProcessScan(const SLms100Scan& soScan,int iProcessedScanCount,FILE* gp,vector <double> &Background)
{
static unsigned int ulDeg90_index = 0; // Calculated during init phase
static unsigned int ulProcessedScanCounter = 0;
int iDataCount = soScan.aDataChannel16.aFlexArrayData[0].aData.uiFlexArrayLength;
int datalength = soScan.aDataChannel16.aFlexArrayData[0].aData.uiFlexArrayLength;
vector <double> afXvalue(datalength);
vector <double> afYvalue(datalength);
pair<double,double> coord(int a,int b);
vector< pair<double,double>> coordinates;
int aiDataReal[80];
int count;
//Finding the blobs
// Write hex values of data in to the file
int success = 0;
writefile(fname,soScan,success);
if (success != 0)
{
printf("Error in printing the file");
}
blobdetector(soScan, iProcessedScanCount,Background,coordinates);
// Read the hex value for XY co-ordinate calculation
//readfile(fname,aiDataReal,idx,success);
if (success == -1)
printf("Error in reading the file");
//calculation of Polar Coardinates to XY values
findXY(soScan,afXvalue,afYvalue);
//writing the XY values to the file
writefile( wfname_XY,iDataCount,afXvalue,afYvalue,success);
if (success == -1)
printf("Error in printing the file");
plotdata(afXvalue,afYvalue,coordinates,gp,iProcessedScanCount);
if (!coordinates.empty())
{
//sendcoordinates(soScan,coordinates);
writefile( "coordinates",soScan,coordinates);
coordinates.clear();
}
iProcessedScanCount++;
return iProcessedScanCount;
}