@@ -1,5 +1,7 @@ | |||||
using BPASmartClient.Helper; | using BPASmartClient.Helper; | ||||
using BPASmartClient.Message; | using BPASmartClient.Message; | ||||
using System.Net; | |||||
using System.Net.NetworkInformation; | |||||
using System.Text; | using System.Text; | ||||
namespace BPASmartClient.JakaRobot | namespace BPASmartClient.JakaRobot | ||||
@@ -60,7 +62,7 @@ namespace BPASmartClient.JakaRobot | |||||
//public const string SENCE_初始位 = "20000"; | //public const string SENCE_初始位 = "20000"; | ||||
#endregion | #endregion | ||||
private int rshd = -1; | |||||
public int rshd = -1; | |||||
private bool login = false; | private bool login = false; | ||||
/// <summary> | /// <summary> | ||||
@@ -74,49 +76,124 @@ namespace BPASmartClient.JakaRobot | |||||
public bool IsIdle { get; set; } = false; | public bool IsIdle { get; set; } = false; | ||||
public bool IsConnected { get { return login; } } | public bool IsConnected { get { return login; } } | ||||
public bool IsDeviceFirstInit { get; set; } | 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) | 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() | public void Power_On() | ||||
{ | { | ||||
if (login) | if (login) | ||||
@@ -129,10 +206,10 @@ namespace BPASmartClient.JakaRobot | |||||
{ | { | ||||
MessageLog.GetInstance.ShowEx(ave.ToString()); | MessageLog.GetInstance.ShowEx(ave.ToString()); | ||||
} | } | ||||
//catch (Exception ex) | |||||
//{ | |||||
// MessageLog.GetInstance.ShowEx(ex.ToString()); | |||||
//} | |||||
catch (Exception ex) | |||||
{ | |||||
MessageLog.GetInstance.ShowEx(ex.ToString()); | |||||
} | |||||
} | } | ||||
else | else | ||||
{ | { | ||||
@@ -324,8 +401,8 @@ namespace BPASmartClient.JakaRobot | |||||
{ | { | ||||
try | try | ||||
{ | { | ||||
//加载 | |||||
p: file = Programname.ToCharArray(); | |||||
//加载 | |||||
p: file = Programname.ToCharArray(); | |||||
MessageLog.GetInstance.Show($"调用文件名:{Programname}"); | MessageLog.GetInstance.Show($"调用文件名:{Programname}"); | ||||
status = new JKTYPE.ProgramState(); | status = new JKTYPE.ProgramState(); | ||||
jakaAPI.get_program_state(ref rshd, ref status); | jakaAPI.get_program_state(ref rshd, ref status); | ||||
@@ -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> | <UserControl.Resources> | ||||
<ResourceDictionary> | <ResourceDictionary> | ||||
<ResourceDictionary.MergedDictionaries> | <ResourceDictionary.MergedDictionaries> | ||||
@@ -14,19 +16,22 @@ | |||||
<ResourceDictionary Source="/BPASmartClient.CustomResource;component/Themes/MyStyle.xaml" /> | <ResourceDictionary Source="/BPASmartClient.CustomResource;component/Themes/MyStyle.xaml" /> | ||||
</ResourceDictionary.MergedDictionaries> | </ResourceDictionary.MergedDictionaries> | ||||
<Style TargetType="ListBoxItem"> | <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 Property="Template"> | ||||
<Setter.Value> | <Setter.Value> | ||||
<ControlTemplate TargetType="ListBoxItem"> | |||||
<Border BorderBrush="Black" BorderThickness="0" Background="Transparent"> | |||||
<ControlTemplate TargetType="ListBoxItem"> | |||||
<Border | |||||
Background="Transparent" | |||||
BorderBrush="Black" | |||||
BorderThickness="0"> | |||||
<Grid> | <Grid> | ||||
<Grid.ColumnDefinitions> | <Grid.ColumnDefinitions> | ||||
<ColumnDefinition Width="80*"/> | |||||
<ColumnDefinition Width="20*"/> | |||||
<ColumnDefinition Width="80*" /> | |||||
<ColumnDefinition Width="20*" /> | |||||
</Grid.ColumnDefinitions> | </Grid.ColumnDefinitions> | ||||
</Grid> | </Grid> | ||||
</Border> | </Border> | ||||
@@ -36,10 +41,5 @@ | |||||
</Style> | </Style> | ||||
</ResourceDictionary> | </ResourceDictionary> | ||||
</UserControl.Resources> | </UserControl.Resources> | ||||
<Grid> | |||||
<ListBox> | |||||
</ListBox> | |||||
</Grid> | |||||
<Grid /> | |||||
</UserControl> | </UserControl> |
@@ -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> | </Application> |
@@ -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> | <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> | </Grid> | ||||
</Window> | </Window> |
@@ -12,6 +12,7 @@ using System.Windows.Media; | |||||
using System.Windows.Media.Imaging; | using System.Windows.Media.Imaging; | ||||
using System.Windows.Navigation; | using System.Windows.Navigation; | ||||
using System.Windows.Shapes; | using System.Windows.Shapes; | ||||
using BPASmartClient.JakaRobot; | |||||
using BPASmartClient.S7Net; | using BPASmartClient.S7Net; | ||||
namespace WpfApp1 | namespace WpfApp1 | ||||
@@ -24,67 +25,87 @@ namespace WpfApp1 | |||||
public MainWindow() | public MainWindow() | ||||
{ | { | ||||
InitializeComponent(); | 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}"); | |||||
} | |||||
} | } | ||||
} | } |
@@ -8,6 +8,7 @@ | |||||
</PropertyGroup> | </PropertyGroup> | ||||
<ItemGroup> | <ItemGroup> | ||||
<ProjectReference Include="..\BPASmartClient.JakaRobot\BPASmartClient.JakaRobot.csproj" /> | |||||
<ProjectReference Include="..\BPASmartClient.S7Net\BPASmartClient.S7Net.csproj" /> | <ProjectReference Include="..\BPASmartClient.S7Net\BPASmartClient.S7Net.csproj" /> | ||||
</ItemGroup> | </ItemGroup> | ||||