-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathMainWindow.xaml.cs
113 lines (97 loc) · 3.7 KB
/
MainWindow.xaml.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
namespace FocasSimple
{
/// <summary>
/// MainWindow.xaml 的交互逻辑
/// </summary>
public partial class MainWindow : Window
{
ushort h;
short ret;
int MacroVal;
short MacroDec;
Focas1.ODBAXIS CncAxis = new Focas1.ODBAXIS();
Focas1.ODBM CncMacro = new Focas1.ODBM();
Focas1.IODBPMC0 bytPMC = new Focas1.IODBPMC0();
public MainWindow()
{
InitializeComponent();
tbIpAddress.Text = "0.0.0.0";
}
private void CmdRead(object sender, RoutedEventArgs e)
{
// 建立连接,IP地址,端口默认8193,连接延时3s
// 获得library handle
ret = Focas1.cnc_allclibhndl3(tbIpAddress.Text, ushort.Parse(tbPort.Text), 3, out h);
if (ret == Focas1.EW_OK)
{
// 读取绝对位置坐标
Focas1.cnc_absolute2(h, -1, 4 + 4 * Focas1.MAX_AXIS, CncAxis);
// 显示,暂时默认三位小数
tbAbsolutX.Text = String.Format("{0:#####0.000}", (double)CncAxis.data[0] / 1000);
// 读取机械位置坐标
Focas1.cnc_machine(h, -1, 4 + 4 * Focas1.MAX_AXIS, CncAxis);
// 显示,暂时默认三位小数
tbMachineX.Text = String.Format("{0:#####0.000}", (double)CncAxis.data[0] / 1000);
// 读取用户宏变量 #500 数值,保留4位小数
Focas1.cnc_rdmacro(h, 500, 10, CncMacro);
tbVariable500.Text = String.Format("{0:########0.0000}", CncMacro.mcr_val * Math.Pow(0.1, CncMacro.dec_val));
// 读取PMC D200 数值
Focas1.pmc_rdpmcrng(h, 9, 0, 200, 200, 9, bytPMC);
tbPmcD0200.Text = bytPMC.cdata[0].ToString();
// 释放 library handle
Focas1.cnc_freelibhndl(h);
}
else
{
// 检查返回值异常
MessageBox.Show("ret = "+ret.ToString());
}
}
private void CmdWrite(object sender, RoutedEventArgs e)
{
// 建立连接,IP地址,端口默认8193,连接延时3s
ret = Focas1.cnc_allclibhndl3(tbIpAddress.Text, ushort.Parse(tbPort.Text), 3, out h);
if (ret == Focas1.EW_OK)
{
// 写入用户宏变量 #500 数值
// 此处限定4位小数,四舍五入
MacroVal = (int)Math.Round(double.Parse(tbVariable500.Text) * 10000);
MacroDec = 4;
Focas1.cnc_wrmacro(h, 500, 10, MacroVal, MacroDec);
// 写入PMC D200 数值
bytPMC.cdata[0] = Convert.ToByte(tbPmcD0200.Text);
bytPMC.type_a = 9;
bytPMC.type_d = 0;
bytPMC.datano_s = 200;
bytPMC.datano_e = 200;
ret = Focas1.pmc_wrpmcrng(h, 9, bytPMC);
// 释放 library handle
Focas1.cnc_freelibhndl(h);
}
else
{
MessageBox.Show("ret = " + ret.ToString());
}
}
private void CmdExit(object sender, RoutedEventArgs e)
{
this.Close();
}
}
}