Changeset - 0e8a31b472f3
[Not reviewed]
default
0 1 0
Hasan Yavuz Ă–ZDERYA - 10 years ago 2015-06-20 04:34:12
hy@ozderya.net
added uint32_test to pseudo device script
1 file changed with 10 insertions and 0 deletions:
0 comments (0 inline, 0 general)
misc/pseudo_device.py
Show inline comments
 
@@ -52,24 +52,34 @@ def float_sine(port):
 
    """Puts 2 channel sine and cosine wafeform through pseudo terminal
 
    continuously."""
 
    i = 0
 
    period = 200
 
    while True:
 
        sin = math.sin(2 * math.pi * i / period)
 
        # cos = math.sin(2 * math.pi * (i / period + 1 / 4))
 
        data = struct.pack('ff', sin, -sin)
 
        os.write(port, data)
 
        i = (i + 1) % period
 
        time.sleep(0.1)
 

	
 
def uint32_test(port, little):
 
    """Puts 32 bit unsigned integer data through pseudo terminal"""
 
    i = 0
 
    maxi = 200
 
    while True:
 
        data = struct.pack('>I', i)
 
        os.write(port, data)
 
        time.sleep(0.05)
 
        i = i+1 if i <= maxi else 0
 

	
 
def run():
 
    # create the pseudo terminal
 
    master, slave = pty.openpty()
 

	
 
    master_name = os.ttyname(master)
 
    slave_name = os.ttyname(slave)
 
    print("Master terminal: {}\nSlave terminal: {}".format(master_name, slave_name))
 

	
 
    try:
 
        float_sine(master)
 
    finally:
 
        # close the pseudo terminal files
0 comments (0 inline, 0 general)