Frm_AxisMoveByIO.cs
3.5 KB
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
using DeviceLibrary;
using OnlineStore;
using OnlineStore.Common;
using OnlineStore.LoadCSVLibrary;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace TheMachine
{
public partial class Frm_AxisMoveByIO : Form
{
private List<AxisBean> axisList;
private AxisBean currentAxis;
private string PortName;
private short SlvAddr;
public Frm_AxisMoveByIO()
{
InitializeComponent();
}
public void LoadData(List<AxisBean> axisList)
{
//this.boxBean = equipBase;
this.axisList = axisList;
//axisList = new List<ConfigMoveAxis>(equipBase.Config.moveAxisList);
if (axisList.Count > 0)
{
cmbAxis.Items.Clear();
foreach (var a in axisList)
{
cmbAxis.Items.Add(crc.GetString(a.Config.ProName, a.Config.Explain));
}
cmbAxis.SelectedIndex = 0;
currentAxis = axisList[0];
PortName = axisList[0].Config.DeviceName;
SlvAddr = axisList[0].Config.GetAxisValue();
}
crc.LanguageProcess(this);
}
Thread td;
private void Frm_AxisMoveByIO_Load(object sender, EventArgs e)
{
td = new Thread(new ThreadStart(monitorio));
td.Start();
}
void monitorio() {
bool isrun = false;
while (!IsDisposed) {
Thread.Sleep(10);
if (!AxisManager.IsServeoOn(PortName, SlvAddr))
continue;
var Fwd = IOManager.IOValue(IO_Type.Axis_Fwd_Btn).Equals(IO_VALUE.HIGH);
var Rwd = IOManager.IOValue(IO_Type.Axis_Rwd_Btn).Equals(IO_VALUE.HIGH);
if ((Fwd && Rwd) || (!Fwd && !Rwd))
{
if (isrun)
{
isrun = false;
AxisManager.SuddenStop(currentAxis.Config);
}
}
else
{
if (!isrun)
{
isrun = true;
AxisMove(1* (Fwd?1:-1));
}
}
}
}
private void cmbAxis_SelectedIndexChanged(object sender, EventArgs e)
{
currentAxis = axisList[cmbAxis.SelectedIndex];
PortName = axisList[cmbAxis.SelectedIndex].Config.DeviceName;
SlvAddr = axisList[cmbAxis.SelectedIndex].Config.GetAxisValue();
int targetSpeed = currentAxis.Config.TargetSpeed;
comjSpeed.Items.Clear();
for (int i = 1; i <= 10; i++)
{
comjSpeed.Items.Add(targetSpeed * i / 10);
}
comjSpeed.SelectedIndex = 4;
open();
}
private void open()
{
//timer1.Start();
LogUtil.info("" + "点击【打开伺服】,【" + PortName + "_" + SlvAddr + "】 ");
AxisManager.ServoOn(PortName, SlvAddr);
}
private void AxisMove(int speed)
{
LogUtil.info("" + "【" + PortName + "_" + SlvAddr + "】点动: 速度:" + speed);
AxisManager.SpeedMove(PortName, SlvAddr, speed, 0, 0);
}
}
}