热像仪Thing的串口,状态,路径

定义线程

private Thread _collectThread;

串口号

[Cfet2Config]
public string SerialPort { get; set; } = "COM6"; 

保存路径(包含文件名)

private string _savePath;
[Cfet2Config]
public string SavePath
{
    get => _savePath;
    set
    {
        if (_savePath != value)
        {
            _savePath = value;
             MyHub.EventHub.Publish(GetPathFor("SavePath"), "changed", _savePath);
        }
     }
}

设置保存路径

string filename = $"{DateTime.Now:yyyyMMddHHmmss}.jpg";
string fullPath = SavePath;
if (string.IsNullOrEmpty(fullPath))
fullPath = Path.Combine(Environment.CurrentDirectory, filename);
else(Directory.Exists(Path.GetDirectoryName(fullPath)))
 fullPath = Path.Combine(Path.GetDirectoryName(fullPath), filename);


_camera.save_image(fullPath);
MyHub.EventHub.Publish(GetPathFor("LastSavedFile"), "changed", fullPath);

将图片保存到路径

间隔

private int _intervalMs = 1000;
[Cfet2Config]
public int IntervalMs
{
    get => _intervalMs;
    set
    {
        if (_intervalMs != value)
        {
            _intervalMs = value;
            MyHub.EventHub.Publish(GetPathFor("IntervalMs"), "changed", _intervalMs);
        }
    }
}

设置间隔

自启动

private bool _run = false;
[Cfet2Config]
public bool Run
{
    get => _run;
    set
    {
        if (_run != value)
        {
            _run = value;
            if (_run) StartCollect();
            else StopCollect();

            MyHub.EventHub.Publish(GetPathFor("Run"), "changed", _run);
        }
    }
}

设置自启动或停止后台采集线程

运行状态

[Cfet2Status("IsRunning")]
public bool IsRunning()
{
    return _running;
}

本文章使用limfx的vscode插件快速发布