@harvester
Good OK you got most of it to work.
Not sure about the delay but here is my modified rc3563.py code. and I don't have any delay
Python:
#!/usr/bin/env python3
import serial
import struct
import sys
import xlwings as xw
with serial.Serial(sys.argv[1], 115200) as ser:
while True:
pkt = ser.read(10)
#print("PKT: ", pkt)
status_disp, r_range_code, r_disp, sign_code, v_range_code, v_disp = struct.unpack('BB3s BB3s', pkt)
#print(f"status_disp='{status_disp:#x}'")
r_disp = struct.unpack('I', r_disp + b'\x00')[0]
resistance = float(r_disp) / 1e4
r_disp_code = (status_disp & 0xF0) >> 4
if r_disp_code == 0x05:
r_unit_disp = 'mΩ'
elif r_disp_code == 0x06:
r_unit_disp = 'mΩ'
resistance = 'OL'
elif r_disp_code == 0x09:
r_unit_disp = 'Ω'
elif r_disp_code == 0x0a:
r_unit_disp = 'Ω'
resistance = 'OL'
else:
print(f"Unknown display code '{r_status_disp_code:#x}'")
#print(f"r_disp_code='{r_disp_code:#x}' r_unit_disp='{r_unit_disp}'")
r_unit = r_unit_disp
if r_range_code == 1:
r_range = '0-20 mΩ'
r_range_unit = 'mΩ'
elif r_range_code == 2:
r_range = '0-200 mΩ'
r_range_unit = 'mΩ'
elif r_range_code == 3:
r_range = '0-2 Ω'
r_range_unit = 'Ω'
elif r_range_code == 4:
r_range = '0-20 Ω'
r_range_unit = 'Ω'
elif r_range_code == 5:
r_range = '0-200 Ω'
r_range_unit = 'Ω'
elif r_range_code == 6:
r_range = 'AUTO'
r_range_unit = None
else:
r_range = None
r_range_unit = None
print(f"Unknown resistance range code '{r_range_code:#x}'")
if r_range_unit and r_unit_disp != r_range_unit:
print(f"Display unit '{r_unit_disp}' override by range unit '{r_range_unit}' for selected range '{r_range}'")
# Range unit has preference
r_unit = r_range_unit
print(f"RESISTANCE range='{r_range}' {resistance} {r_unit}")
sign_multiplier = None
if sign_code == 1:
sign_multiplier = 1.0
elif sign_code == 0:
sign_multiplier = -1.0
else:
print(f"Unknown sign code '{sign_code:#x}'")
v_disp = struct.unpack('I', v_disp + b'\x00')[0]
voltage = sign_multiplier * float(v_disp) / 1e4
v_disp_code = ( status_disp & 0x0F )
if v_disp_code == 0x04:
pass # Nop, everything is OK
elif v_disp_code == 0x08:
voltage = 'OL'
if v_range_code == 1:
v_range = '0-20 V'
elif v_range_code == 2:
v_range = '0-100 V'
elif v_range_code == 3:
v_range = 'AUTO'
else:
v_range = 'Unknown'
print(f"Unknown voltage range code '{v_range_code:#x}'")
#print(f"v_range_code='{v_range_code:#x}' v_range='{v_range}'")
print(f"VOLTAGE range='{v_range}', {voltage} V")
xw.Range('A1722').value = (f"{resistance}")
xw.Range('B1722').value = (f"{voltage}")
I removed a bunch of stuff I didn't need.
Notice at the bottom (Xw.Range) I send the voltage and resistance to excel column A and B row 1722. You can make this any place you want. I just put it low enough in my sheet so it would not interfere with the rest of the sheet.
Once you get the data showing up in excel at the appropriate column and row then you need to modify the VBScript to where you want this data to be copied from and pasted to.
Here is the VBScript with some explanations.
Sub Copy_Paste_Below_Last_Cell()
'Find the last used row in a sheet and copy and paste data below it.
Dim lRow As Long
ThisWorkbook.Activate
' The active workbook that you have open
'1. Find last used row in destination sheet.
In my case the worksheet name is IR & V & Capacity Test.
' The Rows.Count, 7 where the 7 correlates with the 7th column (G) you want to paste the data to. The 8th column (H) is understood as it ' copies and pastes 2 cells adjacent to each other.
lRow = Worksheets("
IR & V & Capacity Test").Cells(Worksheets("IR & V & Capacity Test").
Rows.Count, 7).End(xlUp).Row
'Offset 1 row below last used row
lRow = lRow + 1
'2. Copy data
Worksheets("IR & V & Capacity Test").Range("
A1722:B1722").Copy
' Range("A1722:B1722") is where the rc3563.py script should be sending the data to and that is what you want to copy.
'3. Paste data
Worksheets("IR & V & Capacity Test").Range("G" & lRow).PasteSpecial
' Range("G" & lRow) is where we are pasting to given the instructions above to "Offset 1 row below last used row"
'Clear copy mode (marching ants around copied range)
Application.CutCopyMode = False
Everything in
green is just my explanation and should be removed from the code.
The Macro shortcut you just add to run the VBscript.
In my case as I do 3 separate IR and V measurements,( Pre charge, post charge, post 25 day) hence I have 3 separate scripts that paste the IR and V into 3 different columns. therefore the Ctrl+s , z and so on. Hope this explains how it works. Let me know if you need more help.
Oh also check to see in my sheet that you are getting the data on row 1722 where you see OL and 0 after you insert a cell.
It should show you the V and IR as in this example. Try it with a plain empty workbook and see if you get the right data.
Wolf