def gainscan(idx): gainnum = 1 #where_i_was=acsc.getRPosition(hcomm,0) acsc.toPoint(hcomm, None, 0, gain_z_out_of_beam) # while(abs(acsc.getFVelocity(hcomm, 0))>wait_ms): # 1+1 while (not acsc.getMotorState(hcomm, 0)['in position'] ): #check for stop event using other API call? time.sleep(.1) while (gainnum < num_gain_per_scan): mmc.snapImage() image_npy = mmc.getImage() image_itk = sitk.GetImageFromArray(image_npy) sitk.WriteImage( image_itk, output_dir + "\\gain\\gain_" + str(idx) + "_" + str(gainnum) + ".tiff" ) #Change this to Gainscan_"+str(idx)+".tiff" if you would rather sort by time and not filename dt = datetime.now() micro = dt.microsecond time_temp = time.strftime("%Y%m%d-%H%M%S") + ":" + str(micro) file_output.write("gain_%d\t%f\t%f\t%f\t%s\t%s\t%d\n" % (idx, 0, acsc.getRPosition(hcomm, 1), acsc.getFPosition(hcomm, 1), time_temp, (datetime.now() - startTime), exposure_inpt)) gainnum = gainnum + 1 acsc.toPoint(hcomm, None, 0, where_i_was) # while(abs(acsc.getFVelocity(hcomm, 0))>wait_ms): # 1+1 while (not acsc.getMotorState(hcomm, 0)['in position'] ): #check for stop event using other API call? time.sleep(.1)
def run(self): """Start the run. Comms should be open already with the controller.""" if acsc.getOutput(self.hc, 1, 16): acsc.setOutput(self.hc, 1, 16, 0) if self.vectrino: acsc.enable(self.hc, 0) acsc.enable(self.hc, 1) while not acsc.getMotorState(self.hc, 0)["enabled"] or not \ acsc.getMotorState(self.hc, 1)["enabled"]: self.msleep(100) acsc.toPoint(self.hc, None, 0, self.y_R * self.R) acsc.toPoint(self.hc, None, 1, self.z_H * self.H) while not acsc.getMotorState(self.hc, 0)["in position"] or not \ acsc.getMotorState(self.hc, 1)["in position"]: self.msleep(300) print("y- and z-axes in position") acsc.disable(self.hc, 0) acsc.disable(self.hc, 1) self.vec.serial_port = "COM2" self.vec.connect() tstart = time.time() self.timeout = False self.vecstatus = "Connecting to Vectrino..." while not self.vec.connected: self.msleep(300) if time.time() - tstart > 10: print("Vectrino timed out") self.timeout = True break if not self.timeout: self.vec.stop() self.setvecconfig() if self.recordvno: self.vec.start_disk_recording(self.vecsavepath) self.vec.start() self.vecstatus = "Vectrino connected " while self.vec.state != "Confirmation mode": self.msleep(100) print("Vectrino in data collection mode") print("Waiting 6 seconds") self.sleep(6) self.daqthread.start() if self.fbg: self.fbgthread.start() self.start_motion() elif self.nidaq: self.daqthread.start() if self.fbg: self.fbgthread.start() self.start_motion() else: # Start motion self.start_motion()
def run(self): """Start the run. Comms should be open already with the controller.""" if acsc.getOutput(self.hc, 1, 16): acsc.setOutput(self.hc, 1, 16, 0) if self.vectrino: acsc.enable(self.hc, 0) acsc.enable(self.hc, 1) while not acsc.getMotorState(self.hc, 0)["enabled"] or not \ acsc.getMotorState(self.hc, 1)["enabled"]: self.msleep(100) acsc.toPoint(self.hc, None, 0, self.y_R*self.R) acsc.toPoint(self.hc, None, 1, self.z_H*self.H) while not acsc.getMotorState(self.hc, 0)["in position"] or not \ acsc.getMotorState(self.hc, 1)["in position"]: self.msleep(300) print("y- and z-axes in position") acsc.disable(self.hc, 0) acsc.disable(self.hc, 1) self.vec.serial_port = "COM2" self.vec.connect() tstart = time.time() self.timeout = False self.vecstatus = "Connecting to Vectrino..." while not self.vec.connected: self.msleep(300) if time.time() - tstart > 10: print("Vectrino timed out") self.timeout = True break if not self.timeout: self.vec.stop() self.setvecconfig() if self.recordvno: self.vec.start_disk_recording(self.vecsavepath) self.vec.start() self.vecstatus = "Vectrino connected " while self.vec.state != "Confirmation mode": self.msleep(100) print("Vectrino in data collection mode") print("Waiting 6 seconds") self.sleep(6) self.daqthread.start() if self.fbg: self.fbgthread.start() self.start_motion() elif self.nidaq: self.daqthread.start() if self.fbg: self.fbgthread.start() self.start_motion() else: # Start motion self.start_motion()
then uploading it to the controller and running it. """ from __future__ import division, print_function from acspy import acsc import time #file = open("test/test.prg", "w+") acs_prg = """ ENABLE 1""" + \ """ VEL(1) = 1000 PTP/r 1, -900 STOP """ #file.write(acs_prg) #file.close() print(acs_prg) hc = acsc.openCommDirect() acsc.loadBuffer(hc, 0, acs_prg, 512) acsc.enable(hc, 0) #acsc.LoadBuffersFromFile(hc, "test/test.prg") acsc.runBuffer(hc, 0) time.sleep(1) print(acsc.getRPosition(hc, 1)) print(acsc.getMotorState(hc, 1)) acsc.closeComm(hc)
#exposure=60 mmc.setExposure(exposure_inpt) mmc.setProperty(device_id, "Binning", binning_value) print(mmc.getProperty(device_id, "Binning")) os.chdir(prev_dir) ################## ###camera calls### ################## #load in 10k devices if load_camera10k: camefile_path = "C:\\Users\\ChengLab\\Desktop\\MP71Camera\\VP-71MC-M5_P200SC_4tap(H)_12bit_RG (VST Y12).cam" #Actually do the imaging if do_scan: while (not acsc.getMotorState(hcomm, 1)['in position'] ): #check for stop event using other API call? time.sleep(.1) for focal_idx, focal_position in enumerate(focal_step_mtx): projection_fill[focal_idx] = take_photo(1, 1, focal_position) print("projecting at " + str(focal_position)) where_i_was = acsc.getRPosition(hcomm, 0) acsc.toPoint(hcomm, None, 0, gain_z_out_of_beam) while (not acsc.getMotorState(hcomm, 0)['in position'] ): #check for stop event using other API call? time.sleep(.1) if scan_gain: for focal_idx, focal_position in enumerate(focal_step_mtx): gain_fill[focal_idx] = gainscan(1, focal_position) print("projecting at " + str(focal_position))
def motor_state(self): """Returns motor state dict.""" return acsc.getMotorState(self.controller.hc, self.axisno)
def take_drift_correction_photo(deg): move_stage(0) moving = True # while(abs(acsc.getFVelocity(hcomm, 1))>wait_ms): #check for stop event using other API call? # 1+1 while (not acsc.getMotorState(hcomm, 1)['in position'] ): #check for stop event using other API call? time.sleep(.1) for projnum in range(num_exposures_per_projection): print("Projection average %d out of %d" % (projnum + 1, num_exposures_per_projection)) if load_camera10k: print("Projection %d out of %d" % (projnum + 1, num_exposures_per_projection)) # image_npy,channel_temp=GrabOneImage(channel) s2 = datetime.now() MC.SetParamStr(channel, 'ChannelState', 'ACTIVE') gotEndOfChannelActivity = False gotAcquisitionFailure = False while not gotEndOfChannelActivity: signalInfo = MC.WaitSignal( channel, MC.SIG_ANY, 15000 ) #Attempt to make this call shorter (1.5 second overhead as written....) # signalInfo = MC.WaitSignal(channel, MC.SIG_ANY, 1000) if signalInfo.Signal == MC.SIG_END_CHANNEL_ACTIVITY: gotEndOfChannelActivity = True elif signalInfo.Signal == MC.SIG_ACQUISITION_FAILURE: gotAcquisitionFailure = True elif signalInfo.Signal == MC.SIG_SURFACE_PROCESSING: MC.SetParamStr(signalInfo.SignalInfo, 'SurfaceState', 'FREE') else: raise MC.MultiCamError('Unexpected signal: %d' % signalInfo.Signal) # MC.SetParamStr(channel, "ForceTrig", "TRIG"); if gotAcquisitionFailure: raise MC.MultiCamError('Acquisition failure!') surface = MC.GetParamInst(channel, 'Cluster:0') width = MC.GetParamInt(surface, 'SurfaceSizeX') height = MC.GetParamInt(surface, 'SurfaceSizeY') # image = ConvertSurfaceIntoImage(surface) surfaceAddress = MC.GetParamPtr(surface, 'SurfaceAddr:%d' % planeIndex) surfaceSize = MC.GetParamInt(surface, 'SurfaceSize:%d' % planeIndex) imageBuffer = ctypes.string_at(surfaceAddress, surfaceSize) MC.SetParamStr(channel, 'ChannelState', 'READY') data = np.fromstring(imageBuffer, np.uint16) image_npy = np.reshape(data, (height, width)) # image = ConvertBufferIntoImage(width, height, imageBuffer) # print(image.shape) # print(image[0].shape) # channel_temp=channel print(str(datetime.now() - s2) + " single proj") else: mmc.snapImage() image_npy = mmc.getImage() projection_fill[projnum] = image_npy proj = np.mean(projection_fill, axis=0) # image_itk = sitk.GetImageFromArray(proj) #sitk.WriteImage(image_itk, output_dir+"/Projection_"+str(idx)+".tiff") dx.write_tiff(proj, output_dir + "//Drift_Projections_at_0deg/Correction_Projection_from_" + str(int(np.where(degrees_array == deg)[0][0])) + ".tiff", dtype=np.uint16) move_stage(deg) # while(abs(acsc.getFVelocity(hcomm, 1))>wait_ms): #check for stop event using other API call? # 1+1 while (not acsc.getMotorState(hcomm, 1)['in position'] ): #check for stop event using other API call? time.sleep(.1)
""" This is a test for generating an ACSPL+ program then uploading it to the controller and running it. """ from acspy import acsc import time #file = open("test/test.prg", "w+") acs_prg = """ ENABLE 1""" + \ """ VEL(1) = 1000 PTP/r 1, -900 STOP """ #file.write(acs_prg) #file.close() print acs_prg hc = acsc.openCommDirect() acsc.loadBuffer(hc, 0, acs_prg, 512) acsc.enable(hc, 0) #acsc.LoadBuffersFromFile(hc, "test/test.prg") acsc.runBuffer(hc, 0) time.sleep(1) print acsc.getRPosition(hc, 1) print acsc.getMotorState(hc, 1) acsc.closeComm(hc)