终端一体化运控平台
Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.
 
 
 

79 lignes
3.5 KiB

  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6. namespace BPASmart.Model
  7. {
  8. public class AddressConvert
  9. {
  10. private volatile static AddressConvert _Instance;
  11. public static AddressConvert GetInstance => _Instance ?? (_Instance = new AddressConvert());
  12. private AddressConvert() { }
  13. public PlcConvertModel PlcConverter(ICommunicationDevice device, string Address)
  14. {
  15. PlcConvertModel plcConvertModel = new PlcConvertModel();
  16. if (device != null && Address != null && Address.Length > 0)
  17. {
  18. switch (device)
  19. {
  20. case Invoance _tempInvoance:
  21. if (Address.ToUpper().Contains("D") && Address.Length >= 3)
  22. {
  23. var res = Address.Substring(2);
  24. if (res != null && int.TryParse(res, out int LwAddress))
  25. {
  26. plcConvertModel.Address = LwAddress.ToString();
  27. plcConvertModel.DataType = EDataType.Word.ToString();
  28. }
  29. }
  30. break;
  31. case kinco _tempKinco:
  32. if (Address.ToUpper().Contains("M") && Address.Length >= 4)
  33. {
  34. var res = Address.Substring(1).Split('.');
  35. if (res != null && res.Length == 2)
  36. {
  37. if (int.TryParse(res[0], out int firstAddress) && int.TryParse(res[1], out int ExitAddress))
  38. {
  39. if (ExitAddress >= 0 && ExitAddress <= 7)
  40. {
  41. plcConvertModel.Address = ((firstAddress * 8) + 320 + ExitAddress).ToString();
  42. plcConvertModel.DataType = EDataType.Bool.ToString();
  43. }
  44. }
  45. }
  46. }
  47. else if ((Address.ToUpper().Contains("VW") || Address.ToUpper().Contains("VD")) && Address.Length >= 3)
  48. {
  49. var res = Address.Substring(2);
  50. if (res != null && int.TryParse(res, out int tempAddress))
  51. {
  52. plcConvertModel.Address = ((tempAddress / 2) + 100).ToString();
  53. plcConvertModel.DataType = Address.ToUpper().Contains("VW") ? EDataType.Word.ToString() : EDataType.Dword.ToString();
  54. }
  55. }
  56. break;
  57. case KincoOneMachine _tempKincoOneMachine:
  58. if (Address.ToUpper().Contains("LW") && Address.Length >= 2)
  59. {
  60. var res = Address.Substring(1);
  61. if (res != null && int.TryParse(res, out int LwAddress))
  62. {
  63. plcConvertModel.Address = LwAddress.ToString();
  64. plcConvertModel.DataType = EDataType.Word.ToString();
  65. }
  66. }
  67. break;
  68. default:
  69. break;
  70. }
  71. }
  72. return plcConvertModel;
  73. }
  74. }
  75. }