BOOL GetCorAcquisitionOptionsFromQuestions(char *acqServerName, UINT32 *pAcqDeviceIndex, char *configFileName) { //////// Ask questions to user to select acquisition board/device and config file //////// // Get total number of boards in the system int serverCount = SapManager::GetServerCount(); char deviceIndexToPrint[STRING_LENGTH]; char configFileIndexToPrint[STRING_LENGTH]; if (serverCount == 0) { printf("No device found!\n"); return FALSE; } printf("\nSelect the acquisition server: Press "); printf("1"); CorSnprintf(deviceIndexToPrint, sizeof(deviceIndexToPrint), "%d", serverCount-1); if (serverCount >= 2) { printf(" to "); printf(deviceIndexToPrint); } printf(" or 'q' to quit."); printf("\n........................................\n"); // Scan the boards to find those that support acquisition BOOL serverFound = FALSE; for (int serverIndex = 0; serverIndex < serverCount; serverIndex++) { if (SapManager::GetResourceCount(serverIndex, SapManager::ResourceAcq) != 0) { char serverName[CORSERVER_MAX_STRLEN]; SapManager::GetServerName(serverIndex, serverName, sizeof(serverName)); printf("%d: %s\n", serverIndex, serverName); serverFound = TRUE; } } // At least one acquisition server must be available if (!serverFound) { printf("No acquisition server found!\n"); return FALSE; } char key = (char)_getch(); if (key != 0) { if (key == 'q') return FALSE; int serverNum = key - '0'; // char-to-int conversion if ((serverNum >= 1) && (serverNum < serverCount)) { // update board name SapManager::GetServerName(serverNum, acqServerName, CORSERVER_MAX_STRLEN); } else { printf("Invalid selection!\n"); return FALSE; } } else { printf("Invalid selection!\n"); return FALSE; } // Scan all the acquisition devices on that server and show menu to user int deviceCount = SapManager::GetResourceCount(acqServerName, SapManager::ResourceAcq); int allDeviceCount=0; int cameraCount = 0; #ifndef GRAB_CAMERA_LINK printf("\nSelect the acquisition device: Press "); #else { printf("\nSelect the device you wish to use on this server: Press "); } #endif printf("1"); allDeviceCount = deviceCount; CorSnprintf(deviceIndexToPrint, sizeof(deviceIndexToPrint), "%d", allDeviceCount); if (allDeviceCount >= 2) { printf(" to "); printf(deviceIndexToPrint); } printf(" or 'q' to quit."); printf("\n........................................\n"); for (int deviceIndex = 0; deviceIndex < deviceCount; deviceIndex++) { char deviceName[CORPRM_GETSIZE(CORACQ_PRM_LABEL)]; SapManager::GetResourceName(acqServerName, SapManager::ResourceAcq, deviceIndex, deviceName, sizeof(deviceName)); printf("%d: %s\n", deviceIndex+1, deviceName); } key = (char)_getch(); if (key != 0) { if (key == 'q') return FALSE; int deviceNum = key - '0'; // char-to-int conversion if ((deviceNum >= 1) && (deviceNum <= deviceCount)) { *pAcqDeviceIndex = deviceNum-1; } else { printf("Invalid selection!\n"); return FALSE; } } else { printf("Invalid selection!\n"); return FALSE; } // List all files in the config directory char configPath[MAX_PATH]; GetEnvironmentVariable("SAPERADIR", configPath, sizeof(configPath)); CorStrncat(configPath, "\\CamFiles\\User\\", sizeof(configPath)); char findPath[MAX_PATH]; CorStrncpy(findPath, configPath, MAX_PATH); CorStrncat(findPath, "*.ccf", sizeof(findPath)); HANDLE fhandle; WIN32_FIND_DATA fdata; if ((fhandle = FindFirstFile(findPath, &fdata)) == INVALID_HANDLE_VALUE) { if (cameraCount==0) { printf("No config file found.\nUse CamExpert to generate a config file before running this example.\n"); return FALSE; } } int configFileCount = 0; do { configFileCount++; } while (FindNextFile(fhandle, &fdata) && configFileCount < MAX_CONFIG_FILES); FindClose(fhandle); fhandle = FindFirstFile(findPath, &fdata); // Try to find the last letter to choose int configFileMenuCount = 0; char lastCharMenu='x'; do { // Use numbers 0 to 9, then lowercase letters if there are more than 10 files int configFileMenuShow = configFileMenuCount+1; if (configFileMenuCount > 9) lastCharMenu = (char)(configFileMenuShow - 10 + 'a'); //CorStrncpy(configFileNames[configFileCount], fdata.cFileName, sizeof(configFileNames[configFileCount])); configFileMenuCount++; } while (FindNextFile(fhandle, &fdata) && configFileMenuCount < MAX_CONFIG_FILES); FindClose(fhandle); printf("\nSelect the config file: Press "); printf("1"); CorSnprintf(configFileIndexToPrint, sizeof(configFileIndexToPrint), "%d", configFileCount); if (cameraCount == 0) { if (configFileCount >= 2) { printf(" to "); if (configFileCount <= 9) printf(configFileIndexToPrint); else printf("'9'"); } if (lastCharMenu != 'x') { printf(" or 'a'"); printf(" to '"); printf("%c", lastCharMenu); printf("'"); } } printf(" or 'q' to quit."); printf("\n........................................\n"); configFileCount = 0; fhandle = FindFirstFile(findPath, &fdata); do { // Use numbers 0 to 9, then lowercase letters if there are more than 10 files int configFileShow = configFileCount+1; if (configFileCount < 9) printf("%d: %s\n", configFileShow, fdata.cFileName); else printf("%c: %s\n", configFileShow - 10 + 'a', fdata.cFileName); CorStrncpy(configFileNames[configFileCount], fdata.cFileName, sizeof(configFileNames[configFileCount])); configFileCount++; } while (FindNextFile(fhandle, &fdata) && configFileCount < MAX_CONFIG_FILES); FindClose(fhandle); key = (char)_getch(); if (key != 0) { if (key == '1' && cameraCount != 0) return TRUE; if (key == 'q') return FALSE; // Use numbers 0 to 9, then lowercase letters if there are more than 10 files int configNum; if (key >= '1' && key <= '9') configNum = key - '1'; // char-to-int conversion else configNum = key - 'a' + 10; // char-to-int conversion if ((configNum >= 0) && (configNum <= configFileCount)) { CorStrncpy(configFileName, configPath, sizeof(configPath)); CorStrncat(configFileName, configFileNames[configNum], sizeof(configFileNames[configNum])); } else { printf("Invalid selection!\n"); return FALSE; } } else { printf("Invalid selection!\n"); return FALSE; } printf("\n"); return TRUE; }
BOOL CGioOutputDlg::OnInitDialog() { UINT32 capOutput=0,capTristate=0,capOutputType=0,capEventType=0,capPowerGood=0,capFaultDetect=0; UINT32 bFaultDetect=0; UINT32 prmOutput=0,prmTristate=0; UINT32 iSelection,iIO=0; UINT32 capReadOnly=0; char label[128]; CDialog::OnInitDialog(); if( m_pGio == NULL || !*m_pGio) { AfxMessageBox(_T("Invalid Gio object")); CDialog::OnCancel(); return FALSE; } // Get signal status reporting capability. Note that it is not supported on all // products, and we need to first check if the capability is valid. if (m_pGio->IsCapabilityValid(CORGIO_CAP_OUTPUT_TYPE)) m_pGio->GetCapability(CORGIO_CAP_OUTPUT_TYPE, &capOutputType); if (m_pGio->IsCapabilityValid(CORGIO_CAP_DIR_TRISTATE)) m_pGio->GetCapability(CORGIO_CAP_DIR_TRISTATE,&capTristate); if (m_pGio->IsCapabilityValid(CORGIO_CAP_DIR_OUTPUT)) m_pGio->GetCapability(CORGIO_CAP_DIR_OUTPUT,&capOutput); if (m_pGio->IsParameterValid(CORGIO_PRM_LABEL)) m_pGio->GetParameter(CORGIO_PRM_LABEL, label); if (m_pGio->IsCapabilityValid(CORGIO_CAP_EVENT_TYPE)) m_pGio->GetCapability(CORGIO_CAP_EVENT_TYPE,&capEventType); if (m_pGio->IsCapabilityValid(CORGIO_CAP_POWER_GOOD)) m_pGio->GetCapability(CORGIO_CAP_POWER_GOOD,&capPowerGood); if (m_pGio->IsCapabilityValid(CORGIO_CAP_FAULT_DETECT)) m_pGio->GetCapability(CORGIO_CAP_FAULT_DETECT,&capFaultDetect); if (m_pGio->IsParameterValid(CORGIO_PRM_OUTPUT_TYPE)) m_pGio->GetParameter(CORGIO_PRM_OUTPUT_TYPE,&prmOutput); if (m_pGio->IsParameterValid(CORGIO_PRM_DIR_TRISTATE)) m_pGio->GetParameter(CORGIO_PRM_DIR_TRISTATE,&prmTristate); if (m_pGio->IsCapabilityValid(CORGIO_CAP_READ_ONLY)) m_pGio->GetCapability(CORGIO_CAP_READ_ONLY,&capReadOnly); if( !strstr( label, "output") && !strstr( label, "Output")) { CorStrncat(label," (output)", sizeof(label)); } m_Static_Label.SetWindowText(CString(label)); // Enable only the IO available for (iIO=0; iIO < (UINT32)m_pGio->GetNumPins(); iIO++) { if(!(capReadOnly & (1 << iIO))) { ((CButton*)GetDlgItem(IDC_SCG_PIN1 + iIO))->EnableWindow(capOutput & (1<<iIO)); } } if (capTristate) { iSelection = m_Combo_Output_State.AddString(_T("Tristate")); m_Combo_Output_State.SetItemData( iSelection, OUTPUT_TYPE_TRISTATE); // A value of 0 will be used for Tristate if( prmTristate) { m_Combo_Output_State.SetCurSel(iSelection); } } if (capOutputType & CORGIO_VAL_OUTPUT_TYPE_PNP) { iSelection = m_Combo_Output_State.AddString(_T("PNP")); m_Combo_Output_State.SetItemData(iSelection, CORGIO_VAL_OUTPUT_TYPE_PNP); if( !prmTristate && (prmOutput == CORGIO_VAL_OUTPUT_TYPE_PNP)) { m_Combo_Output_State.SetCurSel(iSelection); } } if (capOutputType & CORGIO_VAL_OUTPUT_TYPE_NPN) { iSelection = m_Combo_Output_State.AddString(_T("NPN")); m_Combo_Output_State.SetItemData( iSelection, CORGIO_VAL_OUTPUT_TYPE_NPN); if( !prmTristate && (prmOutput == CORGIO_VAL_OUTPUT_TYPE_NPN)) { m_Combo_Output_State.SetCurSel(iSelection); } } if (capOutputType & CORGIO_VAL_OUTPUT_TYPE_LED) { iSelection = m_Combo_Output_State.AddString(_T("LED")); m_Combo_Output_State.SetItemData( iSelection, CORGIO_VAL_OUTPUT_TYPE_LED); if( !prmTristate && (prmOutput == CORGIO_VAL_OUTPUT_TYPE_LED)) { m_Combo_Output_State.SetCurSel(iSelection); } } if (capOutputType & CORGIO_VAL_OUTPUT_TYPE_OPTOCOUPLE) { iSelection = m_Combo_Output_State.AddString(_T("OPTO")); m_Combo_Output_State.SetItemData( iSelection, CORGIO_VAL_OUTPUT_TYPE_OPTOCOUPLE); if( !prmTristate && (prmOutput == CORGIO_VAL_OUTPUT_TYPE_OPTOCOUPLE)) { m_Combo_Output_State.SetCurSel(iSelection); } } if (capOutputType & CORGIO_VAL_OUTPUT_TYPE_TTL) { iSelection = m_Combo_Output_State.AddString(_T("TTL")); m_Combo_Output_State.SetItemData( iSelection, CORGIO_VAL_OUTPUT_TYPE_TTL); if( !prmTristate && (prmOutput == CORGIO_VAL_OUTPUT_TYPE_TTL)) { m_Combo_Output_State.SetCurSel(iSelection); } } if (capOutputType & CORGIO_VAL_OUTPUT_TYPE_LVTTL) { iSelection = m_Combo_Output_State.AddString(_T("LVTTL")); m_Combo_Output_State.SetItemData( iSelection, CORGIO_VAL_OUTPUT_TYPE_LVTTL); if( !prmTristate && (prmOutput == CORGIO_VAL_OUTPUT_TYPE_LVTTL)) { m_Combo_Output_State.SetCurSel(iSelection); } } if (!capOutputType) { iSelection = m_Combo_Output_State.AddString(_T("Active")); m_Combo_Output_State.SetItemData( iSelection, OUTPUT_TYPE_ACTIVE); // A value of 0xFFFF will be used for Active if( !prmTristate) { m_Combo_Output_State.SetCurSel(iSelection); } } if (capFaultDetect) { if (m_pGio->IsParameterValid(CORGIO_PRM_FAULT_DETECT)) m_pGio->GetParameter(CORGIO_PRM_FAULT_DETECT,&bFaultDetect); CWnd *PowerNA=GetDlgItem(IDC_STATIC_NA); PowerNA->ModifyStyle(WS_VISIBLE, 0); PowerNA->RedrawWindow(); CWnd *PowerGreen=GetDlgItem(IDC_SCG_POWER_COLOR_GREEN); CWnd *PowerRed=GetDlgItem(IDC_SCG_POWER_COLOR_RED); if (!bFaultDetect) { PowerGreen->EnableWindow(true); PowerRed->EnableWindow(false); PowerGreen->ModifyStyle(0, WS_VISIBLE); PowerGreen->RedrawWindow(); } else { PowerRed->EnableWindow(true); PowerGreen->EnableWindow(false); PowerRed->ModifyStyle(0, WS_VISIBLE); PowerRed->RedrawWindow(); } } else { CWnd *PowerLabel=GetDlgItem(IDC_SCG_POWER_LABEL); PowerLabel->EnableWindow(false); PowerLabel->RedrawWindow(); } // Output buttons captions initialized InitOutputDlg(); return TRUE; }