frmBarcodeControl.cs
35.3 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
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Xml;
using System.Data.SqlClient;
using System.IO;
using System.Threading;
using System.Net;
using System.Net.Sockets;
using MyClassLib;
using MyControlLib;
using HaierExe04;
using System.Xml.Linq;
namespace Weld
{
public partial class frmBarcodeControl : MyFrmReg
{
public frmBarcodeControl()
{
InitializeComponent();
this.Text =this.Text+ "--20181005 V2.2.2";
DataInit();
}
#region
private IPEndPoint ServerInfo;//存放服务器的IP和端口信息
private Socket ServerSocket;//服务端运行的SOCKET
private Socket Robot1_Socket;//
private Socket Robot2_Socket;//
private Socket Robot3_Socket;//
private Thread ServerThread;//服务端运行的线程
private Socket[] ClientSocket;//为客户端建立的SOCKET连接
private int ClientNumb;//存放客户端数量
private byte[] MsgBuffer;//存放消息数据
private string ServerIp;//定义服务端IP地址
private int LocalPort = 6000;//定义端口号
private Boolean ROBOT_READY = false;
private string[] tags = new string[] { "P1", "P2", "P3", "P4", "P5", "W1", "W2", "W3", "W4", "W5" };
private string[] elements = new string[] { "x", "y", "z", "E1", "E2", "E3", "E4", "a", "b", "c", "d", "e", "f" };
#endregion
#region 数据相关的初始化
private void DataInit()
{
try
{
ServerIp = Properties.Settings.Default.ServerIP;
string hostName = System.Net.Dns.GetHostName();
System.Net.IPHostEntry ipEntry = System.Net.Dns.GetHostEntry(hostName);
//IPAddress[] addresslist = Dns.GetHostByName(Dns.GetHostName()).AddressList;
IPAddress[] addresslist = ipEntry.AddressList;
int i = 0;
bool flag = false;
for (i = 0; i < addresslist.Length; i++)
{
if (!addresslist[i].IsIPv6LinkLocal)
{
if (ServerIp == addresslist[i].ToString())
{
flag = true;
}
else
{
LogExecute.WriteInfoLog(string.Format("{0}获取的IP地址{1}", DateTime.Now.ToString(), addresslist[i].ToString()));
}
}
}
if (flag == false)
{
LogExecute.WriteInfoLog("获取的网卡的IP地址中不存在服务器地址:" + ServerIp);
MessageBox.Show("获取的网卡的IP地址中不存在服务器地址:" + ServerIp);
}
LocalPort = Properties.Settings.Default.Port;
timerScan.Interval = Properties.Settings.Default.Interval;
txb_ip.Text = Properties.Settings.Default.ServerIP;
txb_port.Text = LocalPort.ToString();
timerScan.Enabled = false;
ROBOT_READY = false;
refreshButton();
//滚动条 初始化
ucErrorDisplay1.MoveEnable = true;
ucErrorDisplay1.Interval = 400;
ucErrorDisplay1.SpeedMove = 25;
//加载xml 文件
//DirectoryInfo directory = new DirectoryInfo(Application.StartupPath+"/xmlfile");
//XmlDocument xmlDocument = new XmlDocument();
//xmlDocument.Load(Application.StartupPath + "/xmlfile/ext.xml");
}
catch (Exception ex)
{
LogExecute.WriteExceptionLog("DataInit", ex);
}
}
#endregion
#region
/// <summary>
/// //开启服务器 侦听客户端的连接请求
/// </summary>
private bool SocketListen()
{
bool flag = false;
try
{
ServerSocket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
//提供一个 IP 地址,指示服务器应侦听所有网络接口上的客户端活动
//IPAddress ip = IPAddress.Any;
IPAddress ip = IPAddress.Parse(ServerIp);
ServerInfo = new IPEndPoint(ip, LocalPort);
ServerSocket.Bind(ServerInfo);//将SOCKET接口和IP端口绑定
ServerSocket.Listen(20);//开始监听,并且挂起数为25
ClientSocket = new Socket[20];//为客服端提供连接个数
MsgBuffer = new byte[65535];//消息数据的大小
ClientNumb = 0;//客服端数据从0开始计数
ServerThread = new Thread(new ThreadStart(RecieveAccept));//将接受客户端连接的方法委托给线程
ServerThread.Start();//线程开始运行
CheckForIllegalCrossThreadCalls = false;//不捕获对错误线程的调用
string strWrite = "服务器" + ip.ToString() + "于" + DateTime.Now.ToString() + "开始运行" + "\r\n";
txb_ip.Text = ip.ToString();
txb_port.Text = LocalPort.ToString();
txb_listenTime.Text = DateTime.Now.ToString();
listBox1.Items.Add(strWrite);
LogExecute.WriteInfoLog(strWrite);
return true;
}
catch (Exception ex)
{
LogExecute.WriteExceptionLog("SocketListen", ex);
return flag;
}
}
/// <summary>
/// //接受客户端连接的方法
/// </summary>
private void RecieveAccept()
{
while (true)
{
//Accept 以同步方式从侦听套接字的连接请求队列中提取第一个挂起的连接请求,然后创建并返回新的 Socket。
//在阻止模式中,Accept 将一直处于阻止状态,直到传入的连接尝试排入队列。连接被接受后,原来的 Socket 继续将传入的连接请求排入队列,直到您关闭它。
//bool writeflag = false;
try
{
//todo:判断是否以前有该IP的连接
//string remoteEndPoint = ServerSocket.RemoteEndPoint.ToString();
//string ip=ServerSocket.RemoteEndPoint.ToString().Split(':')[0];
//
ClientSocket[ClientNumb] = ServerSocket.Accept();
ClientSocket[ClientNumb].BeginReceive(MsgBuffer, 0, MsgBuffer.Length, SocketFlags.None, new AsyncCallback(RecieveCallBack), ClientSocket[ClientNumb]);
string strWrite = "客户端" + ClientSocket[ClientNumb].RemoteEndPoint.ToString() + "于" + DateTime.Now.ToString() + "成功连接服务器";
LogExecute.WriteInfoLog(strWrite);
string ippoint = ClientSocket[ClientNumb].RemoteEndPoint.ToString();
this.Invoke(new Action(()=> {
comboBox1.Items.Add(ippoint);
listBox1.Items.Add(strWrite);
listBox1.SelectedIndex = 0;
}));
ClientNumb++;
if(ClientNumb == 10)
{
ClientNumb = 0;
}
listBox1.Items.Add("ClientNumb:" + ClientNumb);
}
catch (SocketException ex)
{
LogExecute.WriteExceptionLog("RecieveAccept", ex);
}
}
}
/// <summary>
/// 条码长度
/// </summary>
private int barcodeLen = 10;
/// <summary>
///
/// 帧格式开头
/// </summary>
private string barcodeSTX = ('\x02').ToString();
/// <summary>
/// 帧格式结束
/// </summary>
private string barcodeETX = ('\x03').ToString();
/// <summary>
/// //回发数据给客户端-
/// </summary>
/// <param name="AR"></param>
private void RecieveCallBack(IAsyncResult AR)
{
lock (AR)
{
Socket RSocket = (Socket)AR.AsyncState;
try
{
int REnd = RSocket.EndReceive(AR);
string strRemoteIP = RSocket.RemoteEndPoint.ToString().Split(':')[0];
#region//1获取对应的IP地址 分析相应的处理
//step1: 确认是否为正确的条码信息
string strMsg = Encoding.ASCII.GetString(MsgBuffer).Substring(0, REnd);
string strIP = strRemoteIP;
if (strMsg != "")
{
// step2: 判断传入的数据为
this.Invoke(new Action(() =>
{
if (rtx_rec.TextLength >= 2000)
{
rtx_rec.Text = "";
}
rtx_rec.AppendText(strMsg);
ParseXmlInfo(RSocket, strMsg);
LogExecute.WriteLineDataLog(strMsg);
}));
//处理xml 字符串
//ParseXmlInfo(strMsg.Trim('\r').Trim('\n'));
}
#endregion
if (RSocket.Poll(1000,SelectMode.SelectRead) == false)
RSocket.BeginReceive(MsgBuffer, 0, MsgBuffer.Length, 0, new AsyncCallback(RecieveCallBack), RSocket);
}
catch (Exception ex)
{
if (ex is SocketException)
{
SocketException soex = (SocketException)ex;
LogExecute.WriteExceptionLog(soex.ErrorCode + ":" + soex.Message, ex);
//if (soex.ErrorCode == 10053)//客户端主动关闭10053
//{
// RSocket.Close();
//}
//if (soex.ErrorCode == 10054)//客户端主动关闭10054
//{
// RSocket.Close();
//}
}
else
{
LogExecute.WriteExceptionLog("receievecallback", ex);
RSocket.BeginReceive(MsgBuffer, 0, MsgBuffer.Length, 0, new AsyncCallback(RecieveCallBack), RSocket);
}
}
}
}
#endregion
#region 自定义函数
/// <summary>
/// 解析xml 字符串
/// </summary>
/// <param name="str_xml"></param>
private void ParseXmlInfo(Socket socket, string str_xml)
{
if (socket.RemoteEndPoint.ToString().Split(':')[0] != null)
{
try
{
byte[] sends = ASCIIEncoding.ASCII.GetBytes(rtx_send.Text);
socket.Send(sends);
textBox1.Text = "发送:" + rtx_send.Text;
if (listBox1.Items.Count > 100)
{
listBox1.Items.Clear();
}
handerInfo(socket, str_xml);
LogExecute.WriteInfoLog(rtx_send.Text);
}
catch (SocketException ex)
{
listBox1.Items.Add(ex.Message);
Console.WriteLine(ex.Message);
}
}
}
private void sendMessage(string str_xml)
{
}
private bool IsSocketConnected(Socket s)
{
return !((s.Poll(1000, SelectMode.SelectRead) && (s.Available == 0)) || !s.Connected);
}
private void handerInfo(Socket socket, string message)
{
if(message == HaierExe04.Constant.ROBOT_CONNECT)
{
listBox1.Items.Add("机器人请求连接");
socket.Send(ASCIIEncoding.ASCII.GetBytes(Constant.CONFIRM_OK));
listBox1.Items.Add("上位机接收到请求并告诉机器人");
}
if(message == HaierExe04.Constant.ROBOT_ASK_TESK)
{
listBox1.Items.Add("机器人就绪,请求发送任务");
ROBOT_READY = true;
socket.Send(ASCIIEncoding.ASCII.GetBytes(Constant.CONFIRM_OK));
refreshButton();
// socket.Send(ASCIIEncoding.ASCII.GetBytes(Constant.TASK_START_WELD));
// listBox1.Items.Add("发送机器人开始焊接的任务");
}
if(message == HaierExe04.Constant.TASK_ROBOT_BACK_OK || message == HaierExe04.Constant.TASK_START_WELD_OK
|| message == HaierExe04.Constant.TASK_START_CLEAN_OK || message == HaierExe04.Constant.TASK_WELD_STATION_1_OK
|| message == HaierExe04.Constant.TASK_WELD_STATION_2_OK)
{
listBox1.Items.Add("机器人完成任务");
socket.Send(ASCIIEncoding.ASCII.GetBytes(Constant.CONFIRM_OK));
}
if(message == HaierExe04.Constant.ROBOT_STATION_1 || message == HaierExe04.Constant.ROBOT_STATION_2)
{
listBox1.Items.Add("机器人开始焊接");
socket.Send(ASCIIEncoding.ASCII.GetBytes(Constant.WELD_INFO));
}
}
public XmlNode GetXmlValue(string xml, string tag)
{
XmlDocument xmlDoc = new XmlDocument();
xmlDoc.LoadXml("<?xml version=\"1.0\" encoding=\"utf-8\"?>" + "<PData><CODE>11</CODE><NAME>kkkk</NAME></PData>");
XmlNode rootNode = xmlDoc.SelectSingleNode("PData");
foreach (XmlNode xxNode in rootNode.ChildNodes)
{
string TAG = xxNode.Name;
string value = xxNode.InnerText;
listBox1.Items.Add("TAG:" + TAG + " value:" + value);
}
return rootNode;
}
private void refreshButton()
{
if(ROBOT_READY)
{
startBtn.Enabled = true;
cleanBtn.Enabled = true;
backBtn.Enabled = true;
station1Btn.Enabled = true;
station2Btn.Enabled = true;
} else
{
startBtn.Enabled = false;
cleanBtn.Enabled = false;
backBtn.Enabled = false;
station1Btn.Enabled = false;
station2Btn.Enabled = false;
}
}
#endregion
/// <summary>
/// 定时器事件函数
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void timerScan_Tick(object sender, EventArgs e)
{
try
{
}
catch (Exception ex)
{
LogExecute.WriteExceptionLog("TimerScan", ex);
}
}
/// <summary>
/// 开启服务程序
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void toolStripButton2_Click(object sender, EventArgs e)
{
try
{
if (SocketListen() == true)
{
toolStripButton2.Enabled = false;
toolStripButton1.Enabled = true;
timerScan.Enabled = true;
}
else
{
toolStripButton1.Enabled = false;
toolStripButton2.Enabled = true;
timerScan.Enabled = false;
}
}
catch (Exception)
{
throw;
}
}
/// <summary>
/// 关闭服务程序
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void toolStripButton3_Click(object sender, EventArgs e)
{
try
{
if (ServerThread.IsAlive)
{
ServerThread.Abort();
ServerSocket.Close();
//MasterPLC2.Close();
}
}
catch (Exception ex)
{
LogExecute.WriteExceptionLog("ServerThread", ex);
}
finally
{
toolStripButton2.Enabled = true;
timerScan.Enabled = false;
}
}
/// <summary>
/// 退出系统
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void toolStripButton1_Click(object sender, EventArgs e)
{
this.Close();
}
private void frmBarcodeControl_FormClosing(object sender, FormClosingEventArgs e)
{
if (MessageBox.Show(this, "你确定要退出系统,系统将无法运行", this.Text, MessageBoxButtons.OKCancel) == DialogResult.OK)
{
e.Cancel = false;
if (ServerThread != null && ServerThread.IsAlive)
{
ServerThread.Abort();
ServerSocket.Close();
//ServerThread.close();
}
}
else
{
e.Cancel = true;
}
}
private void button1_Click(object sender, EventArgs e)
{
string ip = comboBox1.SelectedItem.ToString();
foreach (Socket socket in ClientSocket)
{
if (socket is null) continue;
if (socket.RemoteEndPoint.ToString().Split(':')[0] == ip)
{
byte[] sends = ASCIIEncoding.ASCII.GetBytes(rtx_send.Text);
socket.Send(sends);
listBox1.Items.Add(string.Format("Time:{0}RemoteIP:{1} send:{2}", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff"), ip, rtx_send.Text));
if (listBox1.Items.Count > 100)
{
listBox1.Items.Clear();
}
LogExecute.WriteInfoLog(rtx_send.Text);
}
}
}
//导入Excel
private void toolStripSplitButton3_ButtonClick(object sender, EventArgs e)
{
OpenFileDialog dialog = new OpenFileDialog();
dialog.Filter = "Xml文件|*.xml";
if (dialog.ShowDialog() == DialogResult.OK)
{
string filename = dialog.FileName;
frmInput input = new frmInput();
XmlDocument xmlDoc = new XmlDocument();
try
{
xmlDoc.Load(filename); //加载XML文档
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
//throw ex; //这里可以定义你自己的异常处理
}
// praseXML(filename);
frmInput.equipment.MODEL = xmlDoc.SelectSingleNode("/PData/Receive/Model").InnerText;
frmInput.equipment.TYPE = xmlDoc.SelectSingleNode("/PData/Receive/Type").InnerText;
frmInput.equipment.P1X = xmlDoc.SelectSingleNode("/PData/P1/x").InnerText;
frmInput.equipment.P1Y = xmlDoc.SelectSingleNode("/PData/P1/y").InnerText;
frmInput.equipment.P1Z = xmlDoc.SelectSingleNode("/PData/P1/z").InnerText;
frmInput.equipment.P1E1= xmlDoc.SelectSingleNode("/PData/P1/E1").InnerText;
frmInput.equipment.P1E2 = xmlDoc.SelectSingleNode("/PData/P1/E2").InnerText;
frmInput.equipment.P1E3 = xmlDoc.SelectSingleNode("/PData/P1/E3").InnerText;
frmInput.equipment.P1E4 = xmlDoc.SelectSingleNode("/PData/P1/E4").InnerText;
frmInput.equipment.P2X = xmlDoc.SelectSingleNode("/PData/P2/x").InnerText;
frmInput.equipment.P2Y = xmlDoc.SelectSingleNode("/PData/P2/y").InnerText;
frmInput.equipment.P2Z = xmlDoc.SelectSingleNode("/PData/P2/z").InnerText;
frmInput.equipment.P2E1 = xmlDoc.SelectSingleNode("/PData/P2/E1").InnerText;
frmInput.equipment.P2E2 = xmlDoc.SelectSingleNode("/PData/P2/E2").InnerText;
frmInput.equipment.P2E3 = xmlDoc.SelectSingleNode("/PData/P2/E3").InnerText;
frmInput.equipment.P2E4 = xmlDoc.SelectSingleNode("/PData/P2/E4").InnerText;
frmInput.equipment.P3X = xmlDoc.SelectSingleNode("/PData/P3/x").InnerText;
frmInput.equipment.P3Y = xmlDoc.SelectSingleNode("/PData/P3/y").InnerText;
frmInput.equipment.P3Z = xmlDoc.SelectSingleNode("/PData/P3/z").InnerText;
frmInput.equipment.P3E1 = xmlDoc.SelectSingleNode("/PData/P3/E1").InnerText;
frmInput.equipment.P3E2 = xmlDoc.SelectSingleNode("/PData/P3/E2").InnerText;
frmInput.equipment.P3E3 = xmlDoc.SelectSingleNode("/PData/P3/E3").InnerText;
frmInput.equipment.P3E4 = xmlDoc.SelectSingleNode("/PData/P3/E4").InnerText;
frmInput.equipment.P4X = xmlDoc.SelectSingleNode("/PData/P4/x").InnerText;
frmInput.equipment.P4Y = xmlDoc.SelectSingleNode("/PData/P4/y").InnerText;
frmInput.equipment.P4Z = xmlDoc.SelectSingleNode("/PData/P4/z").InnerText;
frmInput.equipment.P4E1 = xmlDoc.SelectSingleNode("/PData/P4/E1").InnerText;
frmInput.equipment.P4E2 = xmlDoc.SelectSingleNode("/PData/P4/E2").InnerText;
frmInput.equipment.P4E3 = xmlDoc.SelectSingleNode("/PData/P4/E3").InnerText;
frmInput.equipment.P4E4 = xmlDoc.SelectSingleNode("/PData/P4/E4").InnerText;
frmInput.equipment.P5X = xmlDoc.SelectSingleNode("/PData/P5/x").InnerText;
frmInput.equipment.P5Y = xmlDoc.SelectSingleNode("/PData/P5/y").InnerText;
frmInput.equipment.P5Z = xmlDoc.SelectSingleNode("/PData/P5/z").InnerText;
frmInput.equipment.P5E1 = xmlDoc.SelectSingleNode("/PData/P5/E1").InnerText;
frmInput.equipment.P5E2 = xmlDoc.SelectSingleNode("/PData/P5/E2").InnerText;
frmInput.equipment.P5E3 = xmlDoc.SelectSingleNode("/PData/P5/E3").InnerText;
frmInput.equipment.P5E4 = xmlDoc.SelectSingleNode("/PData/P5/E4").InnerText;
frmInput.equipment.W1A = xmlDoc.SelectSingleNode("/PData/W1/a").InnerText;
frmInput.equipment.W1B = xmlDoc.SelectSingleNode("/PData/W1/b").InnerText;
frmInput.equipment.W1C = xmlDoc.SelectSingleNode("/PData/W1/c").InnerText;
frmInput.equipment.W1D = xmlDoc.SelectSingleNode("/PData/W1/d").InnerText;
frmInput.equipment.W1E = xmlDoc.SelectSingleNode("/PData/W1/e").InnerText;
frmInput.equipment.W1F = xmlDoc.SelectSingleNode("/PData/W1/f").InnerText;
frmInput.equipment.W2A = xmlDoc.SelectSingleNode("/PData/W2/a").InnerText;
frmInput.equipment.W2B = xmlDoc.SelectSingleNode("/PData/W2/b").InnerText;
frmInput.equipment.W2C = xmlDoc.SelectSingleNode("/PData/W2/c").InnerText;
frmInput.equipment.W2D = xmlDoc.SelectSingleNode("/PData/W2/d").InnerText;
frmInput.equipment.W2E = xmlDoc.SelectSingleNode("/PData/W2/e").InnerText;
frmInput.equipment.W2F = xmlDoc.SelectSingleNode("/PData/W2/f").InnerText;
frmInput.equipment.W3A = xmlDoc.SelectSingleNode("/PData/W3/a").InnerText;
frmInput.equipment.W3B = xmlDoc.SelectSingleNode("/PData/W3/b").InnerText;
frmInput.equipment.W3C = xmlDoc.SelectSingleNode("/PData/W3/c").InnerText;
frmInput.equipment.W3D = xmlDoc.SelectSingleNode("/PData/W3/d").InnerText;
frmInput.equipment.W3E = xmlDoc.SelectSingleNode("/PData/W3/e").InnerText;
frmInput.equipment.W3F = xmlDoc.SelectSingleNode("/PData/W3/f").InnerText;
frmInput.equipment.W4A = xmlDoc.SelectSingleNode("/PData/W4/a").InnerText;
frmInput.equipment.W4B = xmlDoc.SelectSingleNode("/PData/W4/b").InnerText;
frmInput.equipment.W4C = xmlDoc.SelectSingleNode("/PData/W4/c").InnerText;
frmInput.equipment.W4D = xmlDoc.SelectSingleNode("/PData/W4/d").InnerText;
frmInput.equipment.W4E = xmlDoc.SelectSingleNode("/PData/W4/e").InnerText;
frmInput.equipment.W4F = xmlDoc.SelectSingleNode("/PData/W4/f").InnerText;
frmInput.equipment.W5A = xmlDoc.SelectSingleNode("/PData/W5/a").InnerText;
frmInput.equipment.W5B = xmlDoc.SelectSingleNode("/PData/W5/b").InnerText;
frmInput.equipment.W5C = xmlDoc.SelectSingleNode("/PData/W5/c").InnerText;
frmInput.equipment.W5D = xmlDoc.SelectSingleNode("/PData/W5/d").InnerText;
frmInput.equipment.W5E = xmlDoc.SelectSingleNode("/PData/W5/e").InnerText;
frmInput.equipment.W5F = xmlDoc.SelectSingleNode("/PData/W5/f").InnerText;
frmInput.equipment.BASEX = xmlDoc.SelectSingleNode("/PData/Base/x").InnerText;
frmInput.equipment.BASEY = xmlDoc.SelectSingleNode("/PData/Base/y").InnerText;
frmInput.equipment.BASEZ = xmlDoc.SelectSingleNode("/PData/Base/z").InnerText;
frmInput.equipment.BASEA = xmlDoc.SelectSingleNode("/PData/Base/a").InnerText;
frmInput.equipment.BASEB = xmlDoc.SelectSingleNode("/PData/Base/b").InnerText;
frmInput.equipment.BASEC = xmlDoc.SelectSingleNode("/PData/Base/c").InnerText;
}
}
private void sendCommand(String command)
{
ROBOT_READY = false;
refreshButton();
foreach (Socket socket in ClientSocket)
{
if (socket is null) continue;
if (!IsSocketConnected(socket)) continue;
if (socket.RemoteEndPoint.ToString().Split(':')[0] != null)
{
try
{
byte[] sends = ASCIIEncoding.ASCII.GetBytes(command);
socket.Send(sends);
textBox1.Text = "发送:" + command;
listBox1.Items.Add(string.Format("Time:{0} send:{1}", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff"), command));
if (listBox1.Items.Count > 100)
{
listBox1.Items.Clear();
}
LogExecute.WriteInfoLog(rtx_send.Text);
}
catch (SocketException ex)
{
listBox1.Items.Add(ex.Message);
Console.WriteLine(ex.Message);
}
break;
}
}
}
private void startWeld()
{
}
private void cbx_clear_CheckedChanged(object sender, EventArgs e)
{
rtx_rec.Text = "";
}
private void txb_ip_TextChanged(object sender, EventArgs e)
{
}
private void frmBarcodeControl_Load(object sender, EventArgs e)
{
}
private void textBox1_TextChanged(object sender, EventArgs e)
{
}
private void backBtn_Click(object sender, EventArgs e)
{
sendCommand(Constant.TASK_ROBOT_BACK);
}
private void cleanBtn_Click(object sender, EventArgs e)
{
sendCommand(Constant.TASK_CLEAN_WELD);
listBox1.Items.Add("机器人清理焊接枪");
}
private void startBtn_Click(object sender, EventArgs e)
{
sendCommand(Constant.TASK_START_WELD);
listBox1.Items.Add("机器人准备焊接");
}
private void station1Btn_Click(object sender, EventArgs e)
{
sendCommand(Constant.TASK_WELD_STATION_1);
}
private void station2Btn_Click(object sender, EventArgs e)
{
sendCommand(Constant.TASK_WELD_STATION_2);
}
private void toolStripSplitButton2_ButtonClick(object sender, EventArgs e)
{
frmInput input = new frmInput();
DialogResult dialogResult = input.ShowDialog();
if(dialogResult == DialogResult.Cancel)
{
Constant.WELD_INFO = buildWeldInfo(frmInput.equipment);
}
}
private String buildWeldInfo(frmInput.Equipment equipment)
{
StringBuilder builder = new StringBuilder();
builder.Append("<PData><Receive><Model>");
builder.Append(equipment.MODEL);
builder.Append("</Model><Type>");
builder.Append(equipment.TYPE);
builder.Append("</Type></Receive><P1><x>");
builder.Append(equipment.P1X);
builder.Append("</x><y>");
builder.Append(equipment.P1Y);
builder.Append("</y><z>");
builder.Append(equipment.P1Z);
builder.Append("</z><E1>");
builder.Append(equipment.P1E1);
builder.Append("</E1><E2>");
builder.Append(equipment.P1E2);
builder.Append("</E2><E3>");
builder.Append(equipment.P1E3);
builder.Append("</E3><E4>");
builder.Append(equipment.P1E4);
builder.Append("</E4></P1><P2><x>");
builder.Append(equipment.P2X);
builder.Append("</x><y>");
builder.Append(equipment.P2Y);
builder.Append("</y><z>");
builder.Append(equipment.P2Z);
builder.Append("</z><E1>");
builder.Append(equipment.P2E1);
builder.Append("</E1><E2>");
builder.Append(equipment.P2E2);
builder.Append("</E2><E3>");
builder.Append(equipment.P2E3);
builder.Append("</E3><E4>");
builder.Append(equipment.P2E4);
builder.Append("</E4></P2><P3><x>");
builder.Append(equipment.P3X);
builder.Append("</x><y>");
builder.Append(equipment.P3Y);
builder.Append("</y><z>");
builder.Append(equipment.P3Z);
builder.Append("</z><E1>");
builder.Append(equipment.P3E1);
builder.Append("</E1><E2>");
builder.Append(equipment.P3E2);
builder.Append("</E2><E3>");
builder.Append(equipment.P3E3);
builder.Append("</E3><E4>");
builder.Append(equipment.P3E4);
builder.Append("</E4></P3><P4><x>");
builder.Append(equipment.P4X);
builder.Append("</x><y>");
builder.Append(equipment.P4Y);
builder.Append("</y><z>");
builder.Append(equipment.P4Z);
builder.Append("</z><E1>");
builder.Append(equipment.P4E1);
builder.Append("</E1><E2>");
builder.Append(equipment.P4E2);
builder.Append("</E2><E3>");
builder.Append(equipment.P4E3);
builder.Append("</E3><E4>");
builder.Append(equipment.P4E4);
builder.Append("</E4></P4><P5><x>");
builder.Append(equipment.P5X);
builder.Append("</x><y>");
builder.Append(equipment.P5Y);
builder.Append("</y><z>");
builder.Append(equipment.P5Z);
builder.Append("</z><E1>");
builder.Append(equipment.P5E1);
builder.Append("</E1><E2>");
builder.Append(equipment.P5E2);
builder.Append("</E2><E3>");
builder.Append(equipment.P5E3);
builder.Append("</E3><E4>");
builder.Append(equipment.P5E4);
builder.Append("</E4></P5><W1><a>");
builder.Append(equipment.W1A);
builder.Append("</a><b>");
builder.Append(equipment.W1B);
builder.Append("</b><c>");
builder.Append(equipment.W1C);
builder.Append("</c><d>");
builder.Append(equipment.W1D);
builder.Append("</d><e>");
builder.Append(equipment.W1E);
builder.Append("</e><f>");
builder.Append(equipment.W1F);
builder.Append("</f></W1><W2><a>");
builder.Append(equipment.W2A);
builder.Append("</a><b>");
builder.Append(equipment.W2B);
builder.Append("</b><c>");
builder.Append(equipment.W2C);
builder.Append("</c><d>");
builder.Append(equipment.W2D);
builder.Append("</d><e>");
builder.Append(equipment.W2E);
builder.Append("</e><f>");
builder.Append(equipment.W2F);
builder.Append("</f></W2><W3><a>");
builder.Append(equipment.W3A);
builder.Append("</a><b>");
builder.Append(equipment.W3B);
builder.Append("</b><c>");
builder.Append(equipment.W3C);
builder.Append("</c><d>");
builder.Append(equipment.W3D);
builder.Append("</d><e>");
builder.Append(equipment.W3E);
builder.Append("</e><f>");
builder.Append(equipment.W3F);
builder.Append("</f></W3><W4><a>");
builder.Append(equipment.W4A);
builder.Append("</a><b>");
builder.Append(equipment.W4B);
builder.Append("</b><c>");
builder.Append(equipment.W4C);
builder.Append("</c><d>");
builder.Append(equipment.W4D);
builder.Append("</d><e>");
builder.Append(equipment.W4E);
builder.Append("</e><f>");
builder.Append(equipment.W4F);
builder.Append("</f></W4><W5><a>");
builder.Append(equipment.W5A);
builder.Append("</a><b>");
builder.Append(equipment.W5B);
builder.Append("</b><c>");
builder.Append(equipment.W5C);
builder.Append("</c><d>");
builder.Append(equipment.W5D);
builder.Append("</d><e>");
builder.Append(equipment.W5E);
builder.Append("</e><f>");
builder.Append(equipment.W5F);
builder.Append("</f></W5><Base><x>");
builder.Append(equipment.BASEX);
builder.Append("</x><y>");
builder.Append(equipment.BASEY);
builder.Append("</y><z>");
builder.Append(equipment.BASEZ);
builder.Append("</z><a>");
builder.Append(equipment.BASEA);
builder.Append("</a><b>");
builder.Append(equipment.BASEB);
builder.Append("</b><c>");
builder.Append(equipment.BASEC);
builder.Append("</c></Base></PData>");
String info = builder.ToString();
return info;
}
}
}