AI N samples with logger

 1
 2'''
 3AI - AI_N_samples_with_logger.py.
 4
 5This example demonstrates how to read AI data in N-sample mode and save it into a CSV file.
 6
 7To begin with, it start AI acquisition with sampling rate and samples.
 8Then, it outlines the procedure for reading the streaming AI data.
 9Last, save the AI data to CSV file.
10
11For other examples please check:
12    https://github.com/WPC-Systems-Ltd/WPC_Stand-alone_Python_release/tree/main/examples
13
14Copyright (c) 2024 WPC Systems Ltd.
15All rights reserved.
16'''
17
18## WPC
19import pywpc
20
21## Parameters setting
22sampling_rate = 8000
23sample = 10000
24delay = 2000
25
26## Start AI acquisition
27pywpc.AI_start(sampling_rate, sample)
28
29## Read data acquisition
30ai_sample = pywpc.AI_readNsample(sample, delay)
31ai_len = len(ai_sample)
32
33## Stop AI acquisition
34pywpc.AI_stop()
35
36## Open CSV file
37ai_file = open("AI_test.csv", 'w')
38
39## Write CSV file
40ai_file.write("ch0,ch1,ch2,ch3,ch4,ch5,ch6,ch7\r\n")
41for i in range(ai_len):
42    res = ','.join(map(str, ai_sample[i]))
43    ai_file.write(res+'\r\n')
44
45## Close CSV file
46ai_file.close()
47
48del ai_sample