@@ -0,0 +1,3246 @@
+from socket import *%0Aimport sys, time, random%0Aimport pytia%0A%0A# Simple demo of TiA client/server comms process%0A%0Adef data_callback(signalid):%0A    return %5Brandom.uniform(-1000, 1000) for x in range(3)%5D%0A%0Aif __name__ == %22__main__%22:%0A    # create a client and connect to the server%0A    client = pytia.TiAClient('127.0.0.1', 9000)%0A    if not client.connect():%0A        print('Failed to connect to server')%0A        sys.exit(-1)%0A%0A    # TiA clients must start by checking server protocol version against theirs%0A    if not client.cmd_check_protocol_version():%0A        print('Protocol version check failed!')%0A        client.disconnect()%0A        sys.exit(-1)%0A%0A    # The client should now technically use the 'get metainfo' command to %0A    # retrieve the signal information the server  has been configured with.%0A    # TODO this doesn't actually return the actual metainfo data yet%0A    metainfo = client.cmd_get_metainfo()%0A%0A    # next, clients should request a TCP data connection (UDP not supported)%0A    # the server will respond with a port number that the client should connect%0A    # to in order to start streaming data.%0A    status, dport = client.cmd_get_data_connection_tcp()%0A    print(status, dport)%0A    if not status:%0A        print('Failed to get data connection')%0A        client.disconnect()%0A        sys.exit(-1)%0A%0A    # the client connects and requests that the server begin streaming data%0A    print('Connecting to server on port %25d...' %25 dport)%0A    if not client.start_streaming_data_tcp('127.0.0.1', dport):%0A        print('Failed to start streaming data')%0A        client.disconnect()%0A        sys.exit(-1)%0A%0A    # once connected, the server continues streaming data until told to stop%0A    done = False%0A    while not done:%0A        try:%0A            # calling the get_data function returns the most recent data received%0A            # from the server. depending on the buffer size used (TODO?) there may%0A            # be multiple TiA packets returned here.%0A            packets = client.get_data()%0A            print('----------')%0A            print('Retrieved %25d packets' %25 (len(packets)))%0A            if len(packets) %3E 0:%0A                packet = packets%5B0%5D%0A                print('Dumping first packet info...')%0A                print('Packet metadata: ', packet.timestamp, packet.packet_id, packet.packet_number)%0A                print('%25d signals in packet' %25 (len(packet.signals)))%0A                print('Channel counts: ', packet.channels)%0A                print('Block sizes: ', packet.blocksizes)%0A                # accessing data selectively by channel%0A                for i in range(packet.channels%5B0%5D):%0A                    print('1st signal data %5Bchannel %25d/%25d%5D' %25 (i, packet.channels%5B0%5D)),%0A                    print(packet.get_channel(0, i))%0A                # accessing all signal data in one go%0A                print('1st signal data %5Ball%5D'),%0A                print(packet.get_channel(0))%0A                #for i in range(packet.channels%5B0%5D):%0A                #    print('   Channel %25d:' %25 i, packet.get_channel(0, i))%0A            time.sleep(0.1)%0A        except KeyboardInterrupt:%0A            done = True%0A%0A    # the client should tell the server to stop streaming before %0A    # disconnecting itself%0A    client.stop_streaming_data()%0A    client.disconnect()%0A%0A

rename example client