@@ -12,19 +12,22 @@ namespace BPASmart.Model | |||
public static AddressConvert GetInstance => _Instance ?? (_Instance = new AddressConvert()); | |||
private AddressConvert() { } | |||
public string PlcConverter(ICommunicationDevice device, string Address) | |||
public PlcConvertModel PlcConverter(ICommunicationDevice device, string Address) | |||
{ | |||
string address = string.Empty; | |||
//if (Address != null && int.TryParse(Address, out int result)) return result; | |||
PlcConvertModel plcConvertModel = new PlcConvertModel(); | |||
if (device != null && Address != null && Address.Length > 0) | |||
{ | |||
switch (device) | |||
{ | |||
case Invoance _tempInvoance: | |||
if (Address.ToUpper().Contains("LW") && Address.Length >= 3) | |||
if (Address.ToUpper().Contains("D") && Address.Length >= 3) | |||
{ | |||
var res = Address.Substring(2); | |||
if (res != null && int.TryParse(res, out int LwAddress)) return LwAddress.ToString(); | |||
if (res != null && int.TryParse(res, out int LwAddress)) | |||
{ | |||
plcConvertModel.Address = LwAddress.ToString(); | |||
plcConvertModel.DataType = EDataType.Word.ToString(); | |||
} | |||
} | |||
break; | |||
case kinco _tempKinco: | |||
@@ -37,7 +40,8 @@ namespace BPASmart.Model | |||
{ | |||
if (ExitAddress >= 0 && ExitAddress <= 7) | |||
{ | |||
return ((firstAddress * 8) + 320 + ExitAddress).ToString(); | |||
plcConvertModel.Address = ((firstAddress * 8) + 320 + ExitAddress).ToString(); | |||
plcConvertModel.DataType = EDataType.Bool.ToString(); | |||
} | |||
} | |||
} | |||
@@ -45,21 +49,29 @@ namespace BPASmart.Model | |||
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)) return ((tempAddress / 2) + 100).ToString(); | |||
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("D") && Address.Length >= 2) | |||
if (Address.ToUpper().Contains("LW") && Address.Length >= 2) | |||
{ | |||
var res = Address.Substring(1); | |||
if (res != null && int.TryParse(res, out int LwAddress)) return LwAddress.ToString(); | |||
if (res != null && int.TryParse(res, out int LwAddress)) | |||
{ | |||
plcConvertModel.Address = LwAddress.ToString(); | |||
plcConvertModel.DataType = EDataType.Word.ToString(); | |||
} | |||
} | |||
break; | |||
default: | |||
break; | |||
} | |||
} | |||
return address; | |||
return plcConvertModel; | |||
} | |||
} | |||
@@ -17,6 +17,8 @@ namespace BPASmart.Model | |||
Word = 4, | |||
Dint = 5, | |||
Dword = 6, | |||
Float = 7 | |||
Float = 7, | |||
Double = 8, | |||
String = 9, | |||
} | |||
} |
@@ -0,0 +1,13 @@ | |||
using System; | |||
using System.Collections.Generic; | |||
using System.Linq; | |||
using System.Text; | |||
using System.Threading.Tasks; | |||
namespace BPASmart.Model | |||
{ | |||
public class GlobalVar | |||
{ | |||
public static ICommunicationDevice DeviceType { get; set; } | |||
} | |||
} |
@@ -0,0 +1,14 @@ | |||
using System; | |||
using System.Collections.Generic; | |||
using System.Linq; | |||
using System.Text; | |||
using System.Threading.Tasks; | |||
namespace BPASmart.Model | |||
{ | |||
public class PlcConvertModel | |||
{ | |||
public string Address { get; set; } = string.Empty; | |||
public string DataType { get; set; } = string.Empty; | |||
} | |||
} |
@@ -17,13 +17,8 @@ namespace BPASmart.Model | |||
{ | |||
public class VariableInfo : AlarmSet | |||
{ | |||
private ICommunicationDevice DeviceType = new kinco(); | |||
public VariableInfo(params object[] s) | |||
{ | |||
if (s != null && s.Length >= 0) | |||
{ | |||
DeviceType = s[0] as ICommunicationDevice; | |||
} | |||
CancelCommand = new RelayCommand(() => { IsOpen = false; }); | |||
ConfirmCommand = new RelayCommand(() => { IsOpen = false; }); | |||
} | |||
@@ -56,8 +51,9 @@ namespace BPASmart.Model | |||
{ | |||
_mAddress = value; | |||
OnPropertyChanged(); | |||
string address = AddressConvert.GetInstance.PlcConverter(DeviceType, value); | |||
if (address.Length > 0) RealAddress = address; | |||
var address = AddressConvert.GetInstance.PlcConverter(GlobalVar.DeviceType, value); | |||
if (address.Address.Length > 0) RealAddress = address.Address; | |||
if (DataType.Length <= 0) DataType = address.DataType; | |||
} | |||
} | |||
private string _mAddress = string.Empty; | |||
@@ -112,16 +112,16 @@ namespace BPASmart.VariableManager | |||
private void DataSave() | |||
{ | |||
for (int i = 0; i < Json<CommunicationPar>.Data.CommunicationDevices.Count; i++) | |||
{ | |||
for (int m = 0; m < Json<CommunicationPar>.Data.CommunicationDevices.ElementAt(i).VarTableModels.Count; m++) | |||
{ | |||
var deviceType = Json<CommunicationPar>.Data.CommunicationDevices.ElementAt(i).CommDevice; | |||
var deviceValue = Json<CommunicationPar>.Data.CommunicationDevices.ElementAt(i).VarTableModels.ElementAt(m).Address; | |||
string RealAddress = AddressConvert.GetInstance.PlcConverter(deviceType, deviceValue); | |||
Json<CommunicationPar>.Data.CommunicationDevices.ElementAt(i).VarTableModels.ElementAt(m).RealAddress = RealAddress; | |||
} | |||
} | |||
//for (int i = 0; i < Json<CommunicationPar>.Data.CommunicationDevices.Count; i++) | |||
//{ | |||
// for (int m = 0; m < Json<CommunicationPar>.Data.CommunicationDevices.ElementAt(i).VarTableModels.Count; m++) | |||
// { | |||
// var deviceType = Json<CommunicationPar>.Data.CommunicationDevices.ElementAt(i).CommDevice; | |||
// var deviceValue = Json<CommunicationPar>.Data.CommunicationDevices.ElementAt(i).VarTableModels.ElementAt(m).Address; | |||
// string RealAddress = AddressConvert.GetInstance.PlcConverter(deviceType, deviceValue); | |||
// Json<CommunicationPar>.Data.CommunicationDevices.ElementAt(i).VarTableModels.ElementAt(m).RealAddress = RealAddress; | |||
// } | |||
//} | |||
Json<CommunicationPar>.Save(); | |||
} | |||
@@ -73,6 +73,7 @@ namespace BPASmart.VariableManager.ViewModels | |||
if (varialeInfosIndex >= 0 && varialeInfosIndex < Json<CommunicationPar>.Data.CommunicationDevices.Count) | |||
{ | |||
DeviceType = Json<CommunicationPar>.Data.CommunicationDevices.ElementAt(varialeInfosIndex).CommDevice; | |||
GlobalVar.DeviceType = DeviceType; | |||
varialeInfos = Json<CommunicationPar>.Data.CommunicationDevices.ElementAt(varialeInfosIndex).VarTableModels; | |||
if (varialeInfos.Count <= 0) AddRow(); | |||
} | |||
@@ -272,11 +272,12 @@ | |||
Foreground="{Binding IsRedundant, Converter={StaticResource tabConvert}}" | |||
Text="{Binding ID}" /> | |||
<Grid Grid.Column="1"> | |||
<Grid Grid.Column="1" KeyDown="TextBox_KeyDown"> | |||
<TextBox | |||
Width="{Binding DataContext.NameWidth, RelativeSource={RelativeSource AncestorType=ItemsControl, Mode=FindAncestor}}" | |||
Foreground="{Binding IsRedundant, Converter={StaticResource tabConvert}}" | |||
Style="{StaticResource InputTextboxStyle}" | |||
TabIndex="{Binding ID}" | |||
Text="{Binding VarName}" /> | |||
<Border | |||
BorderBrush="{StaticResource bordColor}" | |||
@@ -286,9 +287,11 @@ | |||
<TextBox | |||
Grid.Column="2" | |||
KeyDown="TextBox_KeyDown" | |||
Width="{Binding DataContext.AddressWidth, RelativeSource={RelativeSource AncestorType=ItemsControl, Mode=FindAncestor}}" | |||
Foreground="{Binding IsRedundant, Converter={StaticResource tabConvert}}" | |||
Style="{StaticResource InputTextboxStyle}" | |||
TabIndex="{Binding ID}" | |||
Text="{Binding Address}" /> | |||
<Grid Grid.Column="3"> | |||
@@ -63,5 +63,19 @@ namespace BPASmart.VariableManager.Views | |||
} | |||
} | |||
private void TextBox_KeyDown(object sender, KeyEventArgs e) | |||
{ | |||
var uie = e.OriginalSource as TextBox; | |||
if (uie != null) | |||
{ | |||
if (e.Key == Key.Enter) | |||
{ | |||
uie.MoveFocus(new TraversalRequest(FocusNavigationDirection.Next)); | |||
e.Handled = true; | |||
} | |||
} | |||
} | |||
} | |||
} |
@@ -7,19 +7,19 @@ | |||
<add key="IsEnableTest" value="false"/> | |||
<!--测试环境--> | |||
<!--<add key="apollouri" value="http://10.2.1.21:28080/"/> | |||
<add key="apollouri" value="http://10.2.1.21:28080/"/> | |||
<add key="AppId" value="test1_HostComputer"/> | |||
<add key ="Namespaces" value="DEV.test1.Config"/>--> | |||
<add key ="Namespaces" value="DEV.test1.Config"/> | |||
<!--开发环境--> | |||
<!--<add key="apollouri" value="http://10.2.1.21:28080/"/> | |||
<!--<add key="apollouri" value="http://47.108.65.220:28080/"/> | |||
<add key="AppId" value="HostComputer"/> | |||
<add key ="Namespaces" value="DEV.Config"/>--> | |||
<!--正式环境--> | |||
<add key="apollouri" value="http://47.108.65.220:28080/"/> | |||
<!--正式环境--> | |||
<!--<add key="apollouri" value="http://47.108.65.220:28080/"/> | |||
<add key="AppId" value="HostComputer"/> | |||
<add key ="Namespaces" value="TEST1.Config"/> | |||
<add key ="Namespaces" value="TEST1.Config"/>--> | |||
<!--阿里云上报启动方式:API 或者 LOCAL--> | |||
<!--API :通过客户端ID,调用接口查询“设备连接信息”--> | |||
@@ -12,6 +12,8 @@ namespace ComputerTestDemo | |||
public Form1() | |||
{ | |||
InitializeComponent(); | |||
bool[] cct = new bool[120]; | |||
GetData(cct); | |||
textBox1.Enabled = false; | |||
button1.Enabled = false; | |||
Json<CommunicationPar>.Read(); | |||
@@ -23,8 +25,17 @@ namespace ComputerTestDemo | |||
})); | |||
} | |||
private TResult GetData<TResult>() | |||
private TResult GetData<TResult>(TResult tc) | |||
{ | |||
if (tc is Array tt) | |||
{ | |||
var len = tt.Length; | |||
var va = tt.GetValue(0); | |||
} | |||
Type type = typeof(TResult); | |||
var name = type.Name; | |||
Debug.WriteLine(name); | |||