using System; using System.Collections; using System.Collections.Generic; using UnityEngine; public class Test : MonoBehaviour { private const int BaudRate = 115200; private const int DataBits = 8; private const int Parity = 0; // 0 = None private const int StopBits = 1; // 1 = One private const int ReadTimeoutMs = 5; private const int WriteTimeoutMs = 10; string port = ""; private void Start() { ComNativeWrapper.Serial_CloseAll(); var devices = ComPortScanner.ScanPorts(); print($"Найдено устройств: {devices.Count}"); foreach (var device in devices) { //Витрина if (device.Value == ComPortScanner.DeviceType.PrizeShowcase) { port = device.Key; print($"{device.Key} нашел витрину, запускаю инициализацию"); } else if (device.Value == ComPortScanner.DeviceType.ControllerV1) { port = device.Key; print($"{device.Key} Нашел периферийник1 открываю."); } else if (device.Value == ComPortScanner.DeviceType.ControllerV2) { port = device.Key; print($"{device.Key} Нашел периферийник2 открываю."); } else { print($"неизвестный тип {device.Key}:{device.Value}"); } } } int h; private void Update() { if (Input.GetKeyDown(KeyCode.Alpha1)) { h = ComNativeWrapper.Serial_Open(port, 115200, 8, 0, 1, 4, 10); if(h <= 0) { print($"Неудачное открытие {port}, h={h}"); } } else if (Input.GetKeyDown(KeyCode.Alpha2)) { int res = ComNativeWrapper.Serial_Close(h); print($"Закрытие {port}: {res}"); } } }