Example #1
0
class C37ReceiverThread(threading.Thread):
    def __init__(self, component):
        threading.Thread.__init__(self)
        self.active = threading.Event()
        self.active.clear()
        self.waiting = threading.Event()
        self.terminated = threading.Event()
        self.terminated.clear()
        self.component = component
        self.pdc = Pdc(pmu_ip=self.component.pmu_ip,
                             pmu_port=self.component.pmu_port)

    def run(self):
        self.data_plug = self.component.data_queue.setupPlug(self)
        self.config_plug = self.component.config_queue.setupPlug(self)
        self.header_plug = self.component.header_queue.setupPlug(self)

        while True:
            if self.terminated.is_set():
                break

            if not self.active.is_set():
                if self.pdc.is_connected():
                    self.pdc.stop()
                    self.active.wait()
                    self.pdc.start()
                else:
                    self.active.wait()

            if self.pdc.is_connected():
                data = self.pdc.get()
                self.data_plug.send_pyobj(data)

            else:
                self.pdc.run()
                if self.pdc.is_connected():
                    header = self.pdc.get_header()
                    self.header_plug.send_pyobj(header)
                    config = self.pdc.get_config()
                    self.config_plug.send_pyobj(config)
                    self.pdc.start()
                else:
                    # TODO: wait some?
                    pass


        self.pdc.quit()

    def activate(self):
        self.active.set()

    def deactivate(self):
        self.active.clear()

    def terminate(self):
        self.terminated.set()
Example #2
0
pdc_one.run()
print("RUNNING")

config = mpdc.get_config()
print(config)

ref_pdc.start()
mpdc.start()
pdc_one.start()

data = "Not Connected"

print("Connected")

for i in range(10):
    ref_data = ref_pdc.get()
    data = mpdc.get()
    data_one = pdc_one.get()
    print(len(data))
    print(len(data_one))
    #	print("PMU1")
    #	print(data_one)
    #	print("PMU3")
    #	print(data)

    ref_angle = struct.unpack('>f', ref_data[20:24])[0]

    print("\n\nParsing Hardware PMU:")
    print(struct.unpack('>f', data_one[16:20]))
    print(struct.unpack('>f', data_one[20:24]))
    vmag1 = struct.unpack('>f', data_one[16:20])[0]
Example #3
0
from pypmu.pdc import Pdc
from pypmu.frame import DataFrame
"""
tinyPDC will connect to pmu_ip:pmu_port and send request
for header message, configuration and eventually
to start sending measurements.
"""

if __name__ == "__main__":

    pdc = Pdc(pdc_id=9, pmu_ip="192.168.1.119", pmu_port=4712)
    pdc.logger.setLevel("DEBUG")

    pdc.run()  # Connect to PMU

    header = pdc.get_header()  # Get header message from PMU
    config = pdc.get_config()  # Get configuration from PMU

    pdc.start()  # Request to start sending measurements

    while True:

        data = pdc.get()  # Keep receiving data

        if type(data) == DataFrame:
            print(data.get_measurements())

        if not data:
            pdc.quit()  # Close connection
            break