BOOL CServiceDeviceInfoFactory::EnumEntry(PNDASUSER_DEVICE_ENUM_ENTRY lpEnumEntry) { CDeviceInfo *pObj = NULL; NDAS_DEVICE_ID deviceID; BOOL bSuccess = ::ConvertStringIdToRealId( lpEnumEntry->szDeviceStringId, &deviceID); if ( !bSuccess ) { // TODO : ERROR : Invalid string id return TRUE; // Skip current device } pObj = new CDeviceInfo( lpEnumEntry ); m_listDevice.push_back( CDeviceInfoPtr(pObj) ); pObj->SetServiceInfo(TRUE); NDAS_UNITDEVICE_STATUS status; NDAS_UNITDEVICE_ERROR lastError; BOOL fSuccess = ::NdasQueryDeviceStatus( lpEnumEntry->SlotNo, &status, &lastError); pObj->SetDeviceStatus(status); return TRUE; }
PylonCamera::PylonCamera(CDeviceInfo info, int *pylonInstances, QMutex *pylonInstancesMutex) : mInfo(info), mPylonInstances(pylonInstances), mPylonInstancesMutex(pylonInstancesMutex), mCam(0) { setName(info.GetFriendlyName().c_str()); setGroup(QString("input/pylon/") + info.GetDeviceClass().c_str()); mOut.setName("output"); addOutputPort(mOut); }
int main(int argc, char* argv[]) { // The exit code of the sample application. int exitCode = 0; // Automagically call PylonInitialize and PylonTerminate to ensure the pylon runtime system // is initialized during the lifetime of this object. Pylon::PylonAutoInitTerm autoInitTerm; try { // Declare a local counter used for waiting. int loopCount = 0; // Get the transport layer factory. CTlFactory& tlFactory = CTlFactory::GetInstance(); // Create an instant camera object with the camera device found first. CInstantCamera camera( tlFactory.CreateFirstDevice()); // Print the camera information. cout << "Using device " << camera.GetDeviceInfo().GetModelName() << endl; cout << "Friendly Name: " << camera.GetDeviceInfo().GetFriendlyName() << endl; cout << "Full Name : " << camera.GetDeviceInfo().GetFullName() << endl; cout << "SerialNumber : " << camera.GetDeviceInfo().GetSerialNumber() << endl; cout << endl; // For demonstration purposes only, register another configuration event handler that handles device removal. camera.RegisterConfiguration( new CSampleConfigurationEventHandler, RegistrationMode_Append, Cleanup_Delete); // For demonstration purposes only, add a sample configuration event handler to print out information // about camera use. camera.RegisterConfiguration( new CConfigurationEventPrinter, RegistrationMode_Append, Cleanup_Delete); // Open the camera. Camera device removal is only detected while the camera is open. camera.Open(); // Now, try to detect that the camera has been removed: // Ask the user to disconnect a device loopCount = c_loopCounterInitialValue; cout << endl << "Please disconnect the device (timeout " << loopCount / 4 << "s) " << endl; /////////////////////////////////////////////////// don't single step beyond this line (see comments above) // Before testing the callbacks, we manually set the heartbeat timeout to a short value when using GigE cameras. // Since for debug versions the heartbeat timeout has been set to 5 minutes, it would take up to 5 minutes // until detection of the device removal. CHearbeatHelper heartbeatHelper(camera); heartbeatHelper.SetValue(1000); // 1000 ms timeout try { // Get a camera parameter using generic parameter access. GenApi::CIntegerPtr width(camera.GetNodeMap().GetNode("Width")); // The following loop accesses the camera. It could also be a loop that is // grabbing images. The device removal is handled in the exception handler. while ( loopCount > 0) { // Print a "." every few seconds to tell the user we're waiting for the callback. if (--loopCount % 4 == 0) { cout << "."; cout.flush(); } WaitObject::Sleep(250); // Change the width value in the camera depending on the loop counter. // Any access to the camera like setting parameters or grabbing images // will fail throwing an exception if the camera has been disconnected. width->SetValue( width->GetMax() - (width->GetInc() * (loopCount % 2))); } } catch (GenICam::GenericException &e) { if ( camera.IsCameraDeviceRemoved()) { // The camera device has been removed. This caused the exception. cout << endl; cout << "The camera has been removed from the PC." << endl; cout << "The camera device removal triggered an exception:" << endl << e.GetDescription() << endl; } else { // An unexpected error has occurred. // In this example it is handled by exiting the program. throw; } } if ( !camera.IsCameraDeviceRemoved()) cout << endl << "Timeout expired" << endl; /////////////////////////////////////////////////// Safe to use single stepping (see comments above). // Now try to find the detached camera after it has been attached again: // Create a device info object for remembering the camera properties. CDeviceInfo info; // Remember the camera properties that allow detecting the same camera again. info.SetDeviceClass( camera.GetDeviceInfo().GetDeviceClass()); info.SetSerialNumber( camera.GetDeviceInfo().GetSerialNumber()); // Destroy the Pylon Device representing the detached camera device. // It cannot be used anymore. camera.DestroyDevice(); // Ask the user to connect the same device. loopCount = c_loopCounterInitialValue; cout << endl << "Please connect the same device to the PC again (timeout " << loopCount / 4 << "s) " << endl; // Create a filter containing the CDeviceInfo object info which describes the properties of the device we are looking for. DeviceInfoList_t filter; filter.push_back( info); for ( ; loopCount > 0; --loopCount) { // Print a . every few seconds to tell the user we're waiting for the camera to be attached if ( loopCount % 4 == 0) { cout << "."; cout.flush(); } // Try to find the camera we are looking for. DeviceInfoList_t devices; if ( tlFactory.EnumerateDevices(devices, filter) > 0 ) { // Print two new lines, just for improving printed output. cout << endl << endl; // The camera has been found. Create and attach it to the Instant Camera object. camera.Attach( tlFactory.CreateDevice( devices[0])); //Exit waiting break; } WaitObject::Sleep(250); } // If the camera has been found. if ( camera.IsPylonDeviceAttached()) { // Print the camera information. cout << endl; cout << "Using device " << camera.GetDeviceInfo().GetModelName() << endl; cout << "Friendly Name: " << camera.GetDeviceInfo().GetFriendlyName() << endl; cout << "Full Name : " << camera.GetDeviceInfo().GetFullName() << endl; cout << "SerialNumber : " << camera.GetDeviceInfo().GetSerialNumber() << endl; cout << endl; // All configuration objects and other event handler objects are still registered. // The configuration objects will parameterize the camera device and the instant // camera will be ready for operation again. // Open the camera. camera.Open(); // Now the Instant Camera object can be used as before. } else // Timeout { cout << endl << "Timeout expired." << endl; } } catch (GenICam::GenericException &e) { // Error handling. cerr << "An exception occurred." << endl << e.GetDescription() << endl; exitCode = 1; } // Comment the following two lines to disable waiting on exit. cerr << endl << "Press Enter to exit." << endl; while( cin.get() != '\n'); return exitCode; }
extern "C" int main(int argc, char* argv[] ) { argc = argc; argv = argv; InitLogging(LF_ALWAYS, LL_INFO1); LogFacilityOff(LF_THREADING); printf("KW-Software embedded CLR Version %s for Linux.ARM\n", ECLR_VERSION_STRING); #ifdef PLATFORM_THREADING_SUPPORT //setPriorityScheme(); #endif if (ClrController::Create("Default", loc_object_heap, sizeof(loc_object_heap)) == NULL) { printf("setup controller failed\n"); return -1; } CDeviceInfo* pDeviceInfo = ClrController::getDeviceInfo(); pDeviceInfo->setAttribute(CDeviceInfo::Manufacturer, "KW"); pDeviceInfo->setAttribute(CDeviceInfo::ProductName, "eCLR2.2 for Linux-ARM"); pDeviceInfo->setAttribute(CDeviceInfo::HardwareVersion, "1.0"); pDeviceInfo->setAttribute(CDeviceInfo::FirmwareVersion, "1.0"); pDeviceInfo->setAttribute(CDeviceInfo::MaxApplRetainDataSize, (uint32)0); // pDeviceInfo->setAttribute(CDeviceInfo::TimerResolution, 1000); // pDeviceInfo->setAttribute(CDeviceInfo::ScheduleInterval, 1000); //ClrAppDomain* pAppDomain = ClrController::CreateDomain("Default", ClrAppDomain::CreationDefault); ClrAppDomain* pAppDomain = ClrController::CreateDomain("Default", ClrAppDomain::DownloadChangeSupport); if (pAppDomain == NULL) { printf("vorher setup default domain failed\n"); return -1; } pAppDomain->SetDataMemory(loc_data_heap, sizeof(loc_data_heap)); pAppDomain->SetCodeMemory(loc_code_heap, sizeof(loc_code_heap)); pAppDomain->SetImageStream(&appImgFile); CPcosDomain* pPcosDomain = pcoslib::CreateDomain(pAppDomain); if (pPcosDomain == NULL) { printf("setup default domain failed\n"); return -1; } #ifdef PLATFORM_THREADING_SUPPORT //pPcosDomain->SetTicksPerSecond(0); // scheduler is working with time base of EclrEnvironment #endif #if 0 pPcosDomain->SetCPUCapacity(1000, // int calcFreq_ms 30, // int minCPULoadPerCent 80, // int maxCPULoadPerCent 4 ); // int minFreeTicks #endif //liyamin begin // set the application retentive memory space (simulated by volatile ram) pPcosDomain->AnnounceRetentiveMemory(&g_retain, sizeof(g_retain)); // set a specific ProConOS callback to handle ProConOS state changes //pPcosDomain->setCallback(&myPcosCB); //liyamin end //LIYAMIN_BEGIN //function library loading // GT_LIB10::init(); // GT_LIB10::loadLibrary(); // //share memory loading // CONSEN_SHM::init(); // CONSEN_SHM::loadLibrary(); // // //driver library loading // CONSEN_IO::init(); // CONSEN_IO::loadLibrary(); //LIYAMIN END// // pPcosDomain->WarmStartBootReq(); pPcosDomain->ColdStartBootReq(); // pPcosDomain->AnnounceRetentiveMemory(g_pCshmInterface->m_pMapAddr, 2048); BsdSocket* pBsdSocket = new BsdSocket(); if (pBsdSocket != NULL) { if (pBsdSocket->Open(BsdSocket::Stream, CRemotingDeamon::ClrServerPort) == true) { CRemotingDeamon::addSocket(pBsdSocket); } pBsdSocket->release(); } // start remoting CRemotingDeamon::start(); // change the scheduling policy and priority of this thread struct sched_param zSchedParam; int policy; int nResult; nResult = pthread_getschedparam(pthread_self(), &policy, &zSchedParam); assert(nResult == 0); zSchedParam.sched_priority = SCHEDULER_PRIO; nResult = pthread_setschedparam(pthread_self(), SCHED_FIFO, &zSchedParam); assert(nResult == 0); while (true) { ClrController::Process(); usleep(1 * 1000); //check_timer_overflow(); } return 0; }
int main(int argc, char* argv[]) { // The exit code of the sample application. int exitCode = 0; // Automagically call PylonInitialize and PylonTerminate to ensure the pylon runtime system // is initialized during the lifetime of this object. Pylon::PylonAutoInitTerm autoInitTerm; try { // Only look for cameras supported by Camera_t CDeviceInfo info; info.SetDeviceClass( Camera_t::DeviceClass()); // Create an instant camera object with the first found camera device matching the specified device class. Camera_t camera( CTlFactory::GetInstance().CreateFirstDevice( info)); // Print the model name of the camera. cout << "Using device " << camera.GetDeviceInfo().GetModelName() << endl; cout << "Opening camera..."; // Open the camera. camera.Open(); cout << "done" << endl; cout << "Writing LUT...."; // Select the lookup table using the LUTSelector. camera.LUTSelector.SetValue( LUTSelector_Luminance ); // Some cameras have 10 bit and others have 12 bit lookup tables, so determine // the type of the lookup table for the current device. const int nValues = (int) camera.LUTIndex.GetMax() + 1; int inc; if ( nValues == 4096 ) // 12 bit LUT. inc = 8; else if ( nValues == 1024 ) // 10 bit LUT. inc = 2; else { throw RUNTIME_EXCEPTION( "Type of LUT is not supported by this sample."); } // Use LUTIndex and LUTValue parameter to access the lookup table values. // The following lookup table causes an inversion of the sensor values. for ( int i = 0; i < nValues; i += inc ) { camera.LUTIndex.SetValue( i ); camera.LUTValue.SetValue( nValues - 1 - i ); } cout << "done" << endl; // Enable the lookup table. camera.LUTEnable.SetValue( true ); // Grab and process images here. // ... // Disable the lookup table. camera.LUTEnable.SetValue( false ); // Close the camera. camera.Close(); } catch (GenICam::GenericException &e) { // Error handling. cerr << "An exception occurred." << endl << e.GetDescription() << endl; exitCode = 1; } // Comment the following two lines to disable waiting on exit cerr << endl << "Press Enter to exit." << endl; while( cin.get() != '\n'); return exitCode; }
int main (int argc, char **argv) { if(argc < 2) { fprintf(stdout,"Usage:\n\t%s <conf_file>\n", argv[0]); return 1; } ConfigFile& cf = ConfigFile::GetInstance(); if(!cf.LoadConf(argv[1])) { fprintf(stdout,"load conf file %s error", argv[1]); return 2; } std::string logfile = cf.Value("Global", "LogFile", "./log"); std::string ip = cf.Value("CasdConfig", "Address", "127.0.0.1"); std::string port = cf.Value("CasdConfig", "Port", "12345"); int is_top_camara = atoi(cf.Value("Global", "IsTopCamara", "0").c_str()); int bottom_image_num = atoi(cf.Value("Global", "BottomImageNum", "1").c_str()); int side_image_num = atoi(cf.Value("Global", "SideImageNum", "4").c_str()); casd_client.AddProtocol(PROTOCOL_ID_CSETCAMARASEQREQ, new CSetCamaraSeqReq()); casd_client.AddProtocol(PROTOCOL_ID_CSENDIMAGEPROCESSDATAREQ, new CSendImageProcessDataReq()); if(is_top_camara > 0) { // 非顶部相机需要设置连接回调, 每个物品需要拍摄底部照片和侧边照片 casd_client.SetConnectCB(ConnectCasdCB, &casd_client); gImagesNumPerObj = bottom_image_num + side_image_num; } else { // 顶部相机每个物品只拍摄一张图片, 无需设置连接回调, 当前图片序号永远是固定的 gImagesNumPerObj = 1; gCurImageSeq = atoi(cf.Value("Global", "TopImageSeq", "5").c_str()); } // TODO: 居然还未在tcpclient中加入clog // UVNET::TCPServer::StartLog(LL_DEBUG, "casd", logfile.c_str()); if(!casd_client.Connect(ip.c_str(), atoi(port.c_str()))) { fprintf(stdout, "connect error:%s\n", casd_client.GetLastErrMsg()); } int exitcode = 0; // Before using any pylon methods, the pylon runtime must be initialized. PylonInitialize(); try { CTlFactory& TlFactory = CTlFactory::GetInstance(); CDeviceInfo di; di.SetSerialNumber( "20399956" ); di.SetDeviceClass( BaslerGigEDeviceClass ); IPylonDevice* device = TlFactory.CreateDevice( di ); // Create an instant camera object for the camera device found first. // CInstantCamera camera( CTlFactory::GetInstance().CreateFirstDevice()); CInstantCamera camera( device ); // For demonstration purposes only, register another image event handler. camera.RegisterImageEventHandler( new CSampleImageEventHandler, RegistrationMode_Append, Cleanup_Delete); // Open the camera device. camera.Open(); // Can the camera device be queried whether it is ready to accept the next frame trigger? if (camera.CanWaitForFrameTriggerReady()) { // Start the grabbing using the grab loop thread, by setting the grabLoopType parameter // to GrabLoop_ProvidedByInstantCamera. The grab results are delivered to the image event handlers. // The GrabStrategy_OneByOne default grab strategy is used. camera.StartGrabbing( GrabStrategy_OneByOne, GrabLoop_ProvidedByInstantCamera); cerr << endl << "Enter \"t\" to trigger the camera or \"e\" to exit and press enter? (t/e)" << endl << endl; // Wait for user input to trigger the camera or exit the program. // The grabbing is stopped, the device is closed and destroyed automatically when the camera object goes out of scope. char key; do { cin.get(key); if ( (key == 't' || key == 'T')) { // Execute the software trigger. Wait up to 500 ms for the camera to be ready for trigger. if ( camera.WaitForFrameTriggerReady( 500, TimeoutHandling_ThrowException)) { camera.ExecuteSoftwareTrigger(); } } } while ( (key != 'e') && (key != 'E')); } else { // See the documentation of CInstantCamera::CanWaitForFrameTriggerReady() for more information. cout << endl; cout << "This sample can only be used with cameras that can be queried whether they are ready to accept the next frame trigger."; cout << endl; cout << endl; } } catch (const GenericException &e) { // Error handling. cerr << "An exception occurred." << endl << e.GetDescription() << endl; exitcode = 1; // Remove left over characters from input buffer. cin.ignore(cin.rdbuf()->in_avail()); } // Comment the following two lines to disable waiting on exit. cerr << endl << "Press Enter to exit." << endl; while( cin.get() != '\n'); // Releases all pylon resources. PylonTerminate(); return exitcode; }
int main(int argc, char* argv[]) { int exitCode = 0; Pylon::PylonAutoInitTerm autoInitTerm; CDeviceInfo info; info.SetDeviceClass(Camera_t::DeviceClass()); CTlFactory& tlFactory = CTlFactory::GetInstance(); DeviceInfoList_t devices; if (tlFactory.EnumerateDevices(devices) == 0) { throw RUNTIME_EXCEPTION("No camera present."); } int cam_num = devices.size(); cameras = new CBaslerUsbInstantCameraArray(min(devices.size(), c_maxCamerasToUse)); // Create and attach all Pylon Devices. for (size_t i = 0; i < cameras->GetSize(); ++i) { cameras->operator[](i).Attach(tlFactory.CreateDevice(devices[i])); cameras->operator[](i).RegisterConfiguration(new CSoftwareTriggerConfiguration, RegistrationMode_Append, Cleanup_Delete); cameras->operator[](i).RegisterImageEventHandler(new CSampleImageEventHandler, RegistrationMode_Append, Cleanup_Delete); cameras->operator[](i).Open(); _ImageBuffers[i] = new MyBufferFactory(); cameras->operator[](i).SetBufferFactory(_ImageBuffers[i], Cleanup_None); CDeviceInfo & diRef = devices[i]; if (diRef.GetModelName().find(GenICam::gcstring("acA2500-14uc")) != GenICam::gcstring::_npos()) { _IsCameraBW[i] = false; cameras->operator[](i).PixelFormat.SetValue(PixelFormat_BayerGB12); } else if (diRef.GetModelName().find(GenICam::gcstring("acA2500-14um")) != GenICam::gcstring::_npos()) { _IsCameraBW[i] = true; cameras->operator[](i).PixelFormat.SetValue(PixelFormat_Mono12); } //cameras->operator[](i).PixelFormat.SetValue(PixelFormat_Mono12); //cameras->operator[](i).Gain.SetValue(0); if (_IsCameraBW[i]) cameras->operator[](i).ExposureTime.SetValue(Exposure); else cameras->operator[](i).ExposureTime.SetValue(Exposure*ColorExposureMultiplier); cout << "Using device " << cameras->operator[](i).GetDeviceInfo().GetModelName() << endl; if (GenApi::IsWritable(cameras->operator[](i).ChunkModeActive)) { cameras->operator[](i).ChunkModeActive.SetValue(true); } else { throw RUNTIME_EXCEPTION("The camera doesn't support chunk features"); } cameras->operator[](i).ChunkSelector.SetValue(ChunkSelector_Timestamp); cameras->operator[](i).ChunkEnable.SetValue(true); } try { char key; ProcessMessage(Action); do { cin.get(key); Action = ParseKey(key); ProcessMessage(Action); } while (Action != Quit); } catch (GenICam::GenericException &e) { // Error handling. cerr << "An exception occurred." << endl << e.GetDescription() << endl; exitCode = 1; } // Comment the following two lines to disable waiting on exit. cerr << endl << "Press Enter to exit." << endl; while( cin.get() != '\n'); return exitCode; }
int main(int argc, char* argv[]) { // Exit code of the sample application. int exitCode = 0; // Before using any pylon methods, the pylon runtime must be initialized. PylonInitialize(); try { // Create the event handler. CEventHandler eventHandler; // Only look for cameras supported by Camera_t. CDeviceInfo info; info.SetDeviceClass( Camera_t::DeviceClass()); // Create an instant camera object with the first found camera device matching the specified device class. Camera_t camera( CTlFactory::GetInstance().CreateFirstDevice( info)); // For demonstration purposes only, add sample configuration event handlers to print out information // about camera use and image grabbing. camera.RegisterConfiguration( new CConfigurationEventPrinter, RegistrationMode_Append, Cleanup_Delete); // Camera use. // Register the event handler. camera.RegisterImageEventHandler( &eventHandler, RegistrationMode_Append, Cleanup_None); camera.RegisterCameraEventHandler( &eventHandler, "EventExposureEndData", eMyExposureEndEvent, RegistrationMode_ReplaceAll, Cleanup_None); camera.RegisterCameraEventHandler( &eventHandler, "EventFrameStartOvertriggerData", eMyFrameStartOvertrigger, RegistrationMode_Append, Cleanup_None); // Camera event processing must be activated first, the default is off. camera.GrabCameraEvents = true; // Open the camera for setting parameters. camera.Open(); // Check if the device supports events. if ( !IsAvailable( camera.EventSelector)) { throw RUNTIME_EXCEPTION( "The device doesn't support events."); } // Enable the sending of Exposure End events. // Select the event to be received. camera.EventSelector.SetValue(EventSelector_ExposureEnd); // Enable it. camera.EventNotification.SetValue(EventNotification_On); // Enable the sending of Frame Start Overtrigger events. if ( IsAvailable( camera.EventSelector.GetEntry(EventSelector_FrameStartOvertrigger))) { camera.EventSelector.SetValue(EventSelector_FrameStartOvertrigger); camera.EventNotification.SetValue(EventNotification_On); } // Start the grabbing of c_countOfImagesToGrab images. // The camera device is parameterized with a default configuration which // sets up free-running continuous acquisition. camera.StartGrabbing( c_countOfImagesToGrab); // This smart pointer will receive the grab result data. CGrabResultPtr ptrGrabResult; // Camera.StopGrabbing() is called automatically by the RetrieveResult() method // when c_countOfImagesToGrab images have been retrieved. while ( camera.IsGrabbing()) { // Retrieve grab results and notify the camera event and image event handlers. camera.RetrieveResult( 5000, ptrGrabResult, TimeoutHandling_ThrowException); // Nothing to do here with the grab result, the grab results are handled by the registered event handlers. } // Disable the sending of Exposure End events. camera.EventSelector = EventSelector_ExposureEnd; camera.EventNotification.SetValue(EventNotification_Off); // Disable the sending of Frame Start Overtrigger events. if ( IsAvailable( camera.EventSelector.GetEntry(EventSelector_FrameStartOvertrigger))) { camera.EventSelector.SetValue(EventSelector_FrameStartOvertrigger); camera.EventNotification.SetValue(EventNotification_Off); } // Print the recorded log showing the timing of events and images. eventHandler.PrintLog(); } catch (const GenericException &e) { // Error handling. cerr << "An exception occurred." << endl << e.GetDescription() << endl; exitCode = 1; } // Comment the following two lines to disable waiting on exit. cerr << endl << "Press Enter to exit." << endl; while( cin.get() != '\n'); // Releases all pylon resources. PylonTerminate(); return exitCode; }