|
@@ -5,54 +5,6 @@ using System.Collections.Generic;
|
|
|
using System.IO;
|
|
using System.IO;
|
|
|
using Unity.VisualScripting;
|
|
using Unity.VisualScripting;
|
|
|
using UnityEngine;
|
|
using UnityEngine;
|
|
|
-
|
|
|
|
|
-public class SerialPortHelper:MonoBehaviour
|
|
|
|
|
-{
|
|
|
|
|
- public static SerialPortExample[] SerialPortExampleGroup;
|
|
|
|
|
- private static ArrowSerialPort arrowPort;
|
|
|
|
|
-
|
|
|
|
|
- private static SerialPortHelper _ins;
|
|
|
|
|
-
|
|
|
|
|
- public static SerialPortHelper ins
|
|
|
|
|
- {
|
|
|
|
|
- get
|
|
|
|
|
- {
|
|
|
|
|
- if (_ins == null)
|
|
|
|
|
- {
|
|
|
|
|
- var go = new GameObject("SerialPortHelper");
|
|
|
|
|
- _ins = go.AddComponent<SerialPortHelper>();
|
|
|
|
|
- DontDestroyOnLoad(go);
|
|
|
|
|
- SerialPortExampleGroup = FindObjectsOfType<SerialPortExample>();
|
|
|
|
|
- }
|
|
|
|
|
- return _ins;
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- /// <summary>
|
|
|
|
|
- /// 获取串口实例(0串口和8串口)
|
|
|
|
|
- /// </summary>
|
|
|
|
|
- public SerialPortExample GetPort(int port)
|
|
|
|
|
- {
|
|
|
|
|
- if (port == 0 || port == 8)
|
|
|
|
|
- {
|
|
|
|
|
- foreach (var item in SerialPortExampleGroup)
|
|
|
|
|
- {
|
|
|
|
|
- if (item.name.Contains("com0"))
|
|
|
|
|
- return item;
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
- return null;
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- /// <summary>
|
|
|
|
|
- /// 获取串口实例(1串口)
|
|
|
|
|
- /// </summary>
|
|
|
|
|
- public ArrowSerialPort GetPort()
|
|
|
|
|
- {
|
|
|
|
|
- return arrowPort;
|
|
|
|
|
- }
|
|
|
|
|
-}
|
|
|
|
|
-
|
|
|
|
|
public class SerialPortExample : MonoBehaviour
|
|
public class SerialPortExample : MonoBehaviour
|
|
|
{
|
|
{
|
|
|
public int baudrate = 115200;
|
|
public int baudrate = 115200;
|
|
@@ -103,6 +55,7 @@ public class SerialPortExample : MonoBehaviour
|
|
|
//byte[] datas = new byte[8] { 0xAA, 0x08, 0x04, 0x01, 0x00, 0x00, 0x3C, 0xBB };
|
|
//byte[] datas = new byte[8] { 0xAA, 0x08, 0x04, 0x01, 0x00, 0x00, 0x3C, 0xBB };
|
|
|
//serialPortUtility.Write(datas);
|
|
//serialPortUtility.Write(datas);
|
|
|
|
|
|
|
|
|
|
+ LOG($"{PortName} 串口打开");
|
|
|
if (PortName.Contains("/dev/ttyS0"))
|
|
if (PortName.Contains("/dev/ttyS0"))
|
|
|
{
|
|
{
|
|
|
//拉取二维码
|
|
//拉取二维码
|
|
@@ -433,6 +386,7 @@ public class SerialPortExample : MonoBehaviour
|
|
|
/// <param name="dataIndex">数据编号 从1开始</param>
|
|
/// <param name="dataIndex">数据编号 从1开始</param>
|
|
|
private void RequestUrl(byte dataIndex)
|
|
private void RequestUrl(byte dataIndex)
|
|
|
{
|
|
{
|
|
|
|
|
+ LOG($"请求后台支付URL");
|
|
|
byte[] datas = new byte[7] { 0xAA, 0x55, 0x04, dataIndex, 0xAA, 0x01, 0xAE };
|
|
byte[] datas = new byte[7] { 0xAA, 0x55, 0x04, dataIndex, 0xAA, 0x01, 0xAE };
|
|
|
datas[6] = GetXor(datas);
|
|
datas[6] = GetXor(datas);
|
|
|
serialPortUtility.Write(datas);
|
|
serialPortUtility.Write(datas);
|