using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading; using System.Threading.Tasks; namespace Ips.Cfq.SetFreqBySerialPort.Cli { /// /// 4通道变频器 /// public class CH4BPQ { readonly string rem_on = " /// 打开远控 /// /// /// bool RemOn(ref String errmsg) { bool result; if (_device.SendCommand(rem_on, ref errmsg)) { string result2 = _device.GetOutString(); result = result2.Contains("REM_ON"); } else { result = false; } return result; } /// /// 设置一个频点 /// /// /// /// /// public bool SetFreq(int ch, double freq, ref String errmsg) { String cmd = String.Format(cfreq, ch, freq.ToString("0000.000")); bool result = false; for (int idx = 0; idx < tryCount; ++idx) { if (_device.SendCommand(cmd, ref errmsg)) { string result2 = _device.GetOutString(); result = result2.Contains("CF"); } else { result = false; errmsg = $"{cmd}:{errmsg}"; } if (result) { break; } //控制失败 继续尝试 Thread.Sleep(500); } return result; } public bool SetFreqs(double[] freqs, ref String errmsg) { if (freqs.Length == 0) { return false; } if (!RemOn(ref errmsg)) { return false; } Thread.Sleep(100); bool ret = true; for (int idx = 0; idx < freqs.Length; ++idx) { if (freqs[idx] <= 0.01) continue; if (!SetFreq(idx + 1, freqs[idx], ref errmsg)) { ret = false; } } return ret; } } }