def update_stream_out_buffer(handle, out_context): # Write values to the stream-out buffer. Note that once a set of values have # been written to the stream out buffer (STREAM_OUT0_BUFFER_F32, for # example) and STREAM_OUT#_SET_LOOP has been set, that set of values will # continue to be output in order and will not be interrupted until their # "loop" is complete. Only once that set of values have been output in their # entirety will the next set of values that have been set using # STREAM_OUT#_SET_LOOP start being used. out_names = out_context["names"] ljm.eWriteName(handle, out_names["loop_size"], out_context["state_size"]) state_index = out_context["current_index"] error_address = -1 current_state = out_context["states"][state_index] values = current_state["values"] info = ljm.getHandleInfo(handle) max_bytes = info[5] SINGLE_ARRAY_SEND_MAX_BYTES = 520 if max_bytes > SINGLE_ARRAY_SEND_MAX_BYTES: max_bytes = SINGLE_ARRAY_SEND_MAX_BYTES NUM_HEADER_BYTES = 12 NUM_BYTES_PER_F32 = 4 max_samples = int((max_bytes - NUM_HEADER_BYTES) / NUM_BYTES_PER_F32) start = 0 while start < len(values): num_samples = len(values) - start if num_samples > max_samples: num_samples = max_samples end = start + num_samples write_values = values[start:end] ljm.eWriteNameArray(handle, out_names["buffer"], num_samples, write_values) start = start + num_samples ljm.eWriteName(handle, out_names["set_loop"], out_context["set_loop"]) print(" Wrote " + \ out_context["names"]["stream_out"] + \ " state: " + \ current_state["state_name"] ) # Increment the state and wrap it back to zero out_context["current_index"] = (state_index + 1) % len( out_context["states"])
def update_stream_out_buffer(handle, out_context): # Write values to the stream-out buffer. Note that once a set of values have # been written to the stream out buffer (STREAM_OUT0_BUFFER_F32, for # example) and STREAM_OUT#_SET_LOOP has been set, that set of values will # continue to be output in order and will not be interrupted until their # "loop" is complete. Only once that set of values have been output in their # entirety will the next set of values that have been set using # STREAM_OUT#_SET_LOOP start being used. out_names = out_context["names"] ljm.eWriteName(handle, out_names["loop_size"], out_context["state_size"]) state_index = out_context["current_index"] error_address = -1 current_state = out_context["states"][state_index] values = current_state["values"] info = ljm.getHandleInfo(handle) max_bytes = info[5] SINGLE_ARRAY_SEND_MAX_BYTES = 520 if max_bytes > SINGLE_ARRAY_SEND_MAX_BYTES: max_bytes = SINGLE_ARRAY_SEND_MAX_BYTES NUM_HEADER_BYTES = 12 NUM_BYTES_PER_F32 = 4 max_samples = int((max_bytes - NUM_HEADER_BYTES) / NUM_BYTES_PER_F32) start = 0 while start < len(values): num_samples = len(values) - start if num_samples > max_samples: num_samples = max_samples end = start + num_samples write_values = values[start:end] ljm.eWriteNameArray(handle, out_names["buffer"], num_samples, write_values) start = start + num_samples ljm.eWriteName(handle, out_names["set_loop"], out_context["set_loop"]) print(" Wrote " + \ out_context["names"]["stream_out"] + \ " state: " + \ current_state["state_name"] ) # Increment the state and wrap it back to zero out_context["current_index"] = (state_index + 1) % len(out_context["states"])
def initialise_streamout(handle,waveform,size=1): '''Intialise a labjack handle object open for Stream-Out with a buffer sufficient for a loop size of 127 values on DAC0 from a waveform iterable given. If the loop is bigger than 127, specify the multiplier with the size variable''' #Writing constants for Stream-Out ljm.eWriteName(handle,"STREAM_OUT0_ENABLE",0) ljm.eWriteName(handle,"STREAM_OUT0_TARGET",1000) ljm.eWriteName(handle,"STREAM_OUT0_BUFFER_SIZE",256*size) ljm.eWriteName(handle,"STREAM_OUT0_ENABLE",1) #Writing the waveform onto the labjack ljm.eWriteName(handle,"STREAM_OUT0_LOOP_SIZE",size*127) for x in range(size): ljm.eWriteNameArray(handle,"STREAM_OUT0_BUFFER_F32",127,waveform[x*128:(x+1)*127]) ljm.eWriteName(handle,"STREAM_OUT0_SET_LOOP",1)
handle = ljm.openS("T7", "ETHERNET", "470010370") #Writing constants for Stream-Out ljm.eWriteName(handle, "STREAM_OUT0_ENABLE", 0) ljm.eWriteName(handle, "STREAM_OUT0_TARGET", 1000) ljm.eWriteName(handle, "STREAM_OUT0_BUFFER_SIZE", 2048) ljm.eWriteName(handle, "STREAM_OUT0_ENABLE", 1) size = 1 val = np.arange(2.5, 5, 2.5 / (size * 128)) #Writing the waveform onto the labjack ljm.eWriteName(handle, "STREAM_OUT0_LOOP_SIZE", size * 127) for x in range(4): ljm.eWriteNameArray(handle, "STREAM_OUT0_BUFFER_F32", 127, val[x * 128:(x + 1) * 127]) ljm.eWriteName(handle, "STREAM_OUT0_SET_LOOP", 1) ljm.eStreamStart(handle, size * 127, 2, [4800, 0], 150) for x in range(2): read = ljm.eStreamRead(handle) data = np.append(data, read[0][0:size * 127]) print x ljm.eStreamStop(handle) print("Stream finished") theospace = np.linspace(size * 127, 2 * size * 127, size * 127) slope = ((2.5 * theospace) / (size * 127)) space = np.linspace(2.5, 5, size * 127)
#Paramters for acquisition scanres = int(args.scantime * int(127)) data = [] #Opening labjack and generating handle object handle = ljm.openS("T7","ETHERNET","470010370") #Writing constants for Stream-Out ljm.eWriteName(handle, "STREAM_OUT0_ENABLE",0) ljm.eWriteName(handle,"STREAM_OUT0_TARGET",1000) ljm.eWriteName(handle,"STREAM_OUT0_BUFFER_SIZE",256) ljm.eWriteName(handle,"STREAM_OUT0_ENABLE",1) #Writing the waveform onto the labjack ljm.eWriteName(handle,"STREAM_OUT0_LOOP_SIZE",127) ljm.eWriteNameArray(handle,"STREAM_OUT0_BUFFER_F32",127,val[0:127]) ljm.eWriteName(handle,"STREAM_OUT0_SET_LOOP",1) #Start streaming. 4800 is Stream-Out. 0 is Stream-In ljm.eStreamStart(handle,scanres,2,[4800,2],fqreal*127) for i in range(args.acqtime): read = ljm.eStreamRead(handle) data.append(read[0][0:scanres]) if args.verbosity >0: print(ljm.eStreamRead(handle)[1:]) ljm.eStreamStop(handle) ljm.close(handle)
def ctrl_antenna_motor(self, state): if state in DRIVE_BITS: bits = DRIVE_BITS[state] ljm.eWriteNameArray(self.lj_handle, port.DRIVE, len(bits), bits)