forked from ODZ-UJF-AV-CR/osciloskop
-
Notifications
You must be signed in to change notification settings - Fork 0
/
blesk.py
executable file
·98 lines (76 loc) · 2.14 KB
/
blesk.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
#!/usr/bin/env python
import matplotlib.pyplot as plt
import sys
import os
import time
import h5py
import numpy as np
import ublox # pyUblox librarie
import util
import datetime
# TRYING TO ADAPT THE SCRIPT FOR THE MICSIG oscilloscope
# Create ownership rule as /etc/udev/rules.d/99-micsig.rules
# SUBSYSTEMS=="usb", ATTRS{idVendor}=="18d1", ATTRS{idProduct}=="0303", GROUP="medved", MODE="0666"
class UsbTmcDriver:
def __init__(self, device):
self.device = device
self.FILE = os.open(device, os.O_RDWR)
def write(self, command):
os.write(self.FILE, command);
def read(self, length = 2048):
return os.read(self.FILE, length)
def getName(self):
self.write("*IDN?")
return self.read(300)
def sendReset(self):
self.write("*RST") # Be carefull, this real resets an oscilloscope
# Looking for USBTMC device
def getDeviceList():
dirList=os.listdir("/dev")
result=list()
for fname in dirList:
if(fname.startswith("usbtmc")):
result.append("/dev/" + fname)
return result
# looking for oscilloscope
devices = getDeviceList()
# initiate oscilloscope
osc = UsbTmcDriver(devices[0])
print "$OSC,", osc.getName(),
osc.write("MENU:RUN")
gpsport = '/dev/ttyACM0'
gpsbaudrate = 9600
# Open GPS port
dev = ublox.UBlox(gpsport, baudrate=gpsbaudrate, timeout=0)
try:
# Read GPS messages, if any
while True:
msg = dev.receive_message()
if (msg is None):
pass#break
else:
if msg.name() == 'TIM_TM2':
#print('Got TM2 message')
try:
msg.unpack()
timestring = '$HIT,'
timestring += str(msg.count)
timestring += ','
timestring += str(datetime.datetime.utcnow())
timestring += ','
timestring += str(datetime.datetime.utcfromtimestamp(util.gpsTimeToTime(msg.wnR, 1.0e-3*msg.towMsR)))
print(timestring)
sys.stdout.flush()
osc.write("MENU:STOP")
time.sleep(1)
osc.write(':STORage:CAPTure')
time.sleep(2)
#osc.write(':STORage:SAVECH1,UDISK')
#time.sleep(5)
osc.write("MENU:RUN")
#time.sleep(.1s)
except ublox.UBloxError as e:
print(e)
#break;
except:
dev.close()