Kaynağa Gözat

节卡机器人优化

master
pry 1 yıl önce
ebeveyn
işleme
f18f2ff8d4
6 değiştirilmiş dosya ile 248 ekleme ve 133 silme
  1. +115
    -38
      BPASmartClient.JakaRobot/JaKaHelper.cs
  2. +24
    -24
      BPASmartClient/Control/FoodMenu.xaml
  3. +7
    -8
      WpfApp1/App.xaml
  4. +26
    -9
      WpfApp1/MainWindow.xaml
  5. +75
    -54
      WpfApp1/MainWindow.xaml.cs
  6. +1
    -0
      WpfApp1/WpfApp1.csproj

+ 115
- 38
BPASmartClient.JakaRobot/JaKaHelper.cs Dosyayı Görüntüle

@@ -1,5 +1,7 @@
using BPASmartClient.Helper;
using BPASmartClient.Message;
using System.Net;
using System.Net.NetworkInformation;
using System.Text;

namespace BPASmartClient.JakaRobot
@@ -60,7 +62,7 @@ namespace BPASmartClient.JakaRobot
//public const string SENCE_初始位 = "20000";

#endregion
private int rshd = -1;
public int rshd = -1;
private bool login = false;

/// <summary>
@@ -74,49 +76,124 @@ namespace BPASmartClient.JakaRobot
public bool IsIdle { get; set; } = false;
public bool IsConnected { get { return login; } }
public bool IsDeviceFirstInit { get; set; }
private string IpAddress { get; set; }
private bool IsPingOk { get; set; }

public void Conn(string ip)
{
jakaAPI.create_handler(ip.ToCharArray(), ref rshd);
login = true;
}

public void Connect(string ip)
{
bool ErrorFlag = false;
ThreadManage.GetInstance().StartLong(new Action(() =>
MessageLog.GetInstance.Show("节卡机器人连接中。。。。。");
IpAddress = ip;
Task.Factory.StartNew(() =>
{
if (rshd == -1 || login == false)
while (!IsPingOk)
{
try
{
jakaAPI.create_handler(ip.ToCharArray(), ref rshd);
login = true;
}
catch (Exception ex)
{
if (!ErrorFlag)
{
MessageLog.GetInstance.ShowEx(ex.ToString());
ErrorFlag = true;
login = false;
}
Thread.Sleep(3000);
}
Ping myPing = new Ping();
myPing.PingCompleted += new PingCompletedEventHandler(_myPing_PingCompleted);
myPing.SendAsync(IpAddress, 1000, null);
Thread.Sleep(3000);
}
if (login && IsDeviceFirstInit==false)
});


//bool ErrorFlag = false;
//ThreadManage.GetInstance().StartLong(new Action(() =>
//{
// if (rshd == -1 || login == false)
// {
// try
// {
// jakaAPI.create_handler(ip.ToCharArray(), ref rshd);
// login = true;
// }
// catch (Exception ex)
// {
// if (!ErrorFlag)
// {
// MessageLog.GetInstance.ShowEx(ex.ToString());
// ErrorFlag = true;
// login = false;
// }
// Thread.Sleep(3000);
// }
// }
// if (login && IsDeviceFirstInit == false)
// {
// try
// {
// Power_On();//打开机器人电源
// Thread.Sleep(1000);
// Enable_robot();//机器人上使能
// IsDeviceFirstInit = true;
// MessageLog.GetInstance.Show("机器人已上电使能");
// }
// catch (Exception ex)
// {
// MessageLog.GetInstance.ShowEx("机器人未完成上电和使能");
// }
// }
// Thread.Sleep(5000);
//}), $"节卡机器人连接", true);

}

private void _myPing_PingCompleted(object sender, PingCompletedEventArgs e)
{
if (e.Reply != null && e.Reply.Status == IPStatus.Success)
{
IsPingOk = true;
MessageLog.GetInstance.Show("节卡机器人物理网络准备就绪");
Thread.Sleep(3000);
bool ErrorFlag = false;
ThreadManage.GetInstance().StartLong(new Action(() =>
{
try
if (rshd == -1 || login == false)
{
Power_On();//打开机器人电源
Thread.Sleep(1000);
Enable_robot();//机器人上使能
IsDeviceFirstInit = true;
MessageLog.GetInstance.Show("机器人已上电使能");
try
{
int result = jakaAPI.create_handler(IpAddress.ToCharArray(), ref rshd);
login = true;
MessageLog.GetInstance.Show($"节卡机器人创建连接成功,句柄:{rshd},返回值:{result}");
}
catch (Exception ex)
{
if (!ErrorFlag)
{
MessageLog.GetInstance.ShowEx(ex.ToString());
ErrorFlag = true;
login = false;
}
Thread.Sleep(3000);
}
}
catch (Exception ex)
if (login && IsDeviceFirstInit == false)
{
MessageLog.GetInstance.ShowEx("机器人未完成上电和使能");
try
{
MessageLog.GetInstance.Show("节卡机器人打开电源准备");
Thread.Sleep(2000);
Power_On();//打开机器人电源
Thread.Sleep(1000);
MessageLog.GetInstance.Show("节卡机器人上使能准备");
Enable_robot();//机器人上使能
IsDeviceFirstInit = true;
MessageLog.GetInstance.Show("机器人已上电使能");
}
catch (Exception ex)
{
MessageLog.GetInstance.ShowEx("机器人未完成上电和使能");
}
}
}
Thread.Sleep(5000);
}), $"节卡机器人连接", true);
Thread.Sleep(5000);
}), $"节卡机器人连接", true);
}
}

public void Power_On()
{
if (login)
@@ -129,10 +206,10 @@ namespace BPASmartClient.JakaRobot
{
MessageLog.GetInstance.ShowEx(ave.ToString());
}
//catch (Exception ex)
//{
// MessageLog.GetInstance.ShowEx(ex.ToString());
//}
catch (Exception ex)
{
MessageLog.GetInstance.ShowEx(ex.ToString());
}
}
else
{
@@ -324,8 +401,8 @@ namespace BPASmartClient.JakaRobot
{
try
{
//加载
p: file = Programname.ToCharArray();
//加载
p: file = Programname.ToCharArray();
MessageLog.GetInstance.Show($"调用文件名:{Programname}");
status = new JKTYPE.ProgramState();
jakaAPI.get_program_state(ref rshd, ref status);


+ 24
- 24
BPASmartClient/Control/FoodMenu.xaml Dosyayı Görüntüle

@@ -1,12 +1,14 @@
<UserControl x:Class="Control.FoodMenu"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:local="clr-namespace:Control"
mc:Ignorable="d"
d:DesignHeight="450" d:DesignWidth="800"
Name="FoodMenu">
<UserControl
x:Class="Control.FoodMenu"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:local="clr-namespace:Control"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
Name="FoodMenu1"
d:DesignHeight="450"
d:DesignWidth="800"
mc:Ignorable="d">
<UserControl.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
@@ -14,19 +16,22 @@
<ResourceDictionary Source="/BPASmartClient.CustomResource;component/Themes/MyStyle.xaml" />
</ResourceDictionary.MergedDictionaries>
<Style TargetType="ListBoxItem">
<Setter Property="Margin" Value="2"/>
<Setter Property="FontSize" Value="22"/>
<Setter Property="FontWeight" Value="Black"/>
<Setter Property="Background" Value="Transparent"/>
<Setter Property="FontFamily" Value="楷体"/>
<Setter Property="Margin" Value="2" />
<Setter Property="FontSize" Value="22" />
<Setter Property="FontWeight" Value="Black" />
<Setter Property="Background" Value="Transparent" />
<Setter Property="FontFamily" Value="楷体" />
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="ListBoxItem">
<Border BorderBrush="Black" BorderThickness="0" Background="Transparent">
<ControlTemplate TargetType="ListBoxItem">
<Border
Background="Transparent"
BorderBrush="Black"
BorderThickness="0">
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="80*"/>
<ColumnDefinition Width="20*"/>
<ColumnDefinition Width="80*" />
<ColumnDefinition Width="20*" />
</Grid.ColumnDefinitions>
</Grid>
</Border>
@@ -36,10 +41,5 @@
</Style>
</ResourceDictionary>
</UserControl.Resources>
<Grid>
<ListBox>
</ListBox>
</Grid>
<Grid />
</UserControl>

+ 7
- 8
WpfApp1/App.xaml Dosyayı Görüntüle

@@ -1,9 +1,8 @@
<Application x:Class="WpfApp1.App"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="clr-namespace:WpfApp1"
StartupUri="MainWindow.xaml">
<Application.Resources>
</Application.Resources>
<Application
x:Class="WpfApp1.App"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="clr-namespace:WpfApp1"
StartupUri="MainWindow.xaml">
<Application.Resources />
</Application>

+ 26
- 9
WpfApp1/MainWindow.xaml Dosyayı Görüntüle

@@ -1,12 +1,29 @@
<Window x:Class="WpfApp1.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:WpfApp1"
mc:Ignorable="d"
Title="MainWindow" Height="450" Width="800">
<Window
x:Class="WpfApp1.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:local="clr-namespace:WpfApp1"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
Title="MainWindow"
Width="800"
Height="450"
mc:Ignorable="d">
<Grid>

<Button
Width="100"
Height="30"
Margin="36,24,664,381"
Content="连接" Click="Button_Click" />
<Button
Width="100"
Height="30"
Margin="167,24,533,381"
Content="上电" Click="Button_Click_1" />
<Button
Width="100"
Height="30"
Margin="300,24,400,381"
Content="使能" Click="Button_Click_2" />
</Grid>
</Window>

+ 75
- 54
WpfApp1/MainWindow.xaml.cs Dosyayı Görüntüle

@@ -12,6 +12,7 @@ using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using BPASmartClient.JakaRobot;
using BPASmartClient.S7Net;

namespace WpfApp1
@@ -24,67 +25,87 @@ namespace WpfApp1
public MainWindow()
{
InitializeComponent();
SiemensHelper siemensHelper = new SiemensHelper();
siemensHelper.Connect(S7.Net.CpuType.S71200, "192.168.101.16");
if (siemensHelper.IsConnected)
{
siemensHelper.WriteString(S7.Net.DataType.DataBlock, 1, 0, "cccc");
var res = siemensHelper.ReadClass<XL_Start_DB>(1);
//SiemensHelper siemensHelper = new SiemensHelper();
//siemensHelper.Connect(S7.Net.CpuType.S71200, "192.168.101.16");
//if (siemensHelper.IsConnected)
//{
// siemensHelper.WriteString(S7.Net.DataType.DataBlock, 1, 0, "cccc");
// var res = siemensHelper.ReadClass<XL_Start_DB>(1);

//XL_Start_DB xL_Start_DB = new XL_Start_DB();
//xL_Start_DB.RecipeCode = "编码";
//xL_Start_DB.RecipeName = "名称";
//xL_Start_DB.StockCode = 1;
//xL_Start_DB.TrayCode = 2;
//for (int i = 0; i < xL_Start_DB.Powder.Length; i++)
//{
// xL_Start_DB.Powder[i].Powder_Name = $"料{i}";
// xL_Start_DB.Powder[i].Powder_Weight = (float)(5.0 + i);
//}
//for (int i = 0; i < xL_Start_DB.Material.Length; i++)
//{
// xL_Start_DB.Material[i].Material_Name = $"原料{i}";
// xL_Start_DB.Material[i].Material_Weight = (float)(50.0 + i);
// xL_Start_DB.Material[i].Material_BarrelNum = (short)(i + 1);
//}
//xL_Start_DB.Order_Request_ACK = true;
//xL_Start_DB.Order_Request = true;
// //XL_Start_DB xL_Start_DB = new XL_Start_DB();
// //xL_Start_DB.RecipeCode = "编码";
// //xL_Start_DB.RecipeName = "名称";
// //xL_Start_DB.StockCode = 1;
// //xL_Start_DB.TrayCode = 2;
// //for (int i = 0; i < xL_Start_DB.Powder.Length; i++)
// //{
// // xL_Start_DB.Powder[i].Powder_Name = $"料{i}";
// // xL_Start_DB.Powder[i].Powder_Weight = (float)(5.0 + i);
// //}
// //for (int i = 0; i < xL_Start_DB.Material.Length; i++)
// //{
// // xL_Start_DB.Material[i].Material_Name = $"原料{i}";
// // xL_Start_DB.Material[i].Material_Weight = (float)(50.0 + i);
// // xL_Start_DB.Material[i].Material_BarrelNum = (short)(i + 1);
// //}
// //xL_Start_DB.Order_Request_ACK = true;
// //xL_Start_DB.Order_Request = true;

//for (int i = 0; i < xL_Start_DB.Standby.Length; i++)
//{
// xL_Start_DB.Standby[i] = (short)(i + 100);
// xL_Start_DB.Standby1[i] = (short)(i + 300);
//}
// //for (int i = 0; i < xL_Start_DB.Standby.Length; i++)
// //{
// // xL_Start_DB.Standby[i] = (short)(i + 100);
// // xL_Start_DB.Standby1[i] = (short)(i + 300);
// //}

res.RecipeCode = "";
res.RecipeName = "";
res.StockCode = 0;
res.TrayCode = 0;
for (int i = 0; i < res.Powder.Length; i++)
{
res.Powder[i].Powder_Name = "";
res.Powder[i].Powder_Weight = 0;
}
for (int i = 0; i < res.Material.Length; i++)
{
res.Material[i].Material_Name = "";
res.Material[i].Material_Weight = 0;
res.Material[i].Material_BarrelNum = 0;
}
res.Order_Request_ACK = false;
res.Order_Request = false;
// res.RecipeCode = "";
// res.RecipeName = "";
// res.StockCode = 0;
// res.TrayCode = 0;
// for (int i = 0; i < res.Powder.Length; i++)
// {
// res.Powder[i].Powder_Name = "";
// res.Powder[i].Powder_Weight = 0;
// }
// for (int i = 0; i < res.Material.Length; i++)
// {
// res.Material[i].Material_Name = "";
// res.Material[i].Material_Weight = 0;
// res.Material[i].Material_BarrelNum = 0;
// }
// res.Order_Request_ACK = false;
// res.Order_Request = false;

for (int i = 0; i < res.Standby.Length; i++)
{
res.Standby[i] = 0;
res.Standby1[i] = 0;
}
// for (int i = 0; i < res.Standby.Length; i++)
// {
// res.Standby[i] = 0;
// res.Standby1[i] = 0;
// }

siemensHelper.WriteClass<XL_Start_DB>(res, 1);
// siemensHelper.WriteClass<XL_Start_DB>(res, 1);

var res1 = siemensHelper.ReadClass<XL_Start_DB>(1);
}
// var res1 = siemensHelper.ReadClass<XL_Start_DB>(1);
//}

}

JaKaHelper jaKaHelper = new JaKaHelper();

private void Button_Click(object sender, RoutedEventArgs e)
{
jaKaHelper.Conn("192.168.0.12");
MessageBox.Show($"连接成功,{jaKaHelper.rshd}");
}

private void Button_Click_1(object sender, RoutedEventArgs e)
{
jaKaHelper.Power_On();
MessageBox.Show($"上电成功,{jaKaHelper.rshd}");
}

private void Button_Click_2(object sender, RoutedEventArgs e)
{
jaKaHelper.Enable_robot();
MessageBox.Show($"使能成功,{jaKaHelper.rshd}");
}
}
}

+ 1
- 0
WpfApp1/WpfApp1.csproj Dosyayı Görüntüle

@@ -8,6 +8,7 @@
</PropertyGroup>

<ItemGroup>
<ProjectReference Include="..\BPASmartClient.JakaRobot\BPASmartClient.JakaRobot.csproj" />
<ProjectReference Include="..\BPASmartClient.S7Net\BPASmartClient.S7Net.csproj" />
</ItemGroup>



Yükleniyor…
İptal
Kaydet