-
Notifications
You must be signed in to change notification settings - Fork 0
/
Form1.cs
140 lines (124 loc) · 5.66 KB
/
Form1.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
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
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Net;
using System.Net.Sockets;
using System.Threading;
namespace Pilatus_Snap_WinFormApp
{
public partial class MainForm : Form
{
public MainForm()
{
InitializeComponent();
}
private void setthreshold_Click(object sender, EventArgs e)
{
// initialize IP address of Pilatus 200K and its port
String server = ipAddress_textBox.Text;
String portString = portNumber_textBox.Text;
Int32 port = Int32.Parse(portString);
// create new session with Pilatus 200K
TcpClient session_Pilatus = new TcpClient(server, port);
// initialize stream
NetworkStream stream = session_Pilatus.GetStream();
// set number of images
String setthresholdString = setthresholdCmd_textBox.Text + "\n";
Byte[] data = System.Text.Encoding.ASCII.GetBytes(setthresholdString);
stream.Write(data, 0, data.Length);
// Buffer to store the response bytes.
data = new Byte[256];
// String to store the response ASCII representation.
String responseData_setthreshold = String.Empty;
// Read Pilatus's response
Int32 bytes = stream.Read(data, 0, data.Length);
responseData_setthreshold = System.Text.Encoding.ASCII.GetString(data, 0, bytes);
data = null;
pilatusResponse_richTextBox.Text = responseData_setthreshold;
Thread.Sleep(250);
// Close everything
stream.Flush();
stream.Close();
session_Pilatus.Close();
}
private void takeImage_Click(object sender, EventArgs e)
{
// initialize IP address of Pilatus 200K and its port
String server = ipAddress_textBox.Text;
String portString = portNumber_textBox.Text;
Int32 port = Int32.Parse(portString);
// create new session with Pilatus 200K
TcpClient session_Pilatus = new TcpClient(server, port);
// initialize stream
NetworkStream stream = session_Pilatus.GetStream();
// set number of images
String niString = "ni " + ni_textBox.Text + "\n";
Byte[] data = System.Text.Encoding.ASCII.GetBytes(niString);
stream.Write(data, 0, data.Length);
// Buffer to store the response bytes.
data = new Byte[256];
// String to store the response ASCII representation.
String responseData_ni = String.Empty;
// Read Pilatus's response
Int32 bytes = stream.Read(data, 0, data.Length);
responseData_ni = System.Text.Encoding.ASCII.GetString(data, 0, bytes);
data = null;
Thread.Sleep(250);
// set exposure time
String exptString = "expt " + expt_textBox.Text + "\n";
data = System.Text.Encoding.ASCII.GetBytes(exptString);
stream.Write(data, 0, data.Length);
// Read Pilatus's response
data = new Byte[256];
// String to store the response ASCII representation.
String responseData_expt = String.Empty;
bytes = stream.Read(data, 0, data.Length);
responseData_expt = System.Text.Encoding.ASCII.GetString(data, 0, bytes);
data = null;
Thread.Sleep(250);
// set exposure period
String exppString = "expp " + expp_textBox.Text + "\n";
data = System.Text.Encoding.ASCII.GetBytes(exppString);
stream.Write(data, 0, data.Length);
// Read Pilatus's response
data = new Byte[256];
// String to store the response ASCII representation.
String responseData_expp = String.Empty;
// Read Pilatus's response
bytes = stream.Read(data, 0, data.Length);
responseData_expp = System.Text.Encoding.ASCII.GetString(data, 0, bytes);
data = null;
Thread.Sleep(250);
// take image, do exposure
String expoString = "expo " + imageName_textBox.Text + ".tif" + "\n";
data = System.Text.Encoding.ASCII.GetBytes(expoString);
stream.Write(data, 0, data.Length);
// Read Pilatus's response
data = new Byte[256];
// String to store the response ASCII representation.
String responseData_expo = String.Empty;
// Read Pilatus's response
bytes = stream.Read(data, 0, data.Length);
responseData_expo = System.Text.Encoding.ASCII.GetString(data, 0, bytes);
data = null;
Thread.Sleep(250);
pilatusResponse_richTextBox.Text = responseData_ni + responseData_expt + responseData_expp + responseData_expo;
Int32 niNumber = Int32.Parse(ni_textBox.Text);
float niFloatNumber = Convert.ToSingle(niNumber);
float exppFloatNumber = float.Parse(expp_textBox.Text);
float wait_in_ms_FloatNumber = niFloatNumber * exppFloatNumber * 1000 + 1000;
Int32 wait_in_ms = Convert.ToInt32(wait_in_ms_FloatNumber);
Thread.Sleep(wait_in_ms);
// Close everything
stream.Flush();
stream.Close();
session_Pilatus.Close();
}
}
}