cmd line version working
This commit is contained in:
commit
5110d0cff8
6 changed files with 5498 additions and 0 deletions
187
async-stream-tutorial.py
Normal file
187
async-stream-tutorial.py
Normal file
|
|
@ -0,0 +1,187 @@
|
|||
import argparse
|
||||
import csv
|
||||
import asyncio
|
||||
import serial_asyncio
|
||||
|
||||
parser = argparse.ArgumentParser()
|
||||
parser.add_argument("-o", "--output", default="data.csv", help="output csv file name")
|
||||
parser.add_argument("-d", "--device", help="serial communication port name", required=True)
|
||||
parser.add_argument("-t", "--time", default=60, type=int, help="sampling time in seconds")
|
||||
parser.add_argument("-g", "--debug", action='store_true')
|
||||
|
||||
args = parser.parse_args()
|
||||
print (args)
|
||||
|
||||
is_debug = args.debug
|
||||
device = args.device
|
||||
|
||||
ntc = 13
|
||||
nreq = ntc + 3
|
||||
|
||||
tsample = args.time
|
||||
period = 2. # sec, sampling period
|
||||
nsample = (tsample/period)
|
||||
eol = bytes.fromhex("2A")
|
||||
|
||||
q = asyncio.Queue()
|
||||
|
||||
|
||||
output_file = open(args.output, 'w')
|
||||
outputwriter = csv.writer(output_file, delimiter=',')
|
||||
outputwriter.writerow(["time", "T_ref"] + ["T_{}".format(i) for i in range(ntc)])
|
||||
output_file.flush()
|
||||
|
||||
def get_return_type (b):
|
||||
l = len(b)
|
||||
if b[0] == 0x0D :
|
||||
l = -1
|
||||
elif b[0] == 0x45 :
|
||||
l = 3
|
||||
elif b[0] == 0x43 :
|
||||
l = -1
|
||||
elif b[0] == 0x33 :
|
||||
l = l + 2
|
||||
elif b[0] == 0x4B :
|
||||
l = 4 * nreq + 9 + 4
|
||||
|
||||
return l
|
||||
|
||||
def parse_time(msg):
|
||||
minutes = int.from_bytes(msg[0:2], byteorder='big')
|
||||
hh = minutes // 60
|
||||
mm = minutes - hh * 60
|
||||
ss = int.from_bytes(msg[2:4], byteorder='big') / 10.
|
||||
return hh,mm,ss
|
||||
|
||||
def decode_campbell_float(m):
|
||||
exponent = (m[0] & (128-1)) - 64
|
||||
sign = -1 if m[0] & 128 > 0 else 1
|
||||
mantissa = int.from_bytes(m[1:], byteorder='big')/16777216
|
||||
val = sign * mantissa * (2**exponent)
|
||||
return val
|
||||
|
||||
def parse_data(msg):
|
||||
return ([decode_campbell_float(msg[i:i+4]) for i in range(0,len(msg),4)])
|
||||
|
||||
def parse_binary(msg):
|
||||
time = parse_time(msg[3:7])
|
||||
data = parse_data(msg[9:9+4*nreq])
|
||||
return (time, data)
|
||||
|
||||
parse_data(bytes.fromhex("BF820C49"))
|
||||
|
||||
|
||||
async def main(loop):
|
||||
reader, writer = await serial_asyncio.open_serial_connection(url=device, baudrate=9600)
|
||||
if is_debug: print('Reader created')
|
||||
if is_debug: print('Writer created')
|
||||
|
||||
#writer.write(bytes.fromhex("0D"))
|
||||
a = bytes.fromhex("430D")
|
||||
|
||||
input_loc_request = "".join(
|
||||
["004000"]
|
||||
+ ["{:02X}".format(i+1) for i in range(nreq)]
|
||||
+ ["00"]
|
||||
)
|
||||
|
||||
raw_messages = [
|
||||
"430D",
|
||||
"430D",
|
||||
"333134324A0D",
|
||||
input_loc_request,
|
||||
#"0040000102030405060708090A0B0C0D0E0F101112131415161718191A1B1C00",
|
||||
] + [ "4B0D" for i in range(int(nsample)) ]
|
||||
|
||||
messages = list(map(bytes.fromhex, raw_messages))
|
||||
|
||||
'''
|
||||
print(bytes.fromhex("0D0D"), get_return_type(bytes.fromhex("0D0D")))
|
||||
for msg in messages:
|
||||
print(msg, get_return_type(msg))
|
||||
'''
|
||||
|
||||
# Begin Communication
|
||||
msg = bytes.fromhex("0D")
|
||||
await q.put(get_return_type(msg))
|
||||
writer.write(msg)
|
||||
await asyncio.sleep(1.0)
|
||||
writer.write(msg)
|
||||
await asyncio.sleep(1.0)
|
||||
|
||||
sent = send(writer, messages)
|
||||
received = recv(reader)
|
||||
await asyncio.wait([sent, received])
|
||||
|
||||
|
||||
async def send(w, msgs):
|
||||
# msg = msgs[0]
|
||||
|
||||
for msg in msgs:
|
||||
# while True:
|
||||
# print(msg, get_return_type(msg))
|
||||
await q.put(get_return_type(msg))
|
||||
w.write(msg)
|
||||
if is_debug: print('DEBUG> message sent: ', msg)
|
||||
# print(f'sent: {msg.decode().rstrip()}')
|
||||
await asyncio.sleep(period)
|
||||
|
||||
await q.put(get_return_type((bytes.fromhex("450D"))))
|
||||
w.write(bytes.fromhex("450D"))
|
||||
if is_debug: print('DEBUG> Done sending')
|
||||
|
||||
|
||||
async def recv(r):
|
||||
while True:
|
||||
rtype = await q.get()
|
||||
|
||||
if rtype < 0 :
|
||||
msg = await r.readuntil(eol)
|
||||
else:
|
||||
if is_debug: print("DEBUG> Reading ", rtype, " bytes")
|
||||
msg = await r.readexactly(rtype)
|
||||
|
||||
if is_debug: print('DEBUG> message received: ', msg[0], msg)
|
||||
|
||||
if msg[0] == 75:
|
||||
time, data = parse_binary(msg)
|
||||
hhmmss = "{0[0]}:{0[1]}:{0[2]}".format(time)
|
||||
if is_debug: print ("DEBUG> time {0[0]}:{0[1]}:{0[2]}".format(time))
|
||||
if is_debug: print ("DEBUG> data {}".format(data))
|
||||
outputwriter.writerow([hhmmss] + data[2:])
|
||||
output_file.flush()
|
||||
|
||||
if msg == b'E\r\n':
|
||||
if is_debug: print('DEBUG> Done receiving')
|
||||
break
|
||||
|
||||
|
||||
loop = asyncio.get_event_loop()
|
||||
loop.run_until_complete(main(loop))
|
||||
loop.close()
|
||||
|
||||
|
||||
|
||||
'''
|
||||
41 0D A.
|
||||
|
||||
33 31 34 32 4A 0D 3142J.
|
||||
|
||||
00 40 00 00 .@..
|
||||
|
||||
4B 0D K.
|
||||
|
||||
33 31 34 32 4A 0D 3142J.
|
||||
|
||||
00 40 00 01 02 03 04 05 00 .@.......
|
||||
|
||||
4B 0D K.
|
||||
|
||||
4B 0D K.
|
||||
|
||||
4B 0D K.
|
||||
|
||||
4B 0D K.
|
||||
|
||||
4B 0D K.
|
||||
'''
|
||||
120
data-logger-program/measure-13tc.DEF
Normal file
120
data-logger-program/measure-13tc.DEF
Normal file
|
|
@ -0,0 +1,120 @@
|
|||
11/11/2020
|
||||
20:15:35
|
||||
Created by Short Cut (4.3)
|
||||
Short Cut Program: measure-13tc.DEF
|
||||
|
||||
-Wiring for CR10-
|
||||
|
||||
AM25T
|
||||
1H: HI
|
||||
1L: LO
|
||||
AG: Ground
|
||||
E1: VX
|
||||
C2: RES
|
||||
C1: CLK
|
||||
G: G
|
||||
12V: 12V
|
||||
|
||||
-Wiring for AM25T-
|
||||
|
||||
Type K TC (1)
|
||||
1H: Yellow
|
||||
1L: Red
|
||||
|
||||
Type K TC (2)
|
||||
2H: Yellow
|
||||
2L: Red
|
||||
|
||||
Type K TC (3)
|
||||
3H: Yellow
|
||||
3L: Red
|
||||
|
||||
Type K TC (4)
|
||||
4H: Yellow
|
||||
4L: Red
|
||||
|
||||
Type K TC (5)
|
||||
5H: Yellow
|
||||
5L: Red
|
||||
|
||||
Type K TC (6)
|
||||
6H: Yellow
|
||||
6L: Red
|
||||
|
||||
Type K TC (7)
|
||||
7H: Yellow
|
||||
7L: Red
|
||||
|
||||
Type K TC (8)
|
||||
8H: Yellow
|
||||
8L: Red
|
||||
|
||||
Type K TC (9)
|
||||
9H: Yellow
|
||||
9L: Red
|
||||
|
||||
Type K TC (10)
|
||||
10H: Yellow
|
||||
10L: Red
|
||||
|
||||
Type K TC (11)
|
||||
11H: Yellow
|
||||
11L: Red
|
||||
|
||||
Type K TC (12)
|
||||
12H: Yellow
|
||||
12L: Red
|
||||
|
||||
Type K TC (13)
|
||||
13H: Yellow
|
||||
13L: Red
|
||||
|
||||
-Measurement Labels-
|
||||
|
||||
Default
|
||||
1 BattV
|
||||
2 ProgSig
|
||||
|
||||
AM25T
|
||||
3 RTemp_C
|
||||
|
||||
Type K TC (1)
|
||||
4 Temp_C_0
|
||||
|
||||
Type K TC (2)
|
||||
5 Temp_C_1
|
||||
|
||||
Type K TC (3)
|
||||
6 Temp_C_2
|
||||
|
||||
Type K TC (4)
|
||||
7 Temp_C_3
|
||||
|
||||
Type K TC (5)
|
||||
8 Temp_C_4
|
||||
|
||||
Type K TC (6)
|
||||
9 Temp_C_5
|
||||
|
||||
Type K TC (7)
|
||||
10 Temp_C_6
|
||||
|
||||
Type K TC (8)
|
||||
11 Temp_C_7
|
||||
|
||||
Type K TC (9)
|
||||
12 Temp_C_8
|
||||
|
||||
Type K TC (10)
|
||||
13 Temp_C_9
|
||||
|
||||
Type K TC (11)
|
||||
14 Temp_C_10
|
||||
|
||||
Type K TC (12)
|
||||
15 Temp_C_11
|
||||
|
||||
Type K TC (13)
|
||||
16 Temp_C_12
|
||||
|
||||
Estimated final storage locations used per day: 0
|
||||
114
data-logger-program/measure-13tc.DLD
Normal file
114
data-logger-program/measure-13tc.DLD
Normal file
|
|
@ -0,0 +1,114 @@
|
|||
};CR10
|
||||
;measure-13tc.DLD
|
||||
;Created by Short Cut (4.3)
|
||||
;$
|
||||
;:BattV :ProgSig :RTemp_C :Temp_C_0 :Temp_C_1
|
||||
;:Temp_C_2 :Temp_C_3 :Temp_C_4 :Temp_C_5 :Temp_C_6
|
||||
;:Temp_C_7 :Temp_C_8 :Temp_C_9 :Temp_C_10:Temp_C_11
|
||||
;:Temp_C_12
|
||||
;$
|
||||
|
||||
;%
|
||||
;Final Storage Label File for: measure-13tc.SCW
|
||||
;Date: 11/11/2020
|
||||
;Time: 20:15:35
|
||||
;
|
||||
;Estimated final storage locations used per day: 0
|
||||
;%
|
||||
|
||||
MODE 1
|
||||
SCAN RATE 2.000
|
||||
|
||||
1:P10
|
||||
1:1
|
||||
|
||||
2:P92
|
||||
1:0
|
||||
2:1440
|
||||
3:30
|
||||
|
||||
3:P19
|
||||
1:2
|
||||
|
||||
4:P95
|
||||
|
||||
5:P86
|
||||
1:42
|
||||
|
||||
6:P6
|
||||
1:1
|
||||
2:23
|
||||
3:1
|
||||
4:1
|
||||
5:1200
|
||||
6:3
|
||||
7:-0.001
|
||||
8:0.09707
|
||||
|
||||
7:P59
|
||||
1:1
|
||||
2:3
|
||||
3:10.025
|
||||
|
||||
8:P16
|
||||
1:1
|
||||
2:3
|
||||
3:3
|
||||
4:1
|
||||
5:0
|
||||
|
||||
9:P87
|
||||
1:0
|
||||
2:13
|
||||
|
||||
10:P86
|
||||
1:71
|
||||
|
||||
11:P22
|
||||
1:1
|
||||
2:0
|
||||
3:1
|
||||
4:0
|
||||
|
||||
12:P86
|
||||
1:71
|
||||
|
||||
13:P22
|
||||
1:1
|
||||
2:0
|
||||
3:1
|
||||
4:0
|
||||
|
||||
14:P14
|
||||
1:1
|
||||
2:21
|
||||
3:1
|
||||
4:3
|
||||
5:3
|
||||
6:4--
|
||||
7:1
|
||||
8:0
|
||||
|
||||
15:P95
|
||||
|
||||
16:P86
|
||||
1:52
|
||||
|
||||
MODE 2
|
||||
SCAN RATE 10.0000
|
||||
1:P96
|
||||
1:71
|
||||
|
||||
|
||||
MODE 3
|
||||
|
||||
MODE 10
|
||||
1:28
|
||||
2:102
|
||||
3:0
|
||||
|
||||
MODE 12
|
||||
1:0000
|
||||
2:0000
|
||||
3:0000
|
||||
|
||||
5
data-logger-program/measure-13tc.FSL
Normal file
5
data-logger-program/measure-13tc.FSL
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
Final Storage Label File for: measure-13tc.SCW
|
||||
Date: 11/11/2020
|
||||
Time: 20:15:35
|
||||
|
||||
Estimated final storage locations used per day: 0
|
||||
4956
data-logger-program/measure-13tc.SCW
Normal file
4956
data-logger-program/measure-13tc.SCW
Normal file
File diff suppressed because it is too large
Load diff
116
data-logger-program/test2-comments.DLD
Normal file
116
data-logger-program/test2-comments.DLD
Normal file
|
|
@ -0,0 +1,116 @@
|
|||
};CR10
|
||||
;test2.DLD
|
||||
;Created by Short Cut (4.3)
|
||||
;$
|
||||
;:BattV :ProgSig :RTemp_C :Temp_C :Temp_C_1
|
||||
;:Temp_C_2 :Temp_C_3 :Temp_C_4 :Temp_C_5 :Temp_C_6
|
||||
;:Temp_C_7 :Temp_C_8 :Temp_C_9 :Temp_C_10:Temp_C_11
|
||||
;:Temp_C_12:Temp_C_13:Temp_C_14:Temp_C_15:Temp_C_16
|
||||
;:Temp_C_17:Temp_C_18:Temp_C_19:Temp_C_20:Temp_C_21
|
||||
;:Temp_C_22:Temp_C_23:Temp_C_24
|
||||
;$
|
||||
|
||||
;%
|
||||
;Final Storage Label File for: test2.SCW
|
||||
;Date: 9/28/2020
|
||||
;Time: 19:47:37
|
||||
;
|
||||
;Estimated final storage locations used per day: 0
|
||||
;%
|
||||
|
||||
MODE 1 ; Program Table 1
|
||||
SCAN RATE 1.0000 ; Execution interval
|
||||
|
||||
1:P10
|
||||
1:1
|
||||
|
||||
2:P92 ; IF TIME
|
||||
1:0
|
||||
2:1440
|
||||
3:30 ; DO
|
||||
|
||||
3:P19 ; Move Program Signature to
|
||||
1:2 ; Location
|
||||
|
||||
4:P95 ; END
|
||||
|
||||
5:P86 ; DO Command
|
||||
1:42 ; Set Port 2 High
|
||||
|
||||
6:P6 ; Full bridge with single differential measurement
|
||||
1:1 ; Reps
|
||||
2:23 ; Range
|
||||
3:1 ; Differential channel number
|
||||
4:1 ; Excitation channel number
|
||||
5:1200 ; Excitation voltage (mV)
|
||||
6:3 ; Location
|
||||
7:-0.001 ; Multiplier
|
||||
8:0.09707 ; Offset
|
||||
|
||||
7:P59 ; Bridge Transform
|
||||
1:1 ;
|
||||
2:3
|
||||
3:10.025
|
||||
|
||||
8:P16
|
||||
1:1
|
||||
2:3
|
||||
3:3
|
||||
4:1
|
||||
5:0
|
||||
|
||||
9:P87 ; LOOP
|
||||
1:0 ; Delay
|
||||
2:25 ; Count
|
||||
|
||||
10:P86 ; DO
|
||||
1:71 ; Pulse port 1
|
||||
|
||||
11:P22 ; Excitation with delay
|
||||
1:1
|
||||
2:0
|
||||
3:1
|
||||
4:0
|
||||
|
||||
12:P86 ; DO
|
||||
1:71 ; Pulse port 1
|
||||
|
||||
13:P22 ; Excitation with delay
|
||||
1:1
|
||||
2:0
|
||||
3:1
|
||||
4:0
|
||||
|
||||
14:P14 ; Thermocouple temperature differential measurement
|
||||
1:1 ; Reps
|
||||
2:21 ; Range
|
||||
3:1 ; Differential channel number
|
||||
4:3 ; Thermocouple type
|
||||
5:3 ; Reference temperature location
|
||||
6:4-- ; Destination location
|
||||
7:1 ; Multiplier
|
||||
8:0 ; Offset
|
||||
|
||||
15:P95 ; END LOOP
|
||||
|
||||
16:P86 ; DO
|
||||
1:52 ; Set Port 2 Low
|
||||
|
||||
MODE 2
|
||||
SCAN RATE 10.0000
|
||||
1:P96
|
||||
1:71
|
||||
|
||||
|
||||
MODE 3
|
||||
|
||||
MODE 10
|
||||
1:28
|
||||
2:102
|
||||
3:0
|
||||
|
||||
MODE 12
|
||||
1:0000
|
||||
2:0000
|
||||
3:0000
|
||||
|
||||
Loading…
Add table
Reference in a new issue