-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathWEBUSB_87_1.html
More file actions
90 lines (83 loc) · 2.8 KB
/
WEBUSB_87_1.html
File metadata and controls
90 lines (83 loc) · 2.8 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
<!DOCTYPE html>
<html lang="ru">
<head>
<meta charset="UTF-8">
<title>WebUSB CH340 Терминал (Один Файл)</title>
<style>
body { font-family: sans-serif; padding: 20px; background-color: #f4f4f9; }
h1 { color: #333; }
p { color: #555; }
#output {
width: 100%;
height: 300px;
resize: none;
border: 1px solid #2c3e50;
padding: 10px;
box-sizing: border-box;
background-color: #ecf0f1;
font-family: monospace;
font-size: 14px;
color: #2c3e50;
margin-bottom: 10px;
}
#input-container { margin-top: 10px; display: flex; }
#input-text {
flex-grow: 1;
padding: 8px;
margin-right: 10px;
border: 1px solid #ccc;
font-size: 14px;
}
button {
padding: 8px 15px;
cursor: pointer;
border: none;
background-color: #3498db;
color: white;
border-radius: 4px;
transition: background-color 0.3s;
}
button:hover:not(:disabled) {
background-color: #2980b9;
}
button:disabled {
background-color: #bdc3c7;
cursor: not-allowed;
}
.status-message {
margin-top: 10px;
padding: 10px;
border-radius: 4px;
}
.error {
background-color: #f39c12;
color: white;
}
</style>
</head>
<body>
<h1>WebUSB CH340 UART Терминал 🛠️</h1>
<p>⚠️ **ВАЖНО:** Доступ к WebUSB возможен только по **HTTPS** или на **http://localhost**. Используйте Chrome/Edge.</p>
<button id="connect-button">Подключиться к CH340</button>
<h3>Вывод терминала:</h3>
<textarea id="output" readonly></textarea>
<div id="input-container">
<input type="text" id="input-text" placeholder="Введите команду (Enter для отправки)...">
<button id="send-button" disabled>Отправить</button>
</div>
<script>
// ====================================================
// JAVASCRIPT WEBUSB CH340 TERMINAL
// ====================================================
// --- КОНСТАНТЫ ДЛЯ CH340 ---
const USB_VENDOR_ID = 0x1A86;
const USB_PRODUCT_ID = 0x7523;
const INTERFACE_NUMBER = 0;
const ENDPOINT_IN = 2;
const ENDPOINT_OUT = 2;
const PACKET_SIZE = 64;
// --- ПЕРЕМЕННЫЕ СОСТОЯНИЯ ---
let device;
let isConnected = false;
// --- DOM ЭЛЕМЕНТЫ ---
const connectButton =