ソースを参照

地址数据修改

样式分支
pry 2年前
コミット
5ecd317162
11個のファイルの変更102行の追加36行の削除
  1. +22
    -10
      BPASmart.Model/CommDeviceModel/AddressConvert.cs
  2. +3
    -1
      BPASmart.Model/Enums/EDataType.cs
  3. +13
    -0
      BPASmart.Model/GlobalVar.cs
  4. +14
    -0
      BPASmart.Model/PlcConvertModel.cs
  5. +3
    -7
      BPASmart.Model/VariableInfo.cs
  6. +10
    -10
      BPASmart.VariableManager/App.xaml.cs
  7. +1
    -0
      BPASmart.VariableManager/ViewModels/VariableConfigViewModel.cs
  8. +4
    -1
      BPASmart.VariableManager/Views/VariableConfig.xaml
  9. +14
    -0
      BPASmart.VariableManager/Views/VariableConfig.xaml.cs
  10. +6
    -6
      BPASmartClient/App.config
  11. +12
    -1
      ComputerTestDemo/Form1.cs

+ 22
- 10
BPASmart.Model/CommDeviceModel/AddressConvert.cs ファイルの表示

@@ -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;
}

}


+ 3
- 1
BPASmart.Model/Enums/EDataType.cs ファイルの表示

@@ -17,6 +17,8 @@ namespace BPASmart.Model
Word = 4,
Dint = 5,
Dword = 6,
Float = 7
Float = 7,
Double = 8,
String = 9,
}
}

+ 13
- 0
BPASmart.Model/GlobalVar.cs ファイルの表示

@@ -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; }
}
}

+ 14
- 0
BPASmart.Model/PlcConvertModel.cs ファイルの表示

@@ -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;
}
}

+ 3
- 7
BPASmart.Model/VariableInfo.cs ファイルの表示

@@ -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;


+ 10
- 10
BPASmart.VariableManager/App.xaml.cs ファイルの表示

@@ -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();
}


+ 1
- 0
BPASmart.VariableManager/ViewModels/VariableConfigViewModel.cs ファイルの表示

@@ -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();
}


+ 4
- 1
BPASmart.VariableManager/Views/VariableConfig.xaml ファイルの表示

@@ -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">


+ 14
- 0
BPASmart.VariableManager/Views/VariableConfig.xaml.cs ファイルの表示

@@ -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;
}
}

}
}
}

+ 6
- 6
BPASmartClient/App.config ファイルの表示

@@ -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
- 1
ComputerTestDemo/Form1.cs ファイルの表示

@@ -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);


読み込み中…
キャンセル
保存