|
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778 |
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
-
- namespace BPASmart.Model
- {
- public class AddressConvert
- {
- private volatile static AddressConvert _Instance;
- public static AddressConvert GetInstance => _Instance ?? (_Instance = new AddressConvert());
- private AddressConvert() { }
-
- public PlcConvertModel PlcConverter(ICommunicationDevice device, string Address)
- {
- PlcConvertModel plcConvertModel = new PlcConvertModel();
- if (device != null && Address != null && Address.Length > 0)
- {
- switch (device)
- {
- case Invoance _tempInvoance:
- if (Address.ToUpper().Contains("D") && Address.Length >= 3)
- {
- var res = Address.Substring(2);
- if (res != null && int.TryParse(res, out int LwAddress))
- {
- plcConvertModel.Address = LwAddress.ToString();
- plcConvertModel.DataType = EDataType.Word.ToString();
- }
- }
- break;
- case kinco _tempKinco:
- if (Address.ToUpper().Contains("M") && Address.Length >= 4)
- {
- var res = Address.Substring(1).Split('.');
- if (res != null && res.Length == 2)
- {
- if (int.TryParse(res[0], out int firstAddress) && int.TryParse(res[1], out int ExitAddress))
- {
- if (ExitAddress >= 0 && ExitAddress <= 7)
- {
- plcConvertModel.Address = ((firstAddress * 8) + 320 + ExitAddress).ToString();
- plcConvertModel.DataType = EDataType.Bool.ToString();
- }
- }
- }
- }
- else if ((Address.ToUpper().Contains("VW") || Address.ToUpper().Contains("VD")) && Address.Length >= 3)
- {
- var res = Address.Substring(2);
- if (res != null && int.TryParse(res, out int tempAddress))
- {
- plcConvertModel.Address = ((tempAddress / 2) + 100).ToString();
- plcConvertModel.DataType = Address.ToUpper().Contains("VW") ? EDataType.Word.ToString() : EDataType.Dword.ToString();
- }
- }
- break;
- case KincoOneMachine _tempKincoOneMachine:
- if (Address.ToUpper().Contains("LW") && Address.Length >= 2)
- {
- var res = Address.Substring(1);
- if (res != null && int.TryParse(res, out int LwAddress))
- {
- plcConvertModel.Address = LwAddress.ToString();
- plcConvertModel.DataType = EDataType.Word.ToString();
- }
- }
- break;
- default:
- break;
- }
- }
- return plcConvertModel;
- }
-
- }
- }
|