using System;
using System.Collections;
using System.Collections.Generic;
using System.IO.Ports;
using UnityEngine;
using UnityEngine.UI;
using ZXKFramework;
///
/// 5ml注射器对接硬件脚本
///
public class ZhuSheQi_5SenSor : Sensor
{
///
/// 进度值
///
[HideInInspector]
public float progressValue;
[SerializeField]
Text txt;
[HideInInspector]
public bool isOpen;
float time;
float lastTime;
private void Start()
{
transform.parent.GetComponent().SendFunction("+++");
}
public override void ReceiveData(string datas, SerialPort sp = null)
{
base.ReceiveData(datas);
if (!datas.Split('%')[0].Split("ID:")[1].Split(',')[0].Equals("ZSQ5")) return;
//this.Error(datas);
lastTime = time;
//progressValue = ((Convert.ToInt32(datas.Split("%")[0].Split("LEVEL:")[1]))-3) / 7.0f;
progressValue = (float)double.Parse(datas.Split("%")[0].Split("LEVEL:")[1]) / 10.0f;
//this.Error($"当前5ml注射器的进度为:{progressValue}");
}
private void Update()
{
time += Time.deltaTime;
if (time - lastTime < 1.0f)
{
isOpen = true;
}
else
{
isOpen = false;
//progressValue = 0;
}
txt.text = $"10ml注射器开启:{isOpen}拉取进度:{progressValue}";
}
public override void Display(string datas)
{
base.Display(datas);
txt.text = $"5ml注射器拉取进度:{progressValue}";
}
}