CoreDevice.cs 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. namespace Core.StlMes.Client.LgResMgt.Mcms
  6. {
  7. public enum DeviceStatus
  8. {
  9. INIT = 0,
  10. CLOSE,
  11. OPEN,
  12. IDLE,
  13. }
  14. public class CoreDevice
  15. {
  16. #region <成员变量>
  17. private string _deviceName;
  18. private string _deviceType;
  19. private DeviceStatus _status = new DeviceStatus();
  20. #endregion
  21. #region <属性>
  22. public virtual string DeviceName
  23. {
  24. get { return _deviceName; }
  25. set { _deviceName = value; }
  26. }
  27. public virtual string DeviceType
  28. {
  29. get { return _deviceType; }
  30. set { _deviceType = value; }
  31. }
  32. public DeviceStatus Status
  33. {
  34. get { return _status; }
  35. set { _status = value; }
  36. }
  37. #endregion
  38. #region <通用的方法>
  39. protected string StrToHex(string str)
  40. {
  41. string strTemp = "";
  42. if (str == "")
  43. return "";
  44. byte[] bTemp = System.Text.Encoding.Default.GetBytes(str);
  45. for (int i = 0; i < bTemp.Length; i++)
  46. {
  47. strTemp += bTemp[i].ToString("x");
  48. }
  49. return strTemp;
  50. }
  51. // 2012-03-25 modify by [BHB] 对于"00"的数据认为是自动填充的内容
  52. protected string HexToStr(string s)
  53. {
  54. string xx = "";
  55. string strAsc = "";
  56. string hex = "";
  57. int value = 0;
  58. for (int i = 0; i < s.Length / 2; i++)
  59. {
  60. hex = s.Substring(2 * i, 2);
  61. value = Convert.ToInt32(hex, 16);
  62. if (0 == value) continue;
  63. strAsc += (char)value;
  64. }
  65. return strAsc;
  66. }
  67. protected void WriteLog(string str)
  68. {
  69. try
  70. {
  71. string m_szRunPath = System.Environment.CurrentDirectory.ToString();
  72. //string m_szRunPath = Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().GetName().CodeBase);
  73. if (!(System.IO.Directory.Exists(m_szRunPath + "\\log")))
  74. {
  75. System.IO.Directory.CreateDirectory(m_szRunPath + "\\log");
  76. }
  77. string strDate = System.DateTime.Now.ToString("yyyyMMddhhmm");
  78. System.IO.TextWriter tw = new System.IO.StreamWriter(m_szRunPath + "\\log\\" + DeviceName + "-" + strDate + "_Display.log", true);
  79. tw.WriteLine(System.DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"));
  80. tw.WriteLine(str);
  81. tw.WriteLine("\r\n");
  82. tw.Close();
  83. }
  84. catch (Exception e)
  85. {
  86. ;
  87. }
  88. }
  89. #endregion
  90. }
  91. }