1 Star 0 Fork 0

Pysaoke/Advantech_Qt

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
Ads_DAQ.py 2.48 KB
一键复制 编辑 原始数据 按行查看 历史
Pysaoke 提交于 2014-12-30 16:33 . 添加了QThread测试窗口
#!/usr/bin/env python
# -*- coding: utf-8 -*-
'''Advantech DAQ Thread'''
__author__ = 'baixue'
from PyQt4 import QtCore
from Adsapi import *
class DAQ_Task(QtCore.QThread):
signal_DAQ = QtCore.pyqtSignal(list)
def __init__(self, parent=None):
super(DAQ_Task, self).__init__(parent)
self.DriverHandle = 0
self.usINTBuf = None # int buffer
self.pUserBuf = None # user buffer
self.count = 200
self.working = False
def __del__(self):
self.working = False
def start(self, DeviceNum=0, sampleRate=1000, startChan=0, numChans=2, gains=None, count=200):
self.count = count
self.numChans = numChans
try:
# Open device
self.DriverHandle = DRV_DeviceOpen(DeviceNum)
# Enable event
DRV_EnableEvent(self.DriverHandle, EventType=0xf, Enabled=1, Count=512)
# Allocate INT & data buffer for interrupt transfer
self.usINTBuf, self.pUserBuf = AllocateDataBuffer(count)
# Start interrupt transfer
DRV_FAIIntScanStart(self.DriverHandle, sampleRate, numChans, startChan, count, self.usINTBuf, gains, cyclic=1)
except Ads_Error, e:
self.quit()
else:
self.working = True
super(DAQ_Task, self).start()
def run(self):
while True:
FAIEvent = WaitFAIEvent(self.DriverHandle, timeout=3000)
AI_Terminated = FAIEvent[0]
if AI_Terminated == True:break
AI_BufferHalfReady, AI_BufferFullReady = FAIEvent[1:3]
if AI_BufferHalfReady | AI_BufferFullReady:
overRun = DRV_FAITransfer(self.DriverHandle, self.pUserBuf, self.count)
if overRun != 0:
DRV_ClearOverrun(self.DriverHandle)
data = GetBufferData(self.pUserBuf, self.count)
data = SplitArray1DTo2D(data, self.numChans)
# emit signal
signal_DAQ.emit(data)
def terminate(self):
DRV_FAITerminate(self.DriverHandle)
# Stop A/D conversion for high speed
DRV_FAIStop(self.DriverHandle)
# Close device
DRV_DeviceClose(self.DriverHandle)
super(DAQ_Task, self).terminate()
def stop(self):
DRV_FAITerminate(self.DriverHandle)
# Stop A/D conversion for high speed
DRV_FAIStop(self.DriverHandle)
# Close device
DRV_DeviceClose(self.DriverHandle)
self.wait()
if __name__ == "__main__":
pass
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/baixue/Advantech_Qt.git
[email protected]:baixue/Advantech_Qt.git
baixue
Advantech_Qt
Advantech_Qt
master

搜索帮助