-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvirt_sender.py
34 lines (28 loc) · 1.08 KB
/
virt_sender.py
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
from serial import Serial, EIGHTBITS
from serial.tools import list_ports
from serial.serialutil import SerialException
from random import choice
class VirtualSender():
'''Класс для отправки данных на ком-порт'''
data: list = [0x1F1C, 0x1A3C, 0x7510, 0x1000]
@staticmethod
def get_ports() -> list:
"""Получение ком-портов компьютера"""
ports_list: list = list_ports.comports()
return ports_list
def start_spam(self) -> None:
with Serial(bytesize=EIGHTBITS, write_timeout=0.5) as ser:
ser.port = list(map(lambda x: x.device, self.get_ports()))[0]
while True:
try:
ser.open()
command: bytes = choice(
self.data).to_bytes(4, byteorder='big')
ser.write(command)
ser.close()
except SerialException:
continue
# Отладка в консоли
# sender = VirtualSender()
# print(sender.get_ports())
# sender.start_spam()