Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Multiprocess variable #23

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
fixing to issue 22 work
poledna committed Jun 25, 2020
commit 8a56bed1221c7e200cd839718bacfb7a2ac48f9a
24 changes: 11 additions & 13 deletions synchrophasor/pmu.py
Original file line number Diff line number Diff line change
@@ -4,7 +4,7 @@
from select import select
from threading import Thread
from multiprocessing import Queue
from multiprocessing import Process
from multiprocessing import Process, Value
from sys import stdout
from time import sleep
from synchrophasor.frame import *
@@ -66,7 +66,7 @@ def __init__(self, pmu_id=7734, data_rate=30, port=4712, ip="127.0.0.1",
self.method = method
self.clients = []
self.client_buffers = []

self.data_rate=Value('i',data_rate)

def set_id(self, pmu_id):

@@ -128,7 +128,7 @@ def set_data_rate(self, data_rate):
self.cfg1.set_data_rate(data_rate)
self.cfg2.set_data_rate(data_rate)
# self.cfg3.set_data_rate(data_rate)
self.data_rate = data_rate
self.data_rate.value = data_rate

# Configuration changed - Notify all PDCs about new configuration
self.send(self.cfg2)
@@ -159,8 +159,7 @@ def send(self, frame):
buffer.put(frame)


def send_data(self, phasors=[], analog=[], digital=[], freq=0, dfreq=0,
stat=("ok", True, "timestamp", False, False, False, 0, "<10", 0), soc=None, frasec=None):
def send_data(self, phasors=[], analog=[], digital=[], freq=0, dfreq=0,stat=("ok", True, "timestamp", False, False, False, 0, "<10", 0), soc=None, frasec=None):

# PH_UNIT conversion
if phasors and self.cfg2.get_num_pmu() > 1: # Check if multistreaming:
@@ -220,7 +219,7 @@ def acceptor(self):
self.client_buffers.append(buffer)

process = Process(target=self.pdc_handler, args=(conn, address, buffer, self.cfg2.get_id_code(),
self.cfg2.get_data_rate(), self.cfg1, self.cfg2,
self.data_rate, self.cfg1, self.cfg2,
self.cfg3, self.header, self.buffer_size,
self.set_timestamp, self.logger.level))
process.daemon = True
@@ -238,8 +237,7 @@ def join(self):


@staticmethod
def pdc_handler(connection, address, buffer, pmu_id, data_rate, cfg1, cfg2, cfg3, header,
buffer_size, set_timestamp, log_level):
def pdc_handler(connection, address, buffer, pmu_id, data_rate, cfg1, cfg2, cfg3, header,buffer_size, set_timestamp, log_level):

# Recreate Logger (handler implemented as static method due to Windows process spawning issues)
logger = logging.getLogger(address[0]+str(address[1]))
@@ -254,11 +252,6 @@ def pdc_handler(connection, address, buffer, pmu_id, data_rate, cfg1, cfg2, cfg3
# Wait for start command from connected PDC/PMU to start sending
sending_measurements_enabled = False

# Calculate delay between data frames
if data_rate > 0:
delay = 1.0 / data_rate
else:
delay = -data_rate

try:
while True:
@@ -344,6 +337,11 @@ def pdc_handler(connection, address, buffer, pmu_id, data_rate, cfg1, cfg2, cfg3
if set_timestamp: data.set_time()
data = data.convert2bytes()

# Calculate delay between data frames
if data_rate.value > 0:
delay = 1.0 / data_rate.value
else:
delay = -data_rate.value
sleep(delay)
connection.sendall(data)
logger.debug("[%d] - Message sent at [%f] -> (%s:%d)",