53 lines
1.2 KiB
Python
Executable File
53 lines
1.2 KiB
Python
Executable File
'''
|
|
____ _ ____ _
|
|
/ ___| / \ | _ \ / \
|
|
\___ \ / _ \ | |_) | / _ \
|
|
___) / ___ \| _ < / ___ \
|
|
|____/_/ \_\_| \_\/_/ \_\
|
|
Script to read memory to SARA-R410 memory
|
|
'''
|
|
|
|
import serial
|
|
import time
|
|
import sys
|
|
import json
|
|
|
|
parameter = sys.argv[1:] # Exclude the script name
|
|
port='/dev/'+parameter[0] # ex: ttyAMA2
|
|
message = parameter[1] # ex: Hello
|
|
|
|
baudrate = 9600
|
|
|
|
ser = serial.Serial(
|
|
port=port, #USB0 or ttyS0
|
|
baudrate=baudrate, #115200 ou 9600
|
|
parity=serial.PARITY_NONE, #PARITY_NONE, PARITY_EVEN or PARITY_ODD
|
|
stopbits=serial.STOPBITS_ONE,
|
|
bytesize=serial.EIGHTBITS,
|
|
timeout = 2
|
|
)
|
|
|
|
ser.write(b'AT+URDFILE="sensordata.json"\r')
|
|
|
|
try:
|
|
# Read lines until a timeout occurs
|
|
response_lines = []
|
|
while True:
|
|
line = ser.readline().decode('utf-8').strip()
|
|
if not line:
|
|
break # Break the loop if an empty line is encountered
|
|
response_lines.append(line)
|
|
|
|
# Print the response
|
|
for line in response_lines:
|
|
print(line)
|
|
|
|
except serial.SerialException as e:
|
|
print(f"Error: {e}")
|
|
|
|
finally:
|
|
if ser.is_open:
|
|
ser.close()
|
|
#print("Serial closed")
|
|
|