DeltaDTC.cs 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668
  1. namespace SHJX.Service.PortClient.TempController
  2. {
  3. /// <summary>
  4. /// 台达DTC1000V温控器通信控制类
  5. /// </summary>
  6. public class DeltaDTC
  7. {
  8. private static readonly ILogger logger = LogFactory.BuildLogger(typeof(SerialPortImp));
  9. private DeltaDTC()
  10. {
  11. RetrieveDatas = "";
  12. LastReadPVtime = DateTime.Now;
  13. LastReadSVtime = DateTime.Now;
  14. LastReadOutputTime = DateTime.Now;
  15. CurrTempPv = 0;
  16. CurrTempSv = 0;
  17. }
  18. private static readonly object obj_locker = new();
  19. public static DeltaDTC StartNew
  20. {
  21. get
  22. {
  23. lock (obj_locker)
  24. {
  25. return new();
  26. }
  27. }
  28. }
  29. public DeltaDTC SetAddrNum(byte nodeID)
  30. {
  31. AddrNum = nodeID;
  32. return this;
  33. }
  34. #region protected properties
  35. /// <summary>
  36. /// 温控器RS485通信号
  37. /// </summary>
  38. private byte AddrNum { get; set; }
  39. /// <summary>
  40. /// 最小查询间隔,毫秒
  41. /// </summary>
  42. protected const int IntervalMin = 3000;
  43. /// <summary>
  44. /// 发送指令后收到的响应数据
  45. /// </summary>
  46. private string RetrieveDatas { get; set; }
  47. /// <summary>
  48. /// 记录最后一次查询PV温度的时间,避免频繁查询
  49. /// </summary>
  50. private DateTime LastReadPVtime { get; set; }
  51. /// <summary>
  52. /// 记录最后一次查询SV温度的时间,避免频繁查询
  53. /// </summary>
  54. private DateTime LastReadSVtime { get; set; }
  55. /// <summary>
  56. /// 输出量最后查询时间
  57. /// </summary>
  58. private DateTime LastReadOutputTime { get; set; }
  59. /// <summary>
  60. /// 最近一次读到的实测温度
  61. /// </summary>
  62. private double CurrTempPv { get; set; }
  63. /// <summary>
  64. /// 最近一次读到的设置温度
  65. /// </summary>
  66. private double CurrTempSv { get; set; }
  67. /// <summary>
  68. /// 当前输出量
  69. /// </summary>
  70. private double CurrTempOutput { get; set; }
  71. #endregion
  72. #region protected methods
  73. /// <summary>
  74. /// 发送ASCII指令给温控器
  75. /// </summary>
  76. /// <param name="cmd">功能码+数据+LRC码</param>
  77. protected string SendCommand(string cmd)
  78. {
  79. if (!Rs485Client.IsValid)
  80. {
  81. return string.Empty;
  82. }
  83. RetrieveDatas = "";
  84. //Modbus ASCII格式:[:地址 功能码 数据地址 数据长度 LRC码 \r\n],如:[:-01-03-1000-0002-EA-CRLF]
  85. var msg = $":{cmd}\r\n";
  86. return Rs485Client.SendData(msg, "\r\n");
  87. }
  88. /// <summary>
  89. /// 从寄存器startpos,读取1个字节数据
  90. /// </summary>
  91. /// <param name="memAddr">起始位置,4个字符长度,如"1000"</param>
  92. /// <returns>读取结果</returns>
  93. protected double ReadByte(string memAddr)
  94. {
  95. double retval = -1;
  96. try
  97. {
  98. if (Rs485Client.IsValid)
  99. {
  100. // 读数指令
  101. string cmd = AddrNum.ToString("X").PadLeft(2, '0') + "03" + memAddr + "0001";
  102. cmd += LRC(cmd);
  103. RetrieveDatas = SendCommand(cmd);
  104. #region 解析温度值
  105. if (!string.IsNullOrEmpty(RetrieveDatas) && RetrieveDatas.Length >= (13)) // 例如 ": 06 03 02 00C8 CF \CR\LF"
  106. {
  107. string strPre = string.Format(":{0}03", AddrNum.ToString("X").PadLeft(2, '0'));
  108. if (RetrieveDatas.IndexOf(strPre) >= 0)
  109. {
  110. RetrieveDatas = RetrieveDatas.Remove(0, 5); // 移除":0103"
  111. int rlen = Convert.ToInt16(RetrieveDatas.Substring(0, 2), 16); // 数据长度
  112. RetrieveDatas = RetrieveDatas.Remove(0, 2); // 数据长度
  113. if (RetrieveDatas.Length >= 4)
  114. {
  115. retval = Convert.ToInt16(RetrieveDatas.Substring(0, 4), 16);
  116. RetrieveDatas = RetrieveDatas.Remove(0, 4);
  117. }
  118. }
  119. }
  120. #endregion
  121. RetrieveDatas = "";
  122. }
  123. }
  124. catch (Exception ex)
  125. {
  126. logger.LogError(ex.ToString());
  127. }
  128. return retval;
  129. }
  130. /// <summary>
  131. /// 从寄存器读取startpos开始的length字节数据
  132. /// </summary>
  133. /// <param name="startpos">起始位置,4个字符长度,如"1000"</param>
  134. /// <param name="length">读取长度,不大于6</param>
  135. /// <returns></returns>
  136. protected double[] ReadBytes(string startpos, int length)
  137. {
  138. if (length > 6) { length = 6; }
  139. double[] retval = new double[length];
  140. try
  141. {
  142. if (Rs485Client.IsValid)
  143. {
  144. // 读数指令
  145. string cmd = AddrNum.ToString("X").PadLeft(2, '0') + "03" + startpos + length.ToString("X").PadLeft(4, '0');
  146. cmd += LRC(cmd);
  147. string resdata = SendCommand(cmd);
  148. #region 解析读数值
  149. if (!string.IsNullOrEmpty(resdata) && resdata.Length >= (9 + length * 4)) // 例如 ": 06 03 02 00C8 CF \CR\LF"
  150. {
  151. string strPre = string.Format(":{0}03", AddrNum.ToString("X").PadLeft(2, '0'));
  152. if (resdata.IndexOf(strPre) >= 0)
  153. {
  154. resdata = resdata.Remove(0, 5); // 移除":0103"
  155. int rlen = Convert.ToInt16(resdata.Substring(0, 2), 16); // 数据长度
  156. resdata = resdata.Remove(0, 2); // 数据长度
  157. for (int i = 0; i < length; i++)
  158. {
  159. if (resdata.Length < 4) break;
  160. retval[i] = Convert.ToInt16(resdata.Substring(0, 4), 16);
  161. resdata = resdata.Remove(0, 4);
  162. }
  163. }
  164. }
  165. #endregion
  166. }
  167. }
  168. catch (Exception ex)
  169. {
  170. logger.LogError(ex.ToString());
  171. }
  172. return retval;
  173. }
  174. /// <summary>
  175. /// 写入数据到指定地址
  176. /// </summary>
  177. /// <param name="startpos">写入地址,4位字符</param>
  178. /// <param name="datas">要写入的数据</param>
  179. /// <returns>成功=true;失败=false</returns>
  180. protected bool WriteBytes(string startpos, string datas)
  181. {
  182. bool bRet = false;
  183. try
  184. {
  185. if (Rs485Client.IsValid)
  186. {
  187. string cmd = string.Format("{0}06{1}{2}", AddrNum.ToString("X").PadLeft(2, '0'), startpos, datas);
  188. cmd += LRC(cmd);
  189. string resDatas = SendCommand(cmd);
  190. // 确定是否成功,返回字符串与查询指令相同
  191. if (!string.IsNullOrEmpty(resDatas) && resDatas.IndexOf(cmd) >= 0)
  192. {
  193. bRet = true;
  194. }
  195. }
  196. }
  197. catch (Exception ex)
  198. {
  199. logger.LogError(ex.ToString());
  200. }
  201. return bRet;
  202. }
  203. #endregion
  204. #region static CRC
  205. /// <summary>
  206. /// 计算CRC校验码,16位
  207. /// </summary>
  208. /// <param name="buff">指令</param>
  209. /// <returns>校验码数值</returns>
  210. public static UInt32 CRC16(byte[] buff, int startpos = 0, int length = -1)
  211. {
  212. UInt32 crcval = 0xFFFF;
  213. if (length < 1 || length > buff.Length) { length = buff.Length; }
  214. int i = startpos;
  215. while (length > 0)
  216. {
  217. crcval ^= buff[i++];
  218. for (int j = 0; j < 8; j++)
  219. {
  220. if ((crcval & 0x01) > 0)
  221. crcval = (crcval >> 1) ^ 0xa001;
  222. else
  223. crcval >>= 1;
  224. }
  225. length--;
  226. }
  227. return crcval;
  228. }
  229. /// <summary>
  230. /// 计算LRC校验码,字节码
  231. /// </summary>
  232. /// <param name="auchMsg"></param>
  233. /// <returns></returns>
  234. public static byte LRC(byte[] auchMsg)
  235. {
  236. byte uchLRC = 0;
  237. foreach (byte item in auchMsg)
  238. {
  239. uchLRC += item;
  240. }
  241. return (byte)((uchLRC ^ 0xFF) + 1);
  242. }
  243. /// <summary>
  244. /// 计算LRC校验码,字符串
  245. /// </summary>
  246. /// <param name="auchMsg"></param>
  247. /// <returns></returns>
  248. public static string LRC(string auchMsg)
  249. {
  250. int uchLRC = 0;
  251. for (int i = 0; i < auchMsg.Length; i++)
  252. {
  253. string chs = auchMsg.Substring(i, 2);
  254. uchLRC += Convert.ToInt32(chs, 16);
  255. i++;
  256. }
  257. byte btlrc = (byte)((uchLRC ^ 0xFF) + 1);
  258. return btlrc.ToString("X").PadLeft(2, '0');
  259. }
  260. #endregion
  261. #region PID参数读写
  262. /// <summary>
  263. /// 读取PID参数中的比例Pd
  264. /// </summary>
  265. /// <returns>比例值0.0~9999.0</returns>
  266. public double ReadPidPb()
  267. {
  268. int startpos = 0x1009;
  269. return ReadByte(startpos.ToString("X").PadLeft(4, '0')) / 10.0;
  270. }
  271. /// <summary>
  272. /// 读取PID参数中的积分Ti
  273. /// </summary>
  274. /// <returns>积分值0~9999</returns>
  275. public int ReadPidTi()
  276. {
  277. int startpos = 0x100A;
  278. return (int)ReadByte(startpos.ToString("X").PadLeft(4, '0'));
  279. }
  280. /// <summary>
  281. /// 读取PID参数中的微分Td
  282. /// </summary>
  283. /// <returns>微分值0~9999</returns>
  284. public int ReadPidTd()
  285. {
  286. int startpos = 0x100B;
  287. return (int)ReadByte(startpos.ToString("X").PadLeft(4, '0'));
  288. }
  289. /// <summary>
  290. /// 读取PID参数中的积分量默认值
  291. /// </summary>
  292. /// <returns>积分量默认值,0.0~100.0%</returns>
  293. public double ReadPidTiDeft()
  294. {
  295. int startpos = 0x100C;
  296. return ReadByte(startpos.ToString("X").PadLeft(4, '0')) / 10.0;
  297. }
  298. /// <summary>
  299. /// 写入PID参数中的比例Pb
  300. /// </summary>
  301. /// <param name="newval">比例值,0.0~9999.0</param>
  302. /// <returns>成功=true;失败=false</returns>
  303. public bool WritePidPb(double newval)
  304. {
  305. int startpos = 0x1009;
  306. return WriteBytes(startpos.ToString("X").PadLeft(4, '0'), ((Int32)(newval * 10)).ToString("X").PadLeft(4, '0'));
  307. }
  308. /// <summary>
  309. /// 写入PID参数中的积分Ti
  310. /// </summary>
  311. /// <param name="newval">积分值,0~9999</param>
  312. /// <returns>成功=true;失败=false</returns>
  313. public bool WritePidTi(int newval)
  314. {
  315. int startpos = 0x100A;
  316. return WriteBytes(startpos.ToString("X").PadLeft(4, '0'), newval.ToString("X").PadLeft(4, '0'));
  317. }
  318. /// <summary>
  319. /// 写入PID参数中的微分Td
  320. /// </summary>
  321. /// <param name="newval">微分值,0~9999</param>
  322. /// <returns>成功=true;失败=false</returns>
  323. public bool WritePidTd(int newval)
  324. {
  325. int startpos = 0x100B;
  326. return WriteBytes(startpos.ToString("X").PadLeft(4, '0'), newval.ToString("X").PadLeft(4, '0'));
  327. }
  328. /// <summary>
  329. /// 写入PID参数中的积分量默认值
  330. /// </summary>
  331. /// <param name="newval">积分量默认值,0.0~100.0%</param>
  332. /// <returns>成功=true;失败=false</returns>
  333. public bool WritePidTiDeft(double newval)
  334. {
  335. int startpos = 0x100C;
  336. return WriteBytes(startpos.ToString("X").PadLeft(4, '0'), ((Int32)(newval * 10)).ToString("X").PadLeft(4, '0'));
  337. }
  338. /// <summary>
  339. /// 读取一个通道的pid参数值
  340. /// </summary>
  341. /// <param name="pb">比例带,0.0~9999.0</param>
  342. /// <param name="ti">积分值,0~9999</param>
  343. /// <param name="td">微分值,0~9999</param>
  344. /// <param name="tideft">积分量默认值,0.0~100.0 (%)</param>
  345. public void ReadPid(ref double pb, ref int ti, ref int td, ref double tideft)
  346. {
  347. pb = ReadPidPb();
  348. ti = ReadPidTi();
  349. td = ReadPidTd();
  350. tideft = ReadPidTiDeft();
  351. }
  352. /// <summary>
  353. /// 写入一个通道的pid参数值
  354. /// </summary>
  355. /// <param name="pb">比例带(P),0.0~9999.0</param>
  356. /// <param name="ti">积分值(I),0~9999</param>
  357. /// <param name="td">微分值(D),0~9999</param>
  358. /// <param name="tideft">积分量默认值,0.0~100.0 (%)</param>
  359. /// <returns></returns>
  360. public bool WritePid(double pb, int ti, int td, double tideft)
  361. {
  362. bool retval = true;
  363. retval = retval && WritePidPb(pb);
  364. retval = retval && WritePidTi(ti);
  365. retval = retval && WritePidTd(td);
  366. retval = retval && WritePidTiDeft(tideft);
  367. return retval;
  368. }
  369. #endregion
  370. #region public methods
  371. /// <summary>
  372. /// 读取实际温度
  373. /// </summary>
  374. /// <returns></returns>
  375. public double ReadPV()
  376. {
  377. #region 控制查询频率,避免频繁查询
  378. if (DateTime.Now.Subtract(LastReadPVtime).TotalMilliseconds < IntervalMin)
  379. {
  380. return CurrTempPv;
  381. }
  382. LastReadPVtime = DateTime.Now;
  383. #endregion
  384. try
  385. {
  386. if (Rs485Client.IsValid)
  387. {
  388. DateTime tmstart = DateTime.Now;
  389. // 读取设定温度
  390. string addr = "1000";
  391. string cmd = string.Format("{0}03{1}0001", AddrNum.ToString("X").PadLeft(2, '0'), addr);
  392. cmd += LRC(cmd);
  393. RetrieveDatas = SendCommand(cmd);
  394. #region 解析温度值
  395. if (!string.IsNullOrEmpty(RetrieveDatas) && RetrieveDatas.Length >= 15)
  396. {
  397. string strPre = string.Format(":{0}03", AddrNum.ToString("X").PadLeft(2, '0'));
  398. if (RetrieveDatas.IndexOf(strPre) >= 0)
  399. {
  400. RetrieveDatas = RetrieveDatas.Remove(0, 5); // 移除":0103"
  401. RetrieveDatas = RetrieveDatas.Remove(0, 2);
  402. if (RetrieveDatas.Length >= 4)
  403. {
  404. CurrTempPv = Convert.ToInt16(RetrieveDatas.Substring(0, 4), 16) / 10.0;
  405. RetrieveDatas = RetrieveDatas.Remove(0, 4);
  406. //if (this.LogProgram != null) { this.LogProgram.Info(".." + this.AddrNum.ToString() + ".."); }
  407. }
  408. }
  409. }
  410. #endregion
  411. RetrieveDatas = "";
  412. logger.LogInformation("dtc start query pv = " + DateTime.Now.Subtract(tmstart).TotalMilliseconds.ToString());
  413. }
  414. }
  415. catch (Exception ex)
  416. {
  417. logger.LogError(ex.ToString());
  418. }
  419. return CurrTempPv;
  420. }
  421. /// <summary>
  422. /// 读取设定温度
  423. /// </summary>
  424. /// <returns></returns>
  425. public double ReadSV()
  426. {
  427. #region 控制查询频率,避免频繁查询
  428. if (DateTime.Now.Subtract(LastReadSVtime).TotalMilliseconds < IntervalMin)
  429. {
  430. return CurrTempSv;
  431. }
  432. LastReadSVtime = DateTime.Now;
  433. #endregion
  434. try
  435. {
  436. if (Rs485Client.IsValid)
  437. {
  438. // 读取设定温度
  439. string addr = "1001";
  440. string cmd = string.Format("{0}03{1}0001", AddrNum.ToString("X").PadLeft(2, '0'), addr);
  441. cmd += LRC(cmd);
  442. RetrieveDatas = SendCommand(cmd);
  443. #region 解析温度值
  444. if (!string.IsNullOrEmpty(RetrieveDatas) && RetrieveDatas.Length >= 15)
  445. {
  446. string strPre = string.Format(":{0}03", AddrNum.ToString("X").PadLeft(2, '0'));
  447. if (RetrieveDatas.IndexOf(strPre) >= 0)
  448. {
  449. RetrieveDatas = RetrieveDatas.Remove(0, 5); // 移除":0103"
  450. RetrieveDatas = RetrieveDatas.Remove(0, 2);
  451. if (RetrieveDatas.Length >= 4)
  452. {
  453. CurrTempSv = Convert.ToInt16(RetrieveDatas.Substring(0, 4), 16) / 10.0;
  454. RetrieveDatas = RetrieveDatas.Remove(0, 4);
  455. }
  456. }
  457. }
  458. #endregion
  459. RetrieveDatas = "";
  460. }
  461. }
  462. catch (Exception ex)
  463. {
  464. logger.LogError(ex.ToString());
  465. }
  466. return CurrTempSv;
  467. }
  468. /// <summary>
  469. /// 写入设定温度
  470. /// </summary>
  471. /// <param name="tempVal"></param>
  472. /// <returns></returns>
  473. public bool WriteSV(double tempVal)
  474. {
  475. bool bRet = false;
  476. try
  477. {
  478. if (Rs485Client.IsValid)
  479. {
  480. string addr = "1001";
  481. string strtmp = ((Int32)(tempVal * 10)).ToString("X").PadLeft(4, '0');//2000转为十六进制7D0,左边补0,直到长度为4
  482. if (strtmp.Length > 4) { strtmp = strtmp.Substring(strtmp.Length - 4, 4); }//若长度大于4,取后4位
  483. string cmd = string.Format("{0}06{1}{2}", AddrNum.ToString("X").PadLeft(2, '0'), addr, strtmp);//端口地址+06+1001+07D0+校验
  484. cmd += LRC(cmd);//0706100107D00B--cmd
  485. RetrieveDatas = SendCommand(cmd);
  486. // 确定是否成功
  487. if (!string.IsNullOrEmpty(RetrieveDatas) && RetrieveDatas.Length > 0)
  488. {
  489. if (RetrieveDatas == string.Format(":{0}\r\n", cmd))
  490. {
  491. bRet = true;
  492. }
  493. }
  494. RetrieveDatas = "";
  495. }
  496. }
  497. catch (Exception ex)
  498. {
  499. logger.LogError(ex.ToString());
  500. }
  501. return bRet;
  502. }
  503. /// <summary>
  504. /// 读取PV和SV两个值
  505. /// </summary>
  506. /// <param name="pv">实际温度</param>
  507. /// <param name="sv">设定温度</param>
  508. public void ReadPVnSV(ref double pv, ref double sv)
  509. {
  510. DateTime tmstart = DateTime.Now;
  511. #region 控制查询频率,避免频繁查询
  512. if (DateTime.Now.Subtract(LastReadPVtime).TotalMilliseconds < IntervalMin &&
  513. DateTime.Now.Subtract(LastReadSVtime).TotalMilliseconds < IntervalMin)
  514. {
  515. pv = CurrTempPv;
  516. sv = CurrTempSv;
  517. return;
  518. }
  519. #endregion
  520. try
  521. {
  522. if (Rs485Client.IsValid)
  523. {
  524. // 读取2个温度值(2个word)
  525. string addr = "1000";
  526. string cmd = string.Format("{0}03{1}0002", AddrNum.ToString("X").PadLeft(2, '0'), addr);
  527. cmd += LRC(cmd);
  528. RetrieveDatas = SendCommand(cmd);
  529. #region 解析温度值
  530. if (!string.IsNullOrEmpty(RetrieveDatas) && RetrieveDatas.Length >= 17)
  531. {
  532. string strPre = string.Format(":{0}03", AddrNum.ToString("X").PadLeft(2, '0'));
  533. if (RetrieveDatas.IndexOf(strPre) >= 0)
  534. {
  535. RetrieveDatas = RetrieveDatas.Remove(0, 5); // 移除起始符信息":0103"
  536. RetrieveDatas = RetrieveDatas.Remove(0, 2); // 移除2位length信息
  537. if (RetrieveDatas.Length >= 4)
  538. {
  539. // 解析1000H数据
  540. CurrTempPv = Convert.ToInt16(RetrieveDatas.Substring(0, 4), 16) / 10.0;
  541. RetrieveDatas = RetrieveDatas.Remove(0, 4);
  542. }
  543. if (RetrieveDatas.Length >= 4)
  544. {
  545. // 解析1001H数据
  546. CurrTempSv = Convert.ToInt16(RetrieveDatas.Substring(0, 4), 16) / 10.0;
  547. RetrieveDatas = RetrieveDatas.Remove(0, 4);
  548. }
  549. }
  550. }
  551. #endregion
  552. RetrieveDatas = "";
  553. }
  554. pv = CurrTempPv;
  555. sv = CurrTempSv;
  556. LastReadPVtime = LastReadSVtime = DateTime.Now;
  557. }
  558. catch (UnauthorizedAccessException exo)
  559. {
  560. logger.LogError(exo.ToString());
  561. pv = CurrTempPv;
  562. sv = CurrTempSv;
  563. LastReadPVtime = LastReadSVtime = DateTime.Now;
  564. }
  565. catch (Exception ex)
  566. {
  567. logger.LogError(ex.ToString());
  568. pv = CurrTempPv;
  569. sv = CurrTempSv;
  570. LastReadPVtime = LastReadSVtime = DateTime.Now;
  571. }
  572. }
  573. /// <summary>
  574. /// 读取输出量
  575. /// </summary>
  576. /// <returns></returns>
  577. public double ReadOutput()
  578. {
  579. #region 控制查询频率,避免频繁查询
  580. if (DateTime.Now.Subtract(LastReadOutputTime).TotalMilliseconds < IntervalMin * 3)
  581. {
  582. return CurrTempOutput;
  583. }
  584. LastReadOutputTime = DateTime.Now;
  585. #endregion
  586. int startpos = 0x1012;
  587. CurrTempOutput = ReadByte(startpos.ToString("X").PadLeft(4, '0'));
  588. return CurrTempOutput;
  589. }
  590. /// <summary>
  591. /// 写入输出量(仅温控器处于手动控制模式下有效)
  592. /// </summary>
  593. /// <param name="newvals"></param>
  594. /// <returns></returns>
  595. public bool WriteOutput(double newVal)
  596. {
  597. int startpos = 0x1012;
  598. string datas = ((Int32)(newVal * 10)).ToString("X").PadLeft(4, '0');
  599. return WriteBytes(startpos.ToString("X").PadLeft(4, '0'), datas);
  600. }
  601. #endregion
  602. }
  603. }