// The entry point for mex void mexFunction(int nlhs,mxArray *plhs[],int nrhs,const mxArray *prhs[]) { /* Check for proper number of input and output arguments */ if (nrhs != 0) { mexErrMsgIdAndTxt( "Mscope:initialiseCamera:invalidNumInputs", "One input argument required."); } if (nlhs > 1) { mexErrMsgIdAndTxt( "Mscope:initialiseCamera:maxlhs", "Too many output arguments."); } // Start acquiring is an Andor function unsigned int andorCode = StartAcquisition(); UINT32_T andorCode32 = (UINT32_T) andorCode; // define an array of mwSignedIndex called dims (which is our output array dimensions) mwSignedIndex dims[2] = {1,1}; plhs[0] = mxCreateNumericArray(1, dims, mxUINT32_CLASS, mxREAL); double * outDataPtr = mxGetPr(plhs[0]); memcpy(outDataPtr, &andorCode32, sizeof(andorCode32)); return; }
int main(int argc, char *argv[]) { int adcChannel=1, minX=0, minY=0, binX=1, binY=1, sizeX=1024, sizeY=1024; int triggerMode=0, numExposures=2, numImages=3; float mAcquireTime=0.1f, mAccumulatePeriod=1.0f, mAcquirePeriod=4.0f; float acquireTimeAct, accumulatePeriodAct, acquirePeriodAct; int AAKinetics=3, ATInternal=0; time_t startTime, endTime; int acquireStatus; checkStatus(Initialize("/usr/local/etc/andor")); printf("SetTriggerMode(%d)\n", triggerMode); checkStatus(SetTriggerMode(ATInternal)); printf("SetADChannel(%d)\n", adcChannel); checkStatus(SetADChannel(adcChannel)); //Set fastest HS speed. printf("SetHSSpeed(0, 0)\n"); checkStatus(SetHSSpeed(0, 0)); printf("SetImage(%d,%d,%d,%d,%d,%d)\n", binX, binY, minX+1, minX+sizeX, minY+1, minY+sizeY); checkStatus(SetImage(binX, binY, minX+1, minX+sizeX, minY+1, minY+sizeY)); printf("SetExposureTime(%f)\n", mAcquireTime); checkStatus(SetExposureTime(mAcquireTime)); printf("SetAcquisitionMode(AAKinetics)\n"); checkStatus(SetAcquisitionMode(AAKinetics)); printf("SetNumberAccumulations(%d)\n", numExposures); checkStatus(SetNumberAccumulations(numExposures)); printf("SetAccumulationCycleTime(%f)\n", mAccumulatePeriod); checkStatus(SetAccumulationCycleTime(mAccumulatePeriod)); printf("SetNumberKinetics(%d)\n", numImages); checkStatus(SetNumberKinetics(numImages)); printf("SetKineticCycleTime(%f)\n", mAcquirePeriod); checkStatus(SetKineticCycleTime(mAcquirePeriod)); checkStatus(GetAcquisitionTimings(&acquireTimeAct, &accumulatePeriodAct, &acquirePeriodAct)); printf("GetAcquisitionTimings(exposure=%f, accumulate=%f, kinetic=%f)\n", acquireTimeAct, accumulatePeriodAct, acquirePeriodAct); time(&startTime); printf("StartAcquisition()\n"); checkStatus(StartAcquisition()); while (1) { printf("GetStatus()\n"); checkStatus(GetStatus(&acquireStatus)); if (acquireStatus != DRV_ACQUIRING) break; printf("WaitForAcquisition()\n"); checkStatus(WaitForAcquisition()); time(&endTime); printf("Time since start=%f\n", difftime(endTime, startTime)); } return 0; }
int main() { init_clara(); C(PrepareAcquisition()); int i; for(i=0;;i++){ C(StartAcquisition()); capture_clara(); } C(AbortAcquisition()); C(FreeInternalMemory()); uninit_clara(); return 0; }
bool ANDOR885_Camera::startAcquisition() { int errorValue; bool success = true; // Check to see if camera is idle before trying to turn on acquisition GetStatus(&errorValue); if (errorValue != DRV_IDLE) { std::cerr << "Acquisition still running" << std::endl; success = false; } else { if (acquisitionMode == ACQMODE_KINETIC_SERIES) { //it is assumed that the triggermode is a flavor of external, as required in setAcquisitionMode and setTriggerMode // KINETIC SERIES ACQUISITION MODE IS NOT SUITABLE FOR PLAYING EVENTS. Probably should get rid of the option. SetNumberAccumulations(1); if (eventMetadata == NULL) { SetNumberKinetics(1); } else { SetNumberKinetics(eventMetadata->size()); } } // Start acquisition errorValue = StartAcquisition(); printError(errorValue,"Error starting acquisition", &success, ANDOR_SUCCESS); if (success) takeThrowawayImage = true; //Gets set to false in ANDOR885_Camera.cpp, playCamera } return success; }
void Messenger::ProcessMessage(SocketMessage m, int sid) { if (m.GetKey()==REMOVE_CLIENT) { if (m.GetIntValue()==GetSocketId()) { std::ostringstream o; o << "Some client (id=" << sid << ") asked for this master's disconnection!" << "\n\tIgnoring this request..."; throw Exception(__PRETTY_FUNCTION__, o.str(), JustWarning); return; } const MessageKey key = (sid==m.GetIntValue()) ? THIS_CLIENT_DELETED : OTHER_CLIENT_DELETED; DisconnectClient(m.GetIntValue(), key); throw Exception(__PRETTY_FUNCTION__, "Removing socket client", Info, 11001); } else if (m.GetKey()==PING_CLIENT) { const int toping = m.GetIntValue(); Send(SocketMessage(PING_CLIENT), toping); SocketMessage msg; int i=0; do { msg = FetchMessage(toping); i++; } while (msg.GetKey()!=PING_ANSWER && i<MAX_SOCKET_ATTEMPTS); try { Send(SocketMessage(PING_ANSWER, msg.GetValue()), sid); } catch (Exception& e) { e.Dump(); } } else if (m.GetKey()==GET_CLIENTS) { int i = 0; std::ostringstream os; for (SocketCollection::const_iterator it=fSocketsConnected.begin(); it!=fSocketsConnected.end(); it++, i++) { if (i!=0) os << ";"; os << it->first << " (type " << static_cast<int>(it->second) << ")"; } try { Send(SocketMessage(CLIENTS_LIST, os.str()), sid); } catch (Exception& e) { e.Dump(); } } else if (m.GetKey()==WEB_GET_CLIENTS) { int i = 0; SocketType type; std::ostringstream os; for (SocketCollection::const_iterator it=fSocketsConnected.begin(); it!=fSocketsConnected.end(); it++, i++) { type = (it->first==GetSocketId()) ? MASTER : it->second; if (i!=0) os << ";"; os << it->first << ","; if (it->first==GetSocketId()) os << "Master,"; else os << "Client" << it->first << ","; os << static_cast<int>(type) << "\0"; } try { Send(SocketMessage(CLIENTS_LIST, os.str()), sid); } catch (Exception& e) { e.Dump(); } } else if (m.GetKey()==START_ACQUISITION) { try { StartAcquisition(); } catch (Exception& e) { e.Dump(); SendAll(DAQ, e); } } else if (m.GetKey()==STOP_ACQUISITION) { try { StopAcquisition(); } catch (Exception& e) { e.Dump(); SendAll(DAQ, e); } } else if (m.GetKey()==NEW_RUN) { try { OnlineDBHandler().NewRun(); int last_run = OnlineDBHandler().GetLastRun(); SendAll(DQM, SocketMessage(RUN_NUMBER, last_run)); SendAll(DAQ, SocketMessage(RUN_NUMBER, last_run)); } catch (Exception& e) { e.Dump(); } } else if (m.GetKey()==GET_RUN_NUMBER) { int last_run = 0; try { last_run = OnlineDBHandler().GetLastRun(); } catch (Exception& e) { last_run = -1; } try { Send(SocketMessage(RUN_NUMBER, last_run), sid); } catch (Exception& e) { e.Dump(); } } else if (m.GetKey()==SET_NEW_FILENAME) { try { std::cout << "---> " << m.GetValue() << std::endl; SendAll(DQM, SocketMessage(NEW_FILENAME, m.GetValue().c_str())); } catch (Exception& e) { e.Dump(); } } else if (m.GetKey()==NUM_TRIGGERS or m.GetKey()==HV_STATUS) { try { SendAll(DAQ, m); } catch (Exception& e) { e.Dump(); } } else if (m.GetKey()==NEW_DQM_PLOT or m.GetKey()==UPDATED_DQM_PLOT) { try { SendAll(DAQ, m); } catch (Exception& e) { e.Dump(); } } else if (m.GetKey()==EXCEPTION) { try { SendAll(DAQ, m); std::cout << "--> " << m.GetValue() << std::endl; } catch (Exception& e) { e.Dump(); } } /*else { try { Send(SocketMessage(INVALID_KEY), sid); } catch (Exception& e) { e.Dump(); } std::ostringstream o; o << "Received an invalid message: " << m.GetString(); throw Exception(__PRETTY_FUNCTION__, o.str(), JustWarning); }*/ }
int main(int argc, char **argv) { int status; int bitdepth; int width, height; int min, max; int i, j, numgains; float gain; int num_ad; int num_vspeeds; int num_hspeeds; float speed; AndorCapabilities caps; at_32 lNumCameras; at_32 lCameraHandle; int start_n, stop_n; int npix; /* Check command line */ npix = 90; if (argc > 1) sscanf(argv[1], "%d", &npix); /* FIRST, FIND OUT WHAT WE NEED TO KNOW ABOUT THIS CAMERA. */ printf("Initializing Andor Camera.\n"); /* How many cameras are connected */ printf("GetAvailableCameras = %d\n", GetAvailableCameras(&lNumCameras)); if (lNumCameras == 1) printf("There is %d camera connected.\n", lNumCameras); else printf("There are %d cameras connected.\n", lNumCameras); if (lNumCameras <= 0) exit(0); /* Get the camera we are working with. */ printf("GetCameraHandle = %d\n", GetCameraHandle(0, &lCameraHandle)); printf("SetCurrentCamera = %d\n", SetCurrentCamera(lCameraHandle)); /* Initialize the CCD */ printf("Initialize = %d\n", Initialize("/usr/local/etc/andor")); /* Wait for this to happen */ sleep(2); /* What Capabilities do we have? */ caps.ulSize = sizeof(caps); printf("GetCapabilities = %d\n", GetCapabilities(&caps)); if (caps.ulCameraType & AC_CAMERATYPE_IXON) printf("Camera is an iXon.\n"); else printf("Camera is not an iXon.\n"); if (caps.ulAcqModes & AC_ACQMODE_FRAMETRANSFER) printf("Frame transfer is available.\n"); else printf("Frame transfer is not available.\n"); if (caps.ulSetFunctions & AC_SETFUNCTION_CROPMODE) printf("Crop mode is available.\n"); else printf("Crop mode is not available.\n"); /* Find out what the width and height are */ printf("GetDetector = %d\n", GetDetector(&width, &height)); printf("Andor full size %dx%d.\n", width, height); /* What is the allowable temperature range? */ printf("GetTemperatureRange = %d\n", GetTemperatureRange(&min, &max)); printf("Andor temperature range is %d to %d C.\n", min, max); /* How many preamp gains do we have? */ printf("GetNumberPreAmpGains = %d\n", GetNumberPreAmpGains(&numgains)); printf("Andor number of preamp gains is %d.\n", numgains); /* Let's find out what these gains are */ for (i=0; i<numgains; i++) { printf("GetPreAmpGain = %d\n", GetPreAmpGain(i, &gain)); printf("Andor Preamp Gain %d is %f.\n", i, gain); } /* How many vertical speeds do we have? */ printf("GetNumberVSSpeeds = %d\n", GetNumberVSSpeeds(&num_vspeeds)); printf("Andor number of Vertical Speeds is %d.\n", num_vspeeds); /* Let's find out what these VSpeeds are */ for (i=0; i<num_vspeeds; i++) { printf("GetVSSpeed = %d\n", GetVSSpeed(i, &speed)); printf("Andor Vertical Speed %d is %.2f uS.\n", i, speed); } for(j = 0; j < 1; j++) { if (j == 0) printf("For EMCCD output:\n"); else printf("For CCD output:\n"); /* How many horizontal speeds do we have? */ printf("GetNumberHSSpeeds = %d\n", GetNumberHSSpeeds(0, j, &num_hspeeds)); printf("Andor number of Horizontal Speeds is %d.\n", num_hspeeds); /* Let's find out what these speeds are */ for (i=0; i<num_hspeeds; i++) { printf("GetHSSpeed = %d\n", GetHSSpeed(0, j, i, &speed)); printf("Andor Horizontal Speed %d is %.2f MHz.\n", i, speed); } } /* What is the range of gain settings - This is always wrong */ printf("GetEMGainRange = %d\n", GetEMGainRange(&min, &max)); printf("Andor EM Gain range is %d to %d.\n", min, max); /* How many AD channels are there? */ printf("GetNumberADChannels = %d\n", GetNumberADChannels(&num_ad)); printf("Number of AD channels = %d\n", num_ad); /* What are the bit depths? */ for(i=0; i < num_ad; i++) { printf("GetBitDepth = %d\n", GetBitDepth(i, &bitdepth)); printf("AD channel %d has bit depth %d\n", i, bitdepth); } /* NOW WE START TO SET THINGS UP THE WAY WE WANT THEM */ /* Turn on Cameralink mode */ printf("SetCameraLinkMode = %d\n", SetCameraLinkMode(1)); /* Put us in Frame Transfer Mode */ printf( "Turning on Frame Transfer Mode.\n"); printf("SetFrameTransferMode = %d\n", SetFrameTransferMode(1)); /* Set output amplifier to EMCCD */ printf("SetOutputAmplifier = %d\n", SetOutputAmplifier(0)); /* Turn on advanced EM settings */ printf("SetEMAdvanced = %d\n", SetEMAdvanced(1)); /* Let's see if that worked... we should get 1000 as maximum */ printf("GetEMGainRange = %d\n", GetEMGainRange(&min, &max)); printf("Andor EM Gain range is %d to %d.\n", min, max); /* Set EM gain */ printf("SetEMCCDGain = %d\n", SetEMCCDGain(300)); /* Set our horizontal speed to the desired one. */ printf("SetHSSpeed = %d\n", SetHSSpeed(0, 0)); /* Set our vertical speed to the desired one. */ printf("SetVSSpeed = %d\n", SetVSSpeed(0)); /* Set our gain to the desired one. */ printf("SetPreAmpGain = %d\n", SetPreAmpGain(2)); /* Setup the read mode. I suspect this is the problem */ printf("SetReadMode = %d\n", SetReadMode(4)); /* Try to get frames like this */ printf("SetAcquisitionMode = %d\n", SetAcquisitionMode(5)); printf("PrepareAcquisition = %d\n", PrepareAcquisition()); printf("StartAcquisition %d\n", StartAcquisition()); sleep(1); printf("AbortAcquisition %d\n", AbortAcquisition()); /* This sequence seemed to work with the server */ //printf("SetHSSpeed = %d\n", SetHSSpeed(0, 1)); /* DO we get the right gain range now? */ printf("GetEMGainRange = %d\n", GetEMGainRange(&min, &max)); printf("Andor EM Gain range is %d to %d.\n", min, max); /* We wish to use Cropped mode */ printf("SetIsolatedCropMode = %d\n", SetIsolatedCropMode(1,npix,npix,1,1)); /* Set the image to read the full area of cropped region */ printf("SetImage = %d\n", SetImage(1, 1, 1, npix, 1, npix)); /* Set exposure time to 1mS */ printf("SetExposureTime = %d\n", SetExposureTime(0.001)); /* Set Kinetic Cycle time to the smallest possible value */ printf("SetKineticCycleTime = %d\n",SetKineticCycleTime(0.0)); /* OK, let's see what the frame rate is */ printf("SetAcquisitionMode = %d\n", SetAcquisitionMode(5)); printf("StartAcquisition %d\n", StartAcquisition()); sleep(1); printf("GetTotalNumberImagesAcquired = %d\n", GetTotalNumberImagesAcquired(&start_n)); sleep(5); printf("GetTotalNumberImagesAcquired = %d\n", GetTotalNumberImagesAcquired(&stop_n)); printf("Frame rate seems to be %.2f Hz\n", (double)(stop_n - start_n)/5.0); printf("AbortAcquisition = %d\n",AbortAcquisition()); /* Get one frame... it seems things work better after this */ GetStatus(&status); while(status==DRV_ACQUIRING) GetStatus(&status); printf("SaveAsFITS %d\n", SaveAsFITS("./image.fit", 4)); /* That is all */ printf("ShutDown = %d\n", ShutDown()); exit(0); }
void InitBCI() { concurrency::critical_section::scoped_lock lock(bci_mutex); std::cout << "Initializing BCI" << std::endl; if (StopAcquisition() != ID_WRONG_SEQUENCY_OF_COMMAND) { std::cerr << "Stopped previous data acquisition" << std::endl; } _DEVICE_INFO *devInfo; if (!(devInfo = GetDeviceInfo())) { throw("GetDeviceInfo() failed"); } std::cout << "ABM Device Info:" << std::endl; std::cout << "Device name: " << devInfo->chDeviceName << std::endl; std::cout << "COM Port: " << devInfo->nCommPort << std::endl; std::cout << "ECG Channel: " << devInfo->nECGPos << std::endl; std::cout << "Number of channels: " << devInfo->nNumberOfChannel << std::endl; num_channels = devInfo->nNumberOfChannel; if (num_channels < 0) { std::cerr << "ABM X10 not connected" << std::endl; ExitProcess(1); } std::stringstream destfilepath; SYSTEMTIME stime; GetLocalTime(&stime); int err; destfilepath << "data\\" << stime.wYear << "_" << stime.wMonth << "_" << stime.wDay << "_" << stime.wHour << "_" << stime.wMinute << "_" << stime.wSecond << ".ebs"; std::string dfp = destfilepath.str(); char fullpath[4096] = ""; char *pszfn = NULL; err = GetFullPathNameA(dfp.c_str(), sizeof(fullpath), fullpath, &pszfn); std::cout << "Setting destination file path to " << fullpath << std::endl; if (!(err = SetDestinationFile(fullpath))) { std::cerr << "SetDestinationFile failed! err " << err << std::endl; ExitProcess(1); } std::cout << "Initiating session..." << std::endl; if ((err = InitSession(ABM_DEVICE_X10Standard, ABM_SESSION_RAW, -1, FALSE)) != INIT_SESSION_OK) { std::cerr << "InitSession failed! err " << err << std::endl; switch (err) { case ID_WRONG_SEQUENCY_OF_COMMAND: std::cerr << "Wrong command sequence" << std::endl; break; case INIT_SESSION_NO: std::cerr << "Session initiation failed" << std::endl; break; case INIT_SESSION_NO_DESTFILE_FAILED: std::cerr << "No destination file!" << std::endl; break; } ExitProcess(1); } std::cout << "Getting channel map info" << std::endl; _CHANNELMAP_INFO channelMap; if (!GetChannelMapInfo(channelMap)) { std::cerr << "GetChannelMapInfo failed!" << std::endl; ExitProcess(1); } if (channelMap.nDeviceTypeCode != 0) { std::cerr << "ABM X10 not found! :(" << std::endl; ExitProcess(1); } _EEGCHANNELS_INFO& eegChannels = channelMap.stEEGChannels; for (int i = 0; i < channelMap.nSize; ++i) { std::cout << eegChannels.cChName[i] << " " << eegChannels.bChUsed[i] << " " << eegChannels.bChUsedInQualityData[i] << std::endl; } std::cout << "Starting acquisition..." << std::endl; if (StartAcquisition() != ACQ_STARTED_OK) { std::cerr << "StartAcquisition failed!" << std::endl; ExitProcess(1); } running = true; std::cout << "BCI initialization done!" << std::endl; }