title: make txt file from data received by serial port
body: <p>I am trying to store data from usb port to a txt file using python, I send data from mobile phone using ble uart and chip NORDIC nRF52840 and I want to store it all untill I dont send more data, how do I close the loop? should I use a command like &quot;STOP&quot;? maybe do a list of data? I dont know how to implement this.</p>
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-css lang-css prettyprint-override"><code>import serial
  archi1=open("datos7.txt",'w')
  ser=serial.Serial('COM17',baudrate = 115200, timeout=15)
  
  try:
      ser.isOpen()
      print ("Reading open.")
  except:
      print ("Error.")
      exit()
  
  while True:
      data = ser.read(500)
      data = data.replace(b'\r',b'')
      data = data.replace(b'\x1b',b'')
      dataASCII = data.decode("ascii")
      archi1.write('Envio de datos empezado.\n')
      print(data, end='')
      if archi1.write('Los datos obtenidos son:|%s|' % (dataASCII)):
          archi1.write('\nEnvio de datos terminado.')
          
          break
  archi1.flush()
  archi1.close()</code></pre>
  </div>
  </div>
  </p>