WorldViz User Forum  

Go Back   WorldViz User Forum > Vizard

 
 
Thread Tools Rate Thread Display Modes
Prev Previous Post   Next Post Next
  #3  
Old 09-21-2012, 11:32 AM
mhead10 mhead10 is offline
Member
 
Join Date: Mar 2012
Posts: 40
import ctypes
import numpy
import viztask
import time
import threading
nidaq = ctypes.windll.nicaiu # load the DLL
viz.go()

int32 = ctypes.c_long
uInt32 = ctypes.c_ulong
uInt64 = ctypes.c_ulonglong
float64 = ctypes.c_double
TaskHandle = uInt32
read = int32()
# the constants
DAQmx_Val_Cfg_Default = int32(-1)
DAQmx_Val_Volts = 10348
DAQmx_Val_Rising = 10280
DAQmx_Val_FiniteSamps = 10178
DAQmx_Val_ContSamps = 10123
DAQmx_Val_GroupByChannel = 0
DAQmx_Val_GroupByScanNumber= 1 #interleaved
##############################
# initialize variables
taskHandle = TaskHandle(0)
max_num_samples = 2
data = numpy.zeros((max_num_samples,),dtype=numpy.float64 )

print
def CHK(err):
if err < 0:
buf_size = 100
buf = ctypes.create_string_buffer('\000' * buf_size)
nidaq.DAQmxGetErrorString(err,ctypes.byref(buf),bu f_size)
raise RuntimeError('nidaq call failed with error %d: %s'%(err,repr(buf.value)))

#Main Program
CHK(nidaq.DAQmxCreateTask("",ctypes.byref(taskHand le)))
CHK(nidaq.DAQmxCreateAIVoltageChan(taskHandle,"Dev 2/ai0:1","",DAQmx_Val_Cfg_Default,float64(-13.0),float64(13.0),DAQmx_Val_Volts,None))
CHK(nidaq.DAQmxCfgSampClkTiming(taskHandle,"",floa t64(1),DAQmx_Val_Rising,DAQmx_Val_ContSamps,uInt64 (max_num_samples))); #(samples/sec/channel) #ContSamps
CHK(nidaq.DAQmxStartTask(taskHandle))

# stop/clear when I want to end program by mouseclick
def onMouseDown(button):
if button == viz.MOUSEBUTTON_LEFT:
CHK(nidaq.DAQmxStopTask(taskHandle))
CHK(nidaq.DAQmxClearTask(taskHandle))
viz.callback(viz.MOUSEDOWN_EVENT,onMouseDown)

def obtain_value():# continuosly read the DAQ values
CHK(nidaq.DAQmxReadAnalogF64(taskHandle,1,float64(-1),DAQmx_Val_GroupByChannel,data.ctypes.data,max_n um_samples,ctypes.byref(read),None))
print data

x=0
def loop(): # loop which call for DAQ values to continuosly be read
while x < 10:
obtain_value()
viz.director(loop)

viz.clearcolor(1,0,0) #proves I can use vizard interface with continuous data aquisition

# add haptics
sensable=viz.add('sensable3.dle')
device = sensable.addHapticDevice(name = 'Left')
device.workspace.setScale([100,100,100])
device.workspace.setPosition([0,0,0])
[/CODE]
Reply With Quote
 


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Creating a Vizard Sensor Plugin farshizzo Plug-in development 25 08-01-2019 12:24 AM
Sensable Open Haptics-"Failed to load plug-in: 'sensable3.dle'" mhead10 Vizard 2 09-04-2012 01:40 PM
Could not find plugin to load objects... halley Vizard 1 05-30-2006 11:01 AM


All times are GMT -7. The time now is 09:37 AM.


Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2025, vBulletin Solutions, Inc.
Copyright 2002-2023 WorldViz LLC