Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit bafd01b

Browse files
committedFeb 3, 2025
Initial commit.
1 parent 9136219 commit bafd01b

File tree

2 files changed

+184
-0
lines changed

2 files changed

+184
-0
lines changed
 

‎MTTVirtualDisplayPipe.py

Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
import tkinter as tk
2+
from tkinter import scrolledtext, messagebox
3+
import os
4+
import time
5+
import threading
6+
import win32file, win32pipe
7+
8+
PIPE_NAME = r"\\.\pipe\MTTVirtualDisplayPipe"
9+
10+
class PipeClientGUI:
11+
def __init__(self, root):
12+
self.root = root
13+
self.root.title("Virtual Display Driver Control")
14+
15+
self.frame = tk.Frame(root)
16+
self.frame.pack(padx=10, pady=10)
17+
18+
self.label = tk.Label(self.frame, text="Command:")
19+
self.label.grid(row=0, column=0, sticky="w")
20+
21+
self.command_entry = tk.Entry(self.frame, width=40)
22+
self.command_entry.grid(row=0, column=1, padx=5, pady=5)
23+
24+
self.send_button = tk.Button(self.frame, text="Send Command", command=self.send_command)
25+
self.send_button.grid(row=0, column=2, padx=5, pady=5)
26+
27+
self.reconnect_button = tk.Button(self.frame, text="Reconnect", command=self.reconnect_pipe)
28+
self.reconnect_button.grid(row=0, column=3, padx=5, pady=5)
29+
30+
self.log = scrolledtext.ScrolledText(self.frame, width=60, height=15)
31+
self.log.grid(row=1, column=0, columnspan=4, pady=10)
32+
33+
self.pipe = None
34+
self.connect_pipe()
35+
36+
def connect_pipe(self):
37+
"""Attempts to connect to the named pipe."""
38+
try:
39+
self.pipe = win32file.CreateFile(
40+
PIPE_NAME,
41+
win32file.GENERIC_READ | win32file.GENERIC_WRITE,
42+
0,
43+
None,
44+
win32file.OPEN_EXISTING,
45+
0,
46+
None
47+
)
48+
self.log.insert(tk.END, "Connected to the Virtual Display Driver pipe.\n")
49+
except Exception as e:
50+
self.log.insert(tk.END, f"Failed to connect to pipe: {e}\n")
51+
self.pipe = None
52+
53+
def reconnect_pipe(self):
54+
"""Reconnects to the named pipe."""
55+
self.log.insert(tk.END, "Attempting to reconnect...\n")
56+
self.connect_pipe()
57+
58+
def send_command(self):
59+
"""Sends a command to the driver."""
60+
if not self.pipe:
61+
messagebox.showerror("Error", "Not connected to pipe.")
62+
return
63+
64+
command = self.command_entry.get().strip()
65+
if not command:
66+
messagebox.showwarning("Warning", "Command cannot be empty.")
67+
return
68+
69+
try:
70+
win32file.WriteFile(self.pipe, command.encode('utf-16le'))
71+
self.log.insert(tk.END, f"Sent: {command}\n")
72+
self.receive_response()
73+
except Exception as e:
74+
self.log.insert(tk.END, f"Error sending command: {e}\n")
75+
76+
def receive_response(self):
77+
"""Reads and displays response from the driver."""
78+
try:
79+
_, data = win32file.ReadFile(self.pipe, 512)
80+
response = data.decode('utf-16le').strip()
81+
self.log.insert(tk.END, f"Response: {response}\n")
82+
except Exception as e:
83+
self.log.insert(tk.END, f"Error reading response: {e}\n")
84+
85+
if __name__ == "__main__":
86+
root = tk.Tk()
87+
app = PipeClientGUI(root)
88+
root.mainloop()

‎README.md

Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
## Virtual Display Driver Python Control GUI
2+
3+
![image](https://github.com/user-attachments/assets/b6666055-ac03-4e88-aeea-3b3a5150593d)
4+
5+
6+
This Python script provides a GUI to send commands to the Virtual Display Driver via a named pipe. It allows users to input and send commands, receive responses, and reconnect to the pipe if needed.
7+
8+
### Features
9+
10+
- **Command Entry:** Send commands to the Virtual Display Driver.
11+
- **Reconnect Button:** Re-establish connection to the named pipe.
12+
- **Log Window:** Displays sent commands and received responses.
13+
- **Error Handling:** Alerts for failed connections and invalid inputs.
14+
15+
---
16+
17+
## Prerequisites
18+
19+
This script requires the following dependencies:
20+
21+
- **Python 3.x**
22+
- **Tkinter** (built-in with Python)
23+
- **pywin32** (for Windows named pipes)
24+
25+
To install pywin32, run:
26+
27+
```sh
28+
pip install pywin32
29+
```
30+
31+
---
32+
33+
## Installation
34+
35+
1. **Ensure dependencies are installed** (see prerequisites).
36+
37+
2. **Run the script**:
38+
39+
```sh
40+
python MTTVirtualDisplayPipe.py
41+
```
42+
43+
---
44+
45+
## Usage
46+
47+
### Connecting to the Pipe
48+
Upon launching, the application will attempt to connect to the named pipe:
49+
50+
```plaintext
51+
\\.\pipe\MTTVirtualDisplayPipe
52+
```
53+
54+
If the connection is successful, the log will display:
55+
56+
```plaintext
57+
Connected to the Virtual Display Driver pipe.
58+
```
59+
60+
If it fails, an error message will appear.
61+
62+
### Sending Commands
63+
1. Enter a command in the **Command** field.
64+
2. Click **Send Command** to send it.
65+
3. The log will display the sent command and any response.
66+
67+
Example log output:
68+
69+
```plaintext
70+
Sent: SetResolution 1920x1080
71+
Response: Success
72+
```
73+
74+
### Reconnecting to the Pipe
75+
If the connection is lost:
76+
1. Click **Reconnect** to attempt reconnection.
77+
2. A status message will appear in the log.
78+
79+
---
80+
81+
## Troubleshooting
82+
83+
- **Not connected to pipe error**
84+
- Ensure the Virtual Display Driver is running.
85+
- Click **Reconnect** and try again.
86+
87+
- **No response from the driver**
88+
- Check if the command syntax is correct.
89+
- Confirm the driver is properly handling requests.
90+
91+
- **Pipe connection failure**
92+
- Verify that the named pipe exists and is accessible.
93+
- Restart the Virtual Display Driver service.
94+
95+
96+

0 commit comments

Comments
 (0)
Please sign in to comment.