Attachment 'Attenuator-60dB.py'

Download

   1 #!/usr/bin/env python3 
   2 # program Attenuator-60dB.py
   3 # 20129-08-02
   4 #
   5 # 2020-05-29 RR, added sleep for macOS, otherwise locks
   6 from time import sleep
   7 
   8 # need PySerial module from serial 
   9 import serial       # pip3 install pyserial
  10 # PL2303 USB-Serial bridge device, change to the actual port on your host 
  11 # could be '/dev/ttyUSB0' or 'COM1' for ex. 
  12 # DEVICE = '/dev/tty.Repleo-PL2303-00322314' 
  13 # DEVICE = '/dev/ttyUSB0'  # Linux
  14 DEVICE = '/dev/cu.usbserial' # MacOS
  15 # example: set -38.5 dBm 
  16 dbm = -38.5 
  17 # convert attenuation and troncate to DSA attenuation (0.5 dB step) 
  18 att = int(abs(2*dbm)+0.5)*5 
  19 # protocol 
  20 payload = 'wv0%d\n' % att 
  21 print(payload)
  22 # controller is hardcoded to 115200 8N1 
  23 #port = serial.Serial(DEVICE, 115200)
  24 port = serial.Serial(DEVICE, 115200, timeout=1) 
  25 sleep(0.1)
  26 
  27 # read out Attenuator type
  28 readID = 'rid\n'
  29 port.write(readID.encode()) 
  30 sleep(0.1)
  31 attID = port.readline()
  32 print(attID.decode())
  33 
  34 #print("Open serial port OK")
  35 # write the payload as bytes (payload is pure ASCII) 
  36 port.write(payload.encode()) 
  37 #print("Write OK")
  38 sleep(0.1)
  39 port.close() 

Attached Files

To refer to attachments on a page, use attachment:filename, as shown below in the list of files. Do NOT use the URL of the [get] link, since this is subject to change and can break easily.
  • [get | view] (2020-05-29 04:36:37, 1.1 KB) [[attachment:Attenuator-60dB.py]]
  • [get | view] (2018-09-17 03:52:00, 952.5 KB) [[attachment:Feinstaub_Karte_Wiesbaden.png]]
  • [get | view] (2013-05-08 04:53:00, 9.0 KB) [[attachment:graphviz-SomeGraph-0622e3eec12ac23a2b186cd3a1f8aa46765f1446.png]]
  • [get | view] (2013-05-08 04:53:00, 17.8 KB) [[attachment:shot.jpg]]
 All files | Selected Files: delete move to page copy to page

You are not allowed to attach a file to this page.