kopia lustrzana https://github.com/RobertGawron/IonizationChamber
commit
c922a1e27d
|
@ -35,7 +35,7 @@ matrix:
|
|||
script:
|
||||
- cppcheck --enable=all --inline-suppr --force --quiet --error-exitcode=1 Src/* Inc/*
|
||||
|
||||
# Use pyflakes (or other tool) to check statically Python code
|
||||
# Use pyflakes to check statically Python code
|
||||
- language: python
|
||||
dist: xenial
|
||||
sudo: true
|
||||
|
|
|
@ -20,7 +20,7 @@ It is designed in a way that the device can work remotely, e.g. no connection vi
|
|||
|
||||
Remarks:
|
||||
* Amplifier has three stages (first stage is transimpedance amplifier, not FET like most projects use).
|
||||
* Amplifier has a separate power supply from 4x2V6 lithium batteries
|
||||
* Amplifier has a separate symmetric power supply from 2x2V6 lithium batteries
|
||||
|
||||
|
||||
## Hardware
|
||||
|
|
|
@ -4,14 +4,15 @@ import mcp3425
|
|||
class IonizationChamber:
|
||||
def __init__(self, config):
|
||||
self.config = config
|
||||
self.openSerialPort()
|
||||
|
||||
def openSerialPort(self):
|
||||
|
||||
def connect(self):
|
||||
self.serialPort = Serial(self.config.myDeviceId, baudrate = self.config.myBaudrate, timeout=None)
|
||||
self.serialPort.isOpen()
|
||||
self.serialPort.flushInput()
|
||||
|
||||
def acquireFromDevice(self):
|
||||
|
||||
def getMeasurement(self):
|
||||
dataIn = self.serialPort.read(5)
|
||||
(msb, lsb) = (dataIn[2], dataIn[3])
|
||||
deviceMeasurement = mcp3425.convert(msb, lsb, mcp3425.MCP3425_RESOLUTION.R14)
|
||||
|
|
|
@ -1,3 +1,10 @@
|
|||
# ionization chamber
|
||||
myDeviceId = '/dev/ttyUSB0'
|
||||
myBaudrate = 9600
|
||||
|
||||
# dmm
|
||||
idDMM = "USB0::0x2A8D::0x1601::INSTR"
|
||||
testCommand = "READ?"
|
||||
|
||||
|
||||
useDMM = True
|
||||
|
|
|
@ -1,30 +1,14 @@
|
|||
import datetime
|
||||
import csv
|
||||
import usbtmc
|
||||
|
||||
class DMM:
|
||||
def __init__(self, instrumentId):
|
||||
self.device = usbtmc.Instrument(instrumentId)
|
||||
|
||||
def sendCmd(self, command):
|
||||
return self.device.ask(command)
|
||||
def __init__(self, config):
|
||||
self.config = config
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
testIterations = 50000
|
||||
idDMM = "USB0::0x2A8D::0x1601::INSTR"
|
||||
testCommand = "READ?"
|
||||
plotYLabel = "voltage"
|
||||
def connect(self):
|
||||
self.device = usbtmc.Instrument(self.config.idDMM)
|
||||
|
||||
dmm = DMM(idDMM)
|
||||
|
||||
with open('SampleOutputFile.csv', mode='w') as sampleOutputFile:
|
||||
sampleOutputFileWriter = csv.writer(sampleOutputFile, delimiter=',', quotechar='"', quoting=csv.QUOTE_MINIMAL)
|
||||
sampleOutputFileWriter.writerow(["Timestamp", "Measurement"])
|
||||
def getMeasurement(self):
|
||||
return self.device.ask(self.config.testCommand)
|
||||
|
||||
while(True):
|
||||
sampleData = float(dmm.sendCmd(testCommand))
|
||||
now = datetime.datetime.now()
|
||||
|
||||
sampleOutputFileWriter.writerow([now, sampleData])
|
||||
sampleOutputFile.flush()
|
|
@ -8,9 +8,8 @@ Sys.setenv(LANG = "en")
|
|||
drawDiagramSingle <- function(samples) {
|
||||
|
||||
# date column should be type of date, not string, so parse it
|
||||
png(filename = paste0("results-", format(Sys.time(), "%d_%b_%Y_%H_%M"), ".png"), width = 800, height = 900, bg = "white")
|
||||
|
||||
# create graphs
|
||||
png(filename = paste0("results-", format(Sys.time(), "%d_%b_%Y_%H_%M"), ".png"),
|
||||
width = 800, height = 900, bg = "white")
|
||||
|
||||
samples$Time = as.POSIXct(samples$Time, format="%Y-%m-%d %H:%M:%S.%OS")
|
||||
|
||||
|
@ -21,8 +20,7 @@ drawDiagramSingle <- function(samples) {
|
|||
grid = TRUE,
|
||||
col.line = "black",
|
||||
ylab = "counts per minute",
|
||||
ylim=c(min(samples$Counter), max(samples$Counter)),
|
||||
|
||||
ylim=c(min(samples$Counter), max(samples$Counter)),
|
||||
xlim=c(min(samples$Time), max(samples$Time)),
|
||||
main = "Change over time")
|
||||
|
||||
|
|
|
@ -9,3 +9,7 @@ samples <- read.delim(inputFileName, , sep=",")
|
|||
|
||||
drawDiagramSingle(samples)
|
||||
|
||||
# TODO move to a separate module
|
||||
library(Hmisc)
|
||||
rcorr(samples$Counter,samples$DMM, type="pearson")
|
||||
|
||||
|
|
|
@ -1,38 +1,72 @@
|
|||
import datetime
|
||||
|
||||
from IonizationChamber import IonizationChamber
|
||||
from dmm import DMM
|
||||
import config
|
||||
|
||||
class IonizationChamberStateMachine:
|
||||
def __init__(self, config):
|
||||
self.config = config
|
||||
self.chamber = IonizationChamber(config)
|
||||
self.deviceMeasurement = 0.0
|
||||
self.dmmMeasurement = 0.0
|
||||
|
||||
self.nextState = self.initIonizationChamber
|
||||
|
||||
|
||||
def tick(self):
|
||||
self.nextState()
|
||||
|
||||
|
||||
def initIonizationChamber(self):
|
||||
self.chamber.openSerialPort()
|
||||
self.chamber = IonizationChamber(config)
|
||||
self.chamber.connect()
|
||||
|
||||
if config.useDMM:
|
||||
self.nextState = self.initDMM
|
||||
else:
|
||||
self.nextState = self.initOutputFile
|
||||
|
||||
|
||||
def initDMM(self):
|
||||
self.dmm = DMM(config)
|
||||
self.dmm.connect()
|
||||
|
||||
self.nextState = self.initOutputFile
|
||||
|
||||
|
||||
def initOutputFile(self):
|
||||
self.logFile = open('data.csv', 'w')
|
||||
self.logFile.write("Time,Counter\n")
|
||||
self.logFile.write("Time,Counter,DMM\n")
|
||||
|
||||
self.nextState = self.getMeasurementFromIonizationChamber
|
||||
|
||||
|
||||
def getMeasurementFromIonizationChamber(self):
|
||||
self.deviceMeasurement = self.chamber.acquireFromDevice()
|
||||
self.deviceMeasurement = self.chamber.getMeasurement()
|
||||
|
||||
if config.useDMM:
|
||||
self.nextState = self.getMeasurementFromDMM
|
||||
else:
|
||||
self.nextState = self.saveMeasurement
|
||||
|
||||
|
||||
def getMeasurementFromDMM(self):
|
||||
self.dmmMeasurement = self.dmm.getMeasurement()
|
||||
|
||||
self.nextState = self.saveMeasurement
|
||||
|
||||
|
||||
def saveMeasurement(self):
|
||||
now = datetime.datetime.now()
|
||||
self.logFile.write("{0},{1}\n".format(now, self.deviceMeasurement))
|
||||
self.logFile.write("{0},{1},{2}\n".format(now, self.deviceMeasurement, self.dmmMeasurement))
|
||||
self.logFile.flush()
|
||||
|
||||
self.nextState = self.showMeasurementToUser
|
||||
|
||||
|
||||
def showMeasurementToUser(self):
|
||||
print(self.deviceMeasurement)
|
||||
print("{0}, {1}".format(self.deviceMeasurement, self.dmmMeasurement))
|
||||
|
||||
self.nextState = self.getMeasurementFromIonizationChamber
|
||||
|
||||
|
||||
|
|
Ładowanie…
Reference in New Issue