prc 1 năm trước cách đây
mục cha
commit
7c73932fcc

Những thai đổi đã bị hủy bỏ vì nó quá lớn
+ 416 - 416
client/src/renderer/pages/ListNum/ListNum4.vue


+ 26 - 27
launcher.py

@@ -14,42 +14,41 @@ class Launcher(object):
         print(f"[Launcher] {message}")
 
     def run(self):
-        server_process = None
-        client_process = None
+        server_process = subprocess.Popen(["python", "./server/server.py"], stdout=subprocess.PIPE,
+                                          stderr=subprocess.STDOUT, text=True, bufsize=1)
+        server_ready = False
+        port: int = 1024
+        for line in iter(server_process.stdout.readline, ""):
+            print(f"line: {line}")
+            match = re.search(r"Server is running on port \[(\d+)\].", line.strip())
+            if match is not None:
+                port = int(match.group(1))
+                break
+        for line in iter(server_process.stdout.readline, ""):
+            if "[Server] Server program is ready..." in line:
+                server_ready = True
+                break
+        if not server_ready:
+            print("Server failed to start. Exiting.")
+            server_process.kill()
+            return
+        print("Server is ready, starting client...")
+        client_env = os.environ.copy()
+        client_env["PLC_SIM_PORT"] = f"{port}"
+        client_process = subprocess.Popen(["powershell", "npm run dev"], env=client_env, cwd="./client")
         try:
-            # Start the server process in a new PowerShell window
-            server_process = subprocess.Popen(["powershell", "-Command", "Start-Process", "powershell", "-ArgumentList",
-                                               "'python ./server/server.py'"])
-
-            # Get the port number... (the code here should be modified accordingly to your need
-            # because the new process is running in another window)
-            # ...
-
-            # Start the client process in a new PowerShell window with an environment variable
-            my_env = os.environ.copy()
-            # my_env["PLC_SIM_PORT"] = f"{port}"  # Uncomment when port is available
-            client_cmd = "cd ./client; npm run dev"
-            client_process = subprocess.Popen(
-                ["powershell", "-Command", "Start-Process", "powershell", "-ArgumentList", f"'{client_cmd}'"],
-                env=my_env)
-
-            # Handle cleanup on exit...
             while True:
-                time.sleep(0.5)
-                # Check if one of the processes has terminated
-                if server_process.poll() is not None or client_process.poll() is not None:
+                return_code = client_process.poll()
+                if return_code is not None:
+                    print("Client process terminated with return code", return_code)
                     break
-
+                time.sleep(0.5)
             server_process.terminate()
-            client_process.terminate()
             server_process.wait()
-            client_process.wait()
-
         except KeyboardInterrupt:
             server_process.terminate()
             client_process.terminate()
             server_process.wait()
-            client_process.wait()
         except Exception as e:
             print(f"An error occurred: {str(e)}")
             server_process.terminate()

BIN
server/__pycache__/instrument_controller.cpython-311.pyc


BIN
server/__pycache__/serial_com_service.cpython-311.pyc


BIN
server/__pycache__/serial_device_controller.cpython-311.pyc


+ 1 - 1
server/instrument_controller.py

@@ -62,7 +62,7 @@ class InstrumentController(object):
         self.__pubtools: ProgramPublicTools = pubtools
         self.__scpi_instrument_list: list[ScpiInstrument] = []
         self.services: InstrumentServices = InstrumentServices()
-        self.__retry_times: int = 1
+        self.__retry_times: int = 0
 
     @staticmethod
     def __init_scpi_manager() -> scpiManager:

+ 10 - 10
server/serial_device_controller.py

@@ -359,8 +359,8 @@ class TestService(object):
         self.__receiver2 = None
         self.__task_reset_error_rate_percent: bool = False
         self.__speed_timer: float = 0
-        self.__speed_kbps: float = 0
-        self.__speed_kbps2: float = 0
+        self.speed_kbps: float = 0
+        self.speed_kbps2: float = 0
         self.__rev_timer_sec: float = time.time()
         self.__rev_timeout_sec: float = 2
 
@@ -521,21 +521,21 @@ class TestService(object):
             else:
                 error_rate_percent: float = 0.0
             self.error_rate_push(error_rate_percent, receiver_number)
-            self.__update_speed(count_all, count_error_all, receiver_number)
+            self.__update_speed(count_all, pkg_lose_bytes, receiver_number)
             return count_all, pkg_lose_bytes, count_error_all
         else:
             return 0, 0, 0
 
-    def __update_speed(self, count_all_bytes, count_error_bytes, receiver_number: int = None):
+    def __update_speed(self, count_all_bytes, pkg_lose_bytes, receiver_number: int = None):
         get_time = time.time() - self.__speed_timer
         if get_time != 0:
-            speed_kbps = (count_all_bytes - count_error_bytes) * 8 / (1000 * get_time)
+            speed_kbps = (count_all_bytes - pkg_lose_bytes) * 8 / (1000 * get_time)
         else:
             speed_kbps = 0
         if receiver_number == 2:
-            self.__speed_kbps2 = speed_kbps
+            self.speed_kbps2 = speed_kbps
         else:
-            self.__speed_kbps = speed_kbps
+            self.speed_kbps = speed_kbps
 
     def test_service(self, sender: PLCDeviceSender, receiver: PLCDeviceReceiver,
                      receiver2: Optional[PLCDeviceReceiver] = None):
@@ -582,7 +582,7 @@ class TestService(object):
             self.__tester_output(f"error_rate: {self.error_rate_percent} %", if_print)
             self.__tester_output(f"DBG: 发包={self.__sender.send_pkg_number} 收包={self.__receiver.receive_pkg}",
                                  if_print)
-            self.__tester_output(f"speed: {self.__speed_kbps} kbps", if_print)
+            self.__tester_output(f"speed: {self.speed_kbps} kbps", if_print)
             self.__receiver.pull_up_signal_when_receiving = False
             time.sleep(self.__sender.sleep_sec_every_step)
             if self.__sender.send_pkg_number % 10 == 0:
@@ -600,14 +600,14 @@ class TestService(object):
             self.__tester_output(f"error_rate: {self.error_rate_percent} %", if_print)
             self.__tester_output(f"DBG: 发包={self.__sender.send_pkg_number} 收包={self.__receiver.receive_pkg}",
                                  if_print)
-            self.__tester_output(f"speed: {self.__speed_kbps} kbps", if_print)
+            self.__tester_output(f"speed: {self.speed_kbps} kbps", if_print)
             self.__tester_output(f"Receiver [2]:", if_print)
             self.__tester_output(
                 f"all: {count_all2 * 8} bit, lose: {pkg_lose_bytes2 * 8} bit, error: {count_error2 * 8} bit", if_print)
             self.__tester_output(f"error_rate: {self.error_rate_percent2} %", if_print)
             self.__tester_output(f"DBG: 发包={self.__sender.send_pkg_number} 收包={self.__receiver2.receive_pkg}",
                                  if_print)
-            self.__tester_output(f"speed: {self.__speed_kbps2} kbps", if_print)
+            self.__tester_output(f"speed: {self.speed_kbps2} kbps", if_print)
             self.__receiver.pull_up_signal_when_receiving = False
             time.sleep(self.__sender.sleep_sec_every_step)
             if self.__sender.send_pkg_number % 10 == 0:

+ 16 - 1
server/server.py

@@ -1,6 +1,9 @@
+import os
 import time
 from typing import Optional
 
+import cv2
+import numpy as np
 from flask import Flask, request, jsonify
 from flask_cors import CORS
 
@@ -19,6 +22,11 @@ class Server:
         self.__app = Flask(__name__)
         CORS(self.__app)
         self.__setup_routes()
+        self.__send_server_completed_flag()
+
+    @staticmethod
+    def __send_server_completed_flag():
+        print("[Server] Server program is ready......")
 
     def __server_ip_init(self):
         if self.__server_port is None:
@@ -382,9 +390,16 @@ class Server:
             error_rate_percent: float = tester.error_rate_percent
             error_rate_percent2: float = tester.error_rate_percent2
             print(f"=== @self.__app.route('/serial_device/plc/realtime_performance', methods=['GET']) ===")
-            print(f"error_rate_percent={error_rate_percent}")
             return f"realtime_performance: error_rate_percent={error_rate_percent} error_rate_percent2={error_rate_percent2}"
 
+        @self.__app.route("/serial_device/plc/realtime_performance_speed", methods=['GET'])
+        def serial_device_plc_realtime_performance_speed():
+            tester = self.__core.serial_controller.get_tester()
+            speed_kbps: float = tester.speed_kbps
+            speed_kbps2: float = tester.speed_kbps2
+            print(f"=== @self.__app.route('/serial_device/plc/realtime_performance_speed', methods=['GET']) ===")
+            return f"realtime_performance_speed: speed_kbps={speed_kbps} speed_kbps2={speed_kbps2}"
+
         @self.__app.route("/files/documents/start", methods=['GET'])
         def files_documents_start():
             host, port = self.__core.local_file_service.start()

Một số tệp đã không được hiển thị bởi vì quá nhiều tập tin thay đổi trong này khác