OpenCores
URL https://opencores.org/ocsvn/uart_fpga_slow_control_migrated/uart_fpga_slow_control_migrated/trunk

Subversion Repositories uart_fpga_slow_control_migrated

[/] [uart_fpga_slow_control/] [trunk/] [software/] [py_serial_control.py] - Blame information for rev 28

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 28 aborga
#! /usr/bin/python
2
 
3
######################################################
4
#-- author:     Andrea Borga (andrea.borga@nikhef.nl)
5
#-- date: $22/11/2011    $: created
6
#--
7
#-- version: $Rev 0      $:
8
#--
9
#-- description:
10
#--    basic python script to read and write 
11
#--    UART registers
12
#--
13
#--    NOTE: look through the code for this
14
#--
15
#--         -- ----------------------
16
#--         -- ----------------------
17
#--
18
#--   to spot where the code needs customization 
19
#
20
#-- Tested with Python 2.6 on Ubunru 10.04 LTS
21
#
22
#
23
######################################################
24
 
25
 
26
import serial
27
#ser = serial.Serial('/dev/ttyUSB0',115200,timeout=1)
28
ser = serial.Serial()
29
ser.port = "/dev/ttyUSB0" # set your port check in /dev folder
30
#ser.baudrate = 115200 # set your baud rate
31
ser.baudrate = 921600
32
ser.timeout = 1
33
ser.open()
34
print "Connected to: \t", ser.portstr
35
print "FPGA is ready to accept a command"
36
print "^] to quit"
37
print "help for command menu"
38
while 1:
39
 if ser.isOpen():
40
   in_var_add = raw_input("Type a command >> ")
41
   if in_var_add != '\x1d' :     # send a command
42
     if in_var_add == 'help' :   # help menu 
43
      print "\n", "here is a list implemented commands"
44
      print "  release on  : enables GXBs, PRBS tx, and PRBS rx"
45
      print "  release off : disables whole logic"
46
      #-----------------------
47
          # add commands description here
48
          #-----------------------
49
      print "  update      : sends an update command"
50
      print "  help        : prints this menu", "\n"
51
     elif in_var_add == 'release on' :
52
       ser.write('\x00\x30\x00\x00\x01\x11')
53
     #elif in_var_add == 'release off' :
54
     #  ser.write('\x00\x30\x00\x00\x00\x00')
55
         #-----------------------
56
         # add more commands here
57
         #-----------------------
58
     elif in_var_add == 'update' :
59
       ser.write('\x80\x00\x00\x00\x00\x00')
60
       out_resp = ser.read(72) # read 72 bytes
61
           #-----------------------
62
           # specify the number of bytes to be readout
63
           # nbytes = nregisters * 6
64
           #-----------------------
65
       out_split_resp = list(out_resp)
66
       print "Received: "
67
       ch_arr_resp = range(72)
68
       hex_arr_resp = range(72)
69
       for i in range (0,72):
70
         ch_arr_resp[i] = ord(out_split_resp[i])
71
         hex_arr_resp[i] = hex(ch_arr_resp[i])
72
       for x in range (0, 67, 6):
73
        print repr(hex_arr_resp[x]).rjust(2), repr(hex_arr_resp[x+1]).rjust(3), repr(hex_arr_resp[x+2]).rjust(4), repr(hex_arr_resp[x+3]).rjust(5), repr(hex_arr_resp[x+4]).rjust(6),
74
        print repr(hex_arr_resp[x+5]).rjust(7)
75
     else :
76
       print "unkown command, try again"
77
   elif in_var_add == '\x1d' : #ctrl+]
78
     print "...connetion closed..."
79
     ser.close()
80
     break                 # exit app
81
 
82
 

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.