-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathMockMessageBasedSession.cs
More file actions
349 lines (281 loc) · 10.6 KB
/
MockMessageBasedSession.cs
File metadata and controls
349 lines (281 loc) · 10.6 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
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Ivi.Visa;
using System.Linq;
namespace VisaTesting
{
/// <summary>
/// A mock implementation of a Visa message-based session
/// </summary>
/// <remarks>
/// All writes and reads are delegated to fields WriteHandler and ReadHandler
/// </remarks>
public class MockMessageBasedSession : IMessageBasedRawIO, IMessageBasedSession
{
public delegate void IWriteHandler(string msg);
/// <summary>
/// This delegate is called whenever the session is written to.
/// The msg parameter is the message that was written.
/// </summary>
public IWriteHandler WriteHandler { get; set; }
public delegate string IReadHandler();
/// <summary>
/// This delegate is called whenever the session is read from.
/// Its return value becomes the read message.
/// </summary>
public IReadHandler ReadHandler { get; set; }
public MockMessageBasedSession()
{
FormattedIO = new Ivi.Visa.FormattedIO.MessageBasedFormattedIO(this);
}
public void Read(byte[] buffer, long index, long count, out long actualCount, out ReadStatus readStatus)
{
string msg = ReadHandler();
byte[] ret = Encoding.ASCII.GetBytes(msg);
if (ret.Length > count)
{
// TODO: buffer excess bytes
throw new Exception($"Buffer has size {count}, read {ret.Length} bytes");
}
actualCount = ret.Length;
readStatus = ReadStatus.EndReceived;
ret.CopyTo(buffer, 0);
}
public void Write(byte[] buffer, long index, long count)
{
string msg = Encoding.ASCII.GetString(buffer.Skip((int)index).Take((int)count).ToArray());
WriteHandler(msg);
}
public void Dispose()
{
}
public byte TerminationCharacter { get; set; }
public bool TerminationCharacterEnabled { get; set; }
public IMessageBasedFormattedIO FormattedIO { get; }
public IMessageBasedRawIO RawIO => this;
public string HardwareInterfaceName => "MockHardwareInterfaceName";
public short HardwareInterfaceNumber => 0x987;
public HardwareInterfaceType HardwareInterfaceType => HardwareInterfaceType.Custom;
public string ResourceClass => "MockResourceClass";
public short ResourceManufacturerId => 0x123;
public string ResourceManufacturerName => "MockManufacturer";
public string ResourceName => "MockResourceName";
// None of the remaining functions are implemented
public IOProtocol IOProtocol { get => throw new NotImplementedException(); set => throw new NotImplementedException(); }
public bool SendEndEnabled { get => throw new NotImplementedException(); set => throw new NotImplementedException(); }
public int EventQueueCapacity { get => throw new NotImplementedException(); set => throw new NotImplementedException(); }
public Version ResourceImplementationVersion => throw new NotImplementedException();
public ResourceLockState ResourceLockState => throw new NotImplementedException();
public Version ResourceSpecificationVersion => throw new NotImplementedException();
public bool SynchronizeCallbacks { get => throw new NotImplementedException(); set => throw new NotImplementedException(); }
public int TimeoutMilliseconds { get => throw new NotImplementedException(); set => throw new NotImplementedException(); }
public event EventHandler<VisaEventArgs> ServiceRequest;
public void AbortAsyncOperation(IVisaAsyncResult result)
{
throw new NotImplementedException();
}
public void AssertTrigger()
{
throw new NotImplementedException();
}
public IVisaAsyncResult BeginRead(int count)
{
throw new NotImplementedException();
}
public IVisaAsyncResult BeginRead(int count, object state)
{
throw new NotImplementedException();
}
public IVisaAsyncResult BeginRead(int count, VisaAsyncCallback callback, object state)
{
throw new NotImplementedException();
}
public IVisaAsyncResult BeginRead(byte[] buffer)
{
throw new NotImplementedException();
}
public IVisaAsyncResult BeginRead(byte[] buffer, object state)
{
throw new NotImplementedException();
}
public IVisaAsyncResult BeginRead(byte[] buffer, long index, long count)
{
throw new NotImplementedException();
}
public IVisaAsyncResult BeginRead(byte[] buffer, long index, long count, object state)
{
throw new NotImplementedException();
}
public IVisaAsyncResult BeginRead(byte[] buffer, VisaAsyncCallback callback, object state)
{
throw new NotImplementedException();
}
public IVisaAsyncResult BeginRead(byte[] buffer, long index, long count, VisaAsyncCallback callback, object state)
{
throw new NotImplementedException();
}
public IVisaAsyncResult BeginWrite(string buffer)
{
throw new NotImplementedException();
}
public IVisaAsyncResult BeginWrite(string buffer, object state)
{
throw new NotImplementedException();
}
public IVisaAsyncResult BeginWrite(string buffer, VisaAsyncCallback callback, object state)
{
throw new NotImplementedException();
}
public IVisaAsyncResult BeginWrite(byte[] buffer)
{
throw new NotImplementedException();
}
public IVisaAsyncResult BeginWrite(byte[] buffer, object state)
{
throw new NotImplementedException();
}
public IVisaAsyncResult BeginWrite(byte[] buffer, long index, long count)
{
throw new NotImplementedException();
}
public IVisaAsyncResult BeginWrite(byte[] buffer, long index, long count, object state)
{
throw new NotImplementedException();
}
public IVisaAsyncResult BeginWrite(byte[] buffer, VisaAsyncCallback callback, object state)
{
throw new NotImplementedException();
}
public IVisaAsyncResult BeginWrite(byte[] buffer, long index, long count, VisaAsyncCallback callback, object state)
{
throw new NotImplementedException();
}
public void Clear()
{
throw new NotImplementedException();
}
public void DisableEvent(EventType eventType)
{
throw new NotImplementedException();
}
public void DiscardEvents(EventType eventType)
{
throw new NotImplementedException();
}
public void EnableEvent(EventType eventType)
{
throw new NotImplementedException();
}
public long EndRead(IVisaAsyncResult result)
{
throw new NotImplementedException();
}
public string EndReadString(IVisaAsyncResult result)
{
throw new NotImplementedException();
}
public long EndWrite(IVisaAsyncResult result)
{
throw new NotImplementedException();
}
public void LockResource()
{
throw new NotImplementedException();
}
public void LockResource(TimeSpan timeout)
{
throw new NotImplementedException();
}
public void LockResource(int timeoutMilliseconds)
{
throw new NotImplementedException();
}
public string LockResource(TimeSpan timeout, string sharedKey)
{
throw new NotImplementedException();
}
public string LockResource(int timeoutMilliseconds, string sharedKey)
{
throw new NotImplementedException();
}
public byte[] Read()
{
throw new NotImplementedException();
}
public byte[] Read(long count)
{
throw new NotImplementedException();
}
public byte[] Read(long count, out ReadStatus readStatus)
{
throw new NotImplementedException();
}
public unsafe void Read(byte* buffer, long index, long count, out long actualCount, out ReadStatus readStatus)
{
throw new NotImplementedException();
}
public StatusByteFlags ReadStatusByte()
{
throw new NotImplementedException();
}
public string ReadString()
{
throw new NotImplementedException();
}
public string ReadString(long count)
{
throw new NotImplementedException();
}
public string ReadString(long count, out ReadStatus readStatus)
{
throw new NotImplementedException();
}
public void UnlockResource()
{
throw new NotImplementedException();
}
public VisaEventArgs WaitOnEvent(EventType eventType)
{
throw new NotImplementedException();
}
public VisaEventArgs WaitOnEvent(EventType eventType, out EventQueueStatus status)
{
throw new NotImplementedException();
}
public VisaEventArgs WaitOnEvent(EventType eventType, int timeoutMilliseconds)
{
throw new NotImplementedException();
}
public VisaEventArgs WaitOnEvent(EventType eventType, TimeSpan timeout)
{
throw new NotImplementedException();
}
public VisaEventArgs WaitOnEvent(EventType eventType, int timeoutMilliseconds, out EventQueueStatus status)
{
throw new NotImplementedException();
}
public VisaEventArgs WaitOnEvent(EventType eventType, TimeSpan timeout, out EventQueueStatus status)
{
throw new NotImplementedException();
}
public void Write(byte[] buffer)
{
throw new NotImplementedException();
}
public unsafe void Write(byte* buffer, long index, long count)
{
throw new NotImplementedException();
}
public void Write(string buffer)
{
throw new NotImplementedException();
}
public void Write(string buffer, long index, long count)
{
throw new NotImplementedException();
}
}
}