from scanivalve_mps.mps import MPS
from datetime import datetime

MPS_HOST = "191.30.90.1"

mps = MPS(MPS_HOST)

if not mps.status() == 'ready':
    raise RuntimeError('MPS is not ready; try again later.')

print('Starting zero calibration. This will take 15 seconds or so...')
mps.calibrate_zero()
print('Calibration done.')

now = datetime.now()
print('Setting time to ', now)
res = mps.set_time(now)

mps.set_format('csv')
mps.set_frames_per_scan(FRAMES_PER_SCAN)
mps.set_rate(RATE)
mps.set_scan_units('PA')

output_file = 'run_' + now.strftime('%Y-%m-%d_%H_%M_%S') + '.csv'
mps.scan_to_csv(output_file)

mps.disconnect()

print('Data written to ' + output_file)
input()
def test_mps_calibrate_zero():
    time.sleep(0.2)
    mps = MPS(HOST)
    mps.calibrate_zero()
    assert True
    mps.disconnect()
def test_mps_version():
    time.sleep(0.2)
    mps = MPS(HOST)
    version = mps.version()
    assert 'MPS Scanivalve' in version
    mps.disconnect()
def test_mps_status():
    time.sleep(0.2) # sleep to make sure the socket is closed from previous test
    mps = MPS(HOST)
    status = mps.status()
    assert type(status) is str
    mps.disconnect()
def test_mps_bootloader_version():
    time.sleep(0.2) # sleep to make sure the socket is closed from previous test
    mps = MPS(HOST)
    assert 'BOOTLOADER VERSION' in mps.bootloader_version()
    mps.disconnect()
def test_mps_init():
    mps = MPS(HOST)
    assert type(mps) is MPS
    mps.disconnect()