//--------------------------------------------------------------------------- #include #pragma hdrstop #include "ChartThread.h" #pragma package(smart_init) //--------------------------------------------------------------------------- // Important: Methods and properties of objects in VCL can only be // used in a method called using Synchronize, for example: // // Synchronize(UpdateCaption); // // where UpdateCaption could look like: // // void __fastcall ChartThread::UpdateCaption() // { // Form1->Caption = "Updated in a thread"; // } //--------------------------------------------------------------------------- __fastcall ChartThread::ChartThread(void) : TThread(false) { Priority = tpTimeCritical; } void __fastcall ChartThread::DataChart() { Go2Data data = GO2_NULL; DataContext context; context.memory = NULL; double oriz = -294.91; int i =0; double x; double z; //while(!Terminated) while( i < NUM_PROFILES) { if (Go2System_ReceiveData(Form1->system, RECEIVE_TIMEOUT, &data) == GO2_OK) { for(j = 0; j < Go2Data_ItemCount(data); ++j) { OutputDebugString( IntToStr(j).c_str()); //OutputDebugString( IntToStr(i).c_str()); Go2Data dataItem = Go2Data_ItemAt(data, j); if (Go2Object_Type(dataItem) == GO2_TYPE_PROFILE_DATA) { unsigned int profilePointCount = Go2ProfileData_Width(dataItem); unsigned int profileSizeBytes = profilePointCount * sizeof(short int); //allocate memory if (context.memory == NULL) { context.memory = (short int*)malloc (NUM_PROFILES * profileSizeBytes); // context.memory = (short int*)malloc (2*profileSizeBytes); } context.profileWidth = Go2ProfileData_Width(dataItem); context.xResolution = Go2ProfileData_XResolution(dataItem); context.zResolution = Go2ProfileData_ZResolution(dataItem); context.xOffset = Go2ProfileData_XOffset(dataItem); context.zOffset = Go2ProfileData_ZOffset(dataItem); // memcpy(&context.memory[i * profilePointCount], Go2ProfileData_Ranges(dataItem), profileSizeBytes); memcpy(&context.memory[profilePointCount], Go2ProfileData_Ranges(dataItem), profileSizeBytes); } } Form1->CameraDataChart(&context); /* if ( z <= oriz) { z = 0; } if ( z != 0) {Form1->pointCH->Series[0]->AddXY(xz, z, FloatToStr(x), clRed);} } } }*/ } i++; } free(context.memory); } //--------------------------------------------------------------------------- void __fastcall ChartThread::Execute() { while(!Terminated) { Sleep(1); Synchronize(DataChart); } //Synchronize(DataChart); //---- Place thread code here ---- } //---------------------------------------------------------------------------