import serial
import io
import time

ser = serial.Serial(port='com16', baudrate=9600, timeout=1)

ser.isOpen()

for x in range (0, 3):
    print('-------------Test Start-------------------------------')
    ser.write("/MAX30001/INT_assignment 1 0 0 2 2 0 2 2 0 1 0 0 2 1 0 3 3\r\n".encode())
    print(ser.readline())
    ser.write("/MAX30001/ECG_InitStart 01 00 00 00 00 00 0F 02 00 01 01\r\n".encode())
    print(ser.readline())
    ser.write("/MAX30001/PACE_InitStart 01 00 00 00 00 00 00 05 05\r\n".encode())
    print(ser.readline())
    ser.write("/MAX30001/BIOZ_InitStart 01 01 01 00 00 00 07 00 02 00 00 00 01 08 00 00 00\r\n".encode())
    print(ser.readline())
    ser.write("/MAX30001/RtoR_InitStart 01 03 0F 02 03 20 02 04 01\r\n".encode())
    print(ser.readline())
    ser.write("/MAX30001/Start\r\n".encode())

    for i in range (0,3):
        print(ser.read(100))

    ser.write(" ".encode())
    print(ser.read(100))

    #ser.write("/MAX30001/WriteReg 10 E0004\r\n".encode())
    #print(ser.read(100))
    ser.write("/MAX30001/ReadReg 1D\r\n".encode())
    print(ser.read(100))
    ser.write("/MAX30001/WriteReg 1D 3FA300\r\n".encode())
    print(ser.read(100))
    ser.write("/MAX30001/WriteReg 02 03\r\n".encode())
    print(ser.read(100))
    ser.write("/MAX30001/WriteReg 03 03\r\n".encode())
    print(ser.read(100))


ser.close()
