|
1 | 1 | # funbody2_zmq.py |
2 | 2 | import time |
3 | 3 | import concore |
4 | | -import concore2 |
5 | 4 |
|
6 | 5 | print("funbody using ZMQ via concore") |
7 | 6 |
|
|
15 | 14 |
|
16 | 15 | # Standard concore initializations |
17 | 16 | concore.delay = 0.07 |
18 | | -concore2.delay = 0.07 |
19 | | -concore2.inpath = concore.inpath |
20 | | -concore2.outpath = concore.outpath |
21 | | -concore2.simtime = 0 |
| 17 | +concore.simtime = 0 |
22 | 18 | concore.default_maxtime(100) |
23 | 19 | init_simtime_u_str = "[0.0, 0.0, 0.0]" |
24 | 20 | init_simtime_ym_str = "[0.0, 0.0, 0.0]" |
25 | 21 |
|
26 | 22 | u_data_values = concore.initval(init_simtime_u_str) |
27 | | -ym_data_values = concore2.initval(init_simtime_ym_str) |
| 23 | +ym_data_values = concore.initval(init_simtime_ym_str) |
28 | 24 |
|
29 | 25 | print(f"Initial u_data_values: {u_data_values}, ym_data_values: {ym_data_values}") |
30 | 26 | print(f"Max time: {concore.maxtime}") |
31 | 27 |
|
32 | | -while concore2.simtime < concore.maxtime: |
| 28 | +while concore.simtime < concore.maxtime: |
33 | 29 | received_u_data = concore.read(PORT_NAME_F2_F1, "u_signal", init_simtime_u_str) |
34 | 30 |
|
35 | 31 | if not (isinstance(received_u_data, list) and len(received_u_data) > 0): |
|
49 | 45 | if 'U2' in concore.oport: |
50 | 46 | concore.write(concore.oport['U2'], "u", u_data_values) |
51 | 47 |
|
52 | | - old_concore2_simtime = concore2.simtime |
53 | | - while concore2.unchanged() or concore2.simtime <= old_concore2_simtime: |
| 48 | + # Take a numeric snapshot of the current simulation time to avoid |
| 49 | + # inadvertently sharing a reference with concore.simtime. |
| 50 | + old_concore_simtime = float(concore.simtime) |
| 51 | + while concore.unchanged() or concore.simtime <= old_concore_simtime: |
54 | 52 | # Assuming concore.iport['Y2'] is a file port (e.g., from pmpymax.py) |
55 | | - ym_data_values = concore2.read(concore.iport['Y2'], "ym", init_simtime_ym_str) |
56 | | - # time.sleep(concore2.delay) # Optional delay |
| 53 | + ym_data_values = concore.read(concore.iport['Y2'], "ym", init_simtime_ym_str) |
| 54 | + # time.sleep(concore.delay) # Optional delay |
57 | 55 |
|
58 | | - ym_full_to_send = [concore2.simtime] + ym_data_values |
| 56 | + ym_full_to_send = [concore.simtime] + ym_data_values |
59 | 57 |
|
60 | 58 | concore.write(PORT_NAME_F2_F1, "ym_signal", ym_full_to_send) |
61 | 59 |
|
62 | | - print(f"funbody u={u_data_values} ym={ym_data_values} time={concore2.simtime}") |
| 60 | + print(f"funbody u={u_data_values} ym={ym_data_values} time={concore.simtime}") |
63 | 61 |
|
64 | 62 | print("funbody retry=" + str(concore.retrycount)) |
65 | 63 |
|
|
0 commit comments