simple cable tester project algorithm check AVR to python

I just want to see if I’m missing anything on this AVR to python algorithm? if I’m right this should also work for (n)pins to (n)ADC pins if the loop count is passed over serial and parsed. I also don’t care about hardware. I could use shift registers digital pins an lcd for output etc. doesn’t matter. This is an exercise for me to see if writing an algorithm first will help in coding a project. Thanks for your time.

algorithm to build a 9 pin to 9 pin DB9 cable tester

Microcontroller:

variables:
create a digital pin array of 9 pins
create a ADC array of 9 pins

Setup:

set input and output ports
setup USART

Main loop:

wait for serial command
from serial command response
set 1 digital pin high and scan 9 ADC pins
in known sequence
output char value and ‘.’
increment i array
for all 9 pins
using a nested for loop
for each connection output a 12 char String
one for the pin high
one for delimiter
9 ADC value chars
and newline
send string over port
increment J array
loop through the char values till j > 10
reset buffer
set all digital pins low

Protocol:

digital pins to ADC Pins example protocol

direct 9 to 9

123456789
A = 1XXXXXXXX
B = X1XXXXXXX
C = XX1XXXXXX
D = XXX1XXXXX
E = XXXX1XXXX
F= XXXXX1XXX
G= XXXXXX1XX
H= XXXXXXX1X
I = XXXXXXXX1

Host:

save Master cables as appended strings in a python file as a cable name.
The easiest way would be scan known good cable
save the output string to a master file using a switch case statement.

Running Program:

use master cable with switch sys.argv[var1] for file output
and sys.argv[var2] as master cable to compare serial input
as well as string name.

import master cable file
import sys
import serial

open AVR USART over serial
send command to test cable to micro
test pins over serial port
read incoming serial string
save serial string as a temp string
if any ADC port = XXXXXXXXX
set pin(n).NC as string
if X chars > 9 of incoming serial string
output only high connections to temp string
A.1XXXXXXXX/n
to A.1
save next string
loop 9 times
if sysargv[var2] = ‘m’
concat output string
append string sysargv[var1] to master file
close serial port
exit
concat example string “A.1B.2C.3D.4E.5F.6G.7H.8I.9\n”
if concat string matches master string in file
output cable correct

if strings do not match
output cable mismatch

USE Regular expression:

example concat string ‘A.NCB.2C.3D.4E.5F.6G.7H.8I.9\n’
for each letter parse the value using ‘.’ as delimiter
output differences
convert differences to actual ports and pins

Make Output Human Readable:

show all shorts multi connections
and or no connections for pins
i.e example string ‘A.NCB.2C.3D.4E.5F.6G.7H.8I.9\n’
pin1 has no connection
close serial port
exit

This Simple Python - Arduino demo may give you some ideas.

The Python code should work on Windows if you edit it to use the Windows style of COM ports.

...R

ya I know the python code will work I'll be using linux, but I have lots of serial projects with pyserial and arduino working. I will just need to go over regular expressions and the strip commands again but should be pretty easy from there. I guess I'll just make this work and see if I missed anything else as I go.