-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTeradyneICT.cs
380 lines (352 loc) · 20.6 KB
/
TeradyneICT.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
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
using Virinco.WATS.Interface;
using Virinco.WATS.Integration.TextConverter;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using System.Globalization;
namespace TeradyneConverter
{
public class TeradyneICT : TextConverterBase
{
string currentPartNumber = "";
string currentRevision = "1";
string currentSequenceName = "";
//Main events
enum Event
{
Aborted,
Pass,
Fail,
Error,
SystemError,
Cancelled,
ReturnToDiagnose
}
Dictionary<char, Event> mainEvents = new Dictionary<char, Event>()
{
{'?', Event.Aborted},
{'"', Event.Pass},
{'/', Event.Fail},
{'*', Event.Error},
{'&', Event.SystemError},
{'!', Event.Cancelled},
{']', Event.ReturnToDiagnose}
};
public class PrefixUnit
{
public string Symbol { get; set; }
public double UnitFactor { get; set; }
public double GetValue(double value) { return value * UnitFactor; }
public double GetValueInv(double value) { return value / UnitFactor; }
}
//PrefixUnit
Dictionary<string, PrefixUnit> prefixUnit = new Dictionary<string, PrefixUnit>()
{
{"P",new PrefixUnit() {Symbol="p",UnitFactor=0.000000000001}}, //Pico
{"N",new PrefixUnit() {Symbol="n",UnitFactor=0.000000001}}, //Nano
{"U",new PrefixUnit() {Symbol="µ",UnitFactor=0.000001}}, //Micro
{"M",new PrefixUnit() {Symbol="m",UnitFactor=0.001}}, //Milli
{"",new PrefixUnit() {Symbol="" ,UnitFactor=1.0}}, //No unit prefix
{"K",new PrefixUnit() {Symbol="K",UnitFactor=1000}}, //Kilo
{"MEG",new PrefixUnit() {Symbol="M",UnitFactor=1000000}} //Mega
};
public double ConvertFromToUnit(double value, PrefixUnit from, PrefixUnit to)
{
double realValue = from.GetValue(value);
return to.GetValueInv(realValue);
}
public class TestType
{
public string Description { get; set; }
public string Unit { get; set; }
//public TestType(string description, string unit) { Description = unit; Unit = unit; }
}
Dictionary<string, TestType> testTypes = new Dictionary<string, TestType>()
{
{"AC", new TestType(){Description="MEAS DVM ACV",Unit="V"}},
{"AI", new TestType(){Description="MEAS ACI ACM",Unit=""}},
{"AR", new TestType(){Description="TEST ARITH",Unit=""}},
{"AV", new TestType(){Description="MEAS ACV ACM",Unit=""}},
{"AY", new TestType(){Description="MEAS {DVM | {DMM {VOLTAGE|CURRENT}}}",Unit=""}},
{"CS", new TestType(){Description="MEAS ACZ CS",Unit=""}},
{"CP", new TestType(){Description="MEAS ACZ CP",Unit="F"}},
{"DC", new TestType(){Description="MEAS DVM DCV",Unit="V"}},
{"DD", new TestType(){Description="MEAS ACZ D",Unit=""}},
{"EV", new TestType(){Description="FTM EVENT",Unit=""}},
{"HZ", new TestType(){Description="FTM FREQ",Unit=""}},
{"I", new TestType(){Description="MEAS DCM DCI",Unit=""}},
{"IS", new TestType(){Description="TEST DCS DCI",Unit=""}},
{"LP", new TestType(){Description="MEAS ACZ LP",Unit=""}},
{"LS", new TestType(){Description="MEAS ACZ LS",Unit=""}},
{"QQ", new TestType(){Description="MEAS ACZ Q",Unit=""}},
{"R", new TestType(){Description="MEAS R",Unit="ohm"}},
{"RA", new TestType(){Description="FTM RATIO",Unit=""}},
{"RP", new TestType(){Description="MEAS ACZ RP",Unit=""}},
{"RS", new TestType(){Description="MEAS ACZ RS",Unit=""}},
{"S", new TestType(){Description="FTM PERIOD",Unit=""}},
{"TI", new TestType(){Description="FTM INTERNAL",Unit=""}},
{"V", new TestType(){Description="MEAS DCM DCV",Unit=""}},
{"VS", new TestType(){Description="TEST DCS DCV",Unit=""}},
{"XS", new TestType(){Description="MEAS ACZ XS",Unit=""}},
{"XP", new TestType(){Description="MEAS ACZ XP",Unit=""}},
{"ZM", new TestType(){Description="MEAS ACZ Z",Unit=""}},
{"PS", new TestType(){Description="MEAS",Unit=""}},
};
Dictionary<string, string> genFailures = new Dictionary<string, string>()
{
{"(S","SHORTS test, failed"},
{"(O","OPENS test, failed"},
{"(B","BUSTEST, failure caused by bus"},
{"(C","SCRATCHPROBING connection failure"},
{"(F","CONTACT fixture failure"}
};
Dictionary<char, int> compRefGroupConters = null;
void FixSequence(string compRef)
{
char compRefType = compRef[0]; //Use 1 char to group
if (!compRefGroupConters.ContainsKey(compRefType)) //Make sure a counter exist
compRefGroupConters.Add(compRefType, 0);
if (currentSequence.Name[0] != compRefType)
{
compRefGroupConters[compRefType]++;
currentSequence = currentUUT.GetRootSequenceCall().AddSequenceCall(String.Format("{0}-Group{1}", compRefType, compRefGroupConters[compRefType]));
}
}
int reportCount = 0;
protected override string PreProcessLine(string line)
{
return base.PreProcessLine(line);
}
protected override bool ProcessMatchedLine(TextConverterBase.SearchFields.SearchMatch match, ref TextConverterBase.ReportReadState readState)
{
if (match == null) return true;
switch (match.matchField.fieldName)
{
case "StartProgram":
//e.g. {FileName}(?<PartNumber>[^_]+)_
//e.g. (?<Drive>[a-zA-Z]*:)?(?<Path>(?:\\[^\\]+)+\\)?(?<FileName>[^\\]+)\.obc\x5B(?<DateTime>[1-9-A-Z]+ +[0-9:]+)
string regExPN =ConverterParameters["partNumberRegEx"];
string fileName = (string)match.GetSubField("FileName");
string path = (string)match.GetSubField("Path");
if (regExPN.StartsWith("{FileName}"))
currentPartNumber=new Regex(regExPN.Replace("{FileName}","")).Match(fileName).Groups["PartNumber"].Value;
else if (regExPN.StartsWith("{Path}"))
currentPartNumber = new Regex(regExPN.Replace("{Path}", "")).Match(fileName).Groups["PartNumber"].Value;
currentSequenceName = match.completeLine.Substring(0, match.completeLine.IndexOf('['));
break;
case "StartTest":
compRefGroupConters = new Dictionary<char, int>();
currentUUT.PartNumber = currentPartNumber;
currentUUT.PartRevisionNumber = currentRevision;
currentUUT.SequenceName = currentSequenceName;
if (!String.IsNullOrEmpty(converterArguments["stationName"])) currentUUT.StationName = converterArguments["stationName"]; //Use StationName in converter.xml if specified
break;
case "StartPanel":
for (int i = 1; i < match.regExpMatch.Groups.Count; i++)
if (!string.IsNullOrEmpty(match.regExpMatch.Groups[i].Value))
{
currentUUT.TestSocketIndex = (short)i;
break;
}
break;
case "MainEvent":
Event ev = mainEvents[(char)match.GetSubField("Event")];
switch (ev)
{
case Event.Aborted:
case Event.Cancelled:
currentUUT.Status = UUTStatusType.Terminated;
break;
case Event.Pass:
currentUUT.Status = UUTStatusType.Passed;
break;
case Event.Fail:
currentUUT.Status = UUTStatusType.Failed;
currentUUT.GetRootSequenceCall().Status = StepStatusType.Failed;
break;
case Event.SystemError:
case Event.Error:
currentUUT.Status = UUTStatusType.Error;
break;
case Event.ReturnToDiagnose:
//Ignore
break;
default:
break;
}
reportCount++;
TimeSpan elapsed = (DateTime)match.GetSubField("DateTime") - currentUUT.StartDateTime;
currentUUT.ExecutionTime = elapsed.TotalMilliseconds / 1000.0;
logStream.WriteLine("{0}: Submitting UUT #{1} (SN={2})",
DateTime.Now.ToString("dd.MM.yy HH:mm:ss.ff"), reportCount, currentUUT.SerialNumber);
try
{
if (string.IsNullOrEmpty(currentUUT.PartNumber))
{
//If partnumber not specified in the file, try using file name up to .
Regex ex = new Regex(@"^(?<PartNumber>[^.]*)");
Match m = ex.Match(apiRef.ConversionSource.SourceFile.Name);
if (m.Groups.Count > 0)
currentUUT.PartNumber = m.Groups[0].Value;
else
currentUUT.PartNumber = apiRef.ConversionSource.SourceFile.Name; //Use whole partno
}
//Skip UUT if it doesn't have any steps and staus == terminated
if (!(currentUUT.Status == UUTStatusType.Terminated && currentStep.StepOrderNumber <= 1))
apiRef.Submit(currentUUT);
}
catch (Exception ex)
{
ParseError(String.Format("Submitting UUT in ProcessMatchedLine: {0}", ex.Message + (ex.InnerException == null ? "" : "\r\nInner: " + ex.InnerException.Message)), currentUUT.SerialNumber);
throw;
}
CreateDefaultUUT();
if (!String.IsNullOrEmpty(converterArguments["stationName"])) currentUUT.StationName = converterArguments["stationName"]; //Use StationName in converter.xml if specified
break;
case "FailuresGen":
currentStep = currentSequence.AddStringValueStep(genFailures[(string)match.GetSubField("Key")]);
currentStep.Status = StepStatusType.Failed;
currentStep.Parent.Status = StepStatusType.Failed;
currentStep.ReportText = (string)match.GetSubField("Info");
currentUUT.GetRootSequenceCall().Status = StepStatusType.Failed;
break;
case "Measure":
string compRef = (string)match.GetSubField("CompRef");
FixSequence(compRef);
string result = (string)match.GetSubField("Result");
string meas = (string)match.GetSubField("meas");
PrefixUnit measUnit = prefixUnit[(string)match.GetSubField("measU")];
string lowLimit = (string)match.GetSubField("LowLim");
PrefixUnit lowLimitUnit = prefixUnit[(string)match.GetSubField("LowLimU")];
string highLimit = (string)match.GetSubField("HighLim");
PrefixUnit highLimitUnit = prefixUnit[(string)match.GetSubField("HighLimU")];
string testType = (string)match.GetSubField("Type");
string stepName = testType == "" ? compRef : string.Format("{0}({1})", compRef, testType);
if (meas != "")
{
currentStep = currentSequence.AddNumericLimitStep(stepName);
//double measDouble = (double)ConvertStringToAny(meas, typeof(double), null, currentCulture);
double measDouble = ConvertFromToUnit((double)ConvertStringToAny(meas, typeof(double), null, currentCulture), measUnit, lowLimitUnit);
double lowLimitDouble = ConvertFromToUnit((double)ConvertStringToAny(lowLimit, typeof(double), null, currentCulture), lowLimitUnit, lowLimitUnit);
double highLimitDouble = ConvertFromToUnit((double)ConvertStringToAny(highLimit, typeof(double), null, currentCulture), highLimitUnit, lowLimitUnit);
string units = String.Format("{0}({1})", measUnit.Symbol, testType);
if (lowLimit == "" && highLimit == "")
((NumericLimitStep)currentStep).AddTest(measDouble, units);
else if (lowLimit != "" && highLimit == "")
currentNumLimTest = ((NumericLimitStep)currentStep).AddTest(measDouble, CompOperatorType.GE, lowLimitDouble, units);
else if (highLimit != "" && lowLimit == "")
currentNumLimTest = ((NumericLimitStep)currentStep).AddTest(measDouble, CompOperatorType.LE, highLimitDouble, units);
else
currentNumLimTest = ((NumericLimitStep)currentStep).AddTest(measDouble, CompOperatorType.GELE, lowLimitDouble, highLimitDouble, units);
}
else //No Measure
{
if (testType != "IS" && testType != "VS") //Filter these measures
{
currentStep = currentSequence.AddPassFailStep(stepName);
((PassFailStep)currentStep).AddTest(result == "=");
}
else break;
}
if (result != "=" && result != "#")
{
currentStep.Status = StepStatusType.Failed;
currentStep.Parent.Status = StepStatusType.Failed;
currentUUT.GetRootSequenceCall().Status = StepStatusType.Failed;
if (!string.IsNullOrEmpty(testType)) currentStep.StepErrorMessage = testTypes[testType].Description;
}
if (result == "#")
currentStep.Status = StepStatusType.Done;
if ((string)match.GetSubField("Message") != "")
currentStep.ReportText = (string)match.GetSubField("Message");
break;
default:
break;
}
return true;
}
Dictionary<string,string> ExtraArguments =
new Dictionary<string, string>
{
{"startProgramRegEx",@"(?<Drive>[a-zA-Z]*:)(?<Path>.*\\)?(?<FileName>[^\\]+)\.obc\[(?<DateTime>.*)"},
{"partNumberRegEx", @"{FileName}(?<PartNumber>[^_]+)_?" },
{"socketNumberRegEx", @"TOP_OF_LOOP-(?:(A)|(B)|(C)|(D)|(E)|(F)|(G)|(H))" }
};
public TeradyneICT() : base()
{
foreach (var keyValuePair in ExtraArguments)
{
ConverterParameters.Add(keyValuePair.Key,keyValuePair.Value);
}
}
public TeradyneICT(IDictionary<string, string> args)
: base(args)
{
//Existing converters need to merge these, note - users should reinstall converter in client to get these as Client parameters
foreach (var keyValuePair in ExtraArguments)
{
if (!ConverterParameters.ContainsKey(keyValuePair.Key)) ConverterParameters.Add(keyValuePair.Key, keyValuePair.Value);
}
currentCulture = new CultureInfo("en-US"); //Use english culture info
//Custom properties
searchFields.AddExactField(UUTField.PartNumber, ReportReadState.InTest, "WATS_partNumber=", null, typeof(string));
searchFields.AddExactField(UUTField.PartRevisionNumber, ReportReadState.InTest, "WATS_partRevision=", null, typeof(string));
searchFields.AddExactField(UUTField.SequenceName, ReportReadState.InTest, "WATS_sequenceName=", null, typeof(string));
searchFields.AddExactField(UUTField.SequenceVersion, ReportReadState.InTest, "WATS_sequenceVersion=", null, typeof(string));
searchFields.AddExactField(UUTField.Operator, ReportReadState.InTest, "WATS_operator=", null, typeof(string));
searchFields.AddExactField(UUTField.StationName, ReportReadState.InTest, "WATS_stationName=", null, typeof(string));
//F:\BOARDS\ABB_DA\43420_BIO2_PROGRAM\43420_BIO2.obc[31-JUL-12 14:17:35
string regStartProgram = ConverterParameters["startProgramRegEx"];
SearchFields.RegExpSearchField fmt = searchFields.AddRegExpField("StartProgram", ReportReadState.InHeader, regStartProgram, "", typeof(string));
fmt.AddSubField("Drive", typeof(string));
fmt.AddSubField("Path", typeof(string));
fmt.AddSubField("FileName", typeof(string));
fmt.AddSubField("DateTime", typeof(DateTime), "dd-MMM-yy HH:mm:ss"); //Ignore
//@31-JUL-12 14:18:51 SN MP3774501MRS050643E
const string regStartTest = @"^@(?<DateTime>.*) SN (?<SerialNumber>.*)";
fmt = searchFields.AddRegExpField(UUTField.UseSubFields, ReportReadState.InHeader, regStartTest, "", typeof(string), ReportReadState.InTest);
fmt.fieldName = "StartTest";
fmt.AddSubField("DateTime", typeof(DateTime), "dd-MMM-yy HH:mm:ss", UUTField.StartDateTime);
fmt.AddSubField("SerialNumber", typeof(string), null, UUTField.SerialNumber);
string regStartPanel = ConverterParameters["socketNumberRegEx"];
fmt = searchFields.AddRegExpField("StartPanel", ReportReadState.InTest, regStartPanel, "", typeof(string));
//?31-JUL-12 14:18:59
//"25-AUG-12 09:05:10
///25-AUG-12 09:12:01
//&25-AUG-12 14:11:33
//!25-AUG-12 08:56:29
//]25-AUG-12 08:59:07
const string regMainEvent = @"^(?<Event>[?""/&!\]])(?<DateTime>.*)";
fmt = searchFields.AddRegExpField("MainEvent", ReportReadState.InTest, regMainEvent, "", typeof(string), ReportReadState.InHeader);
fmt.AddSubField("Event", typeof(char));
fmt.AddSubField("DateTime", typeof(DateTime), "dd-MMM-yy HH:mm:ss");
//(S SHORTS test, failed
//(O OPENS test, failed
//(B BUSTEST, failure caused by bus
//(C SCRATCHPROBING connection failure
//(F CONTACT fixture failure
const string regFailuresGen = @"^(?<Key>\x28S|\x28O|\x28B|\x28C|\x28F) *(?<Info>.*)";
fmt = searchFields.AddRegExpField("FailuresGen", ReportReadState.InTest, regFailuresGen, "", typeof(string));
fmt.AddSubField("Key", typeof(string));
fmt.AddSubField("Info", typeof(string));
//K500_RLY1_NO=62.532611M(-500M,500M)V
//K500_CLEAR#(,)VS
//V404=6.96336(0,20)RP
// Scientific notation regex taken from: https://stackoverflow.com/questions/638565/parsing-scientific-notation-sensibly
const string regMeasure = @"^(?<CompRef>[^=<>#%]+)(?<Result>[=<>#%])(?<meas>([+\-]?(?:0|[1-9]\d*)(?:\.\d+)?(?:[eE][+\-]?\d+)?)*)(?<measU>(?:MEG*)|(?:[NPUMK]*))\x28*(?<LowLim>([+\-]?(?:0|[1-9]\d*)(?:\.\d+)?(?:[eE][+\-]?\d+)?)*)(?<LowLimU>(?:MEG*)|(?:[NPUMK]*)),*(?<HighLim>([+\-]?(?:0|[1-9]\d*)(?:\.\d+)?(?:[eE][+\-]?\d+)?)*)(?<HighLimU>(?:MEG*)|(?:[NPUMK]*))\x29*(?<Type>\w*) *=*(?<Message>.*)";
fmt = searchFields.AddRegExpField("Measure", ReportReadState.InTest, regMeasure, null, typeof(string));
fmt.AddSubField("CompRef", typeof(string));
fmt.AddSubField("Result", typeof(string));
fmt.AddSubField("meas", typeof(string));
fmt.AddSubField("measU", typeof(string));
fmt.AddSubField("LowLim", typeof(string));
fmt.AddSubField("LowLimU", typeof(string));
fmt.AddSubField("HighLim", typeof(string));
fmt.AddSubField("HighLimU", typeof(string));
fmt.AddSubField("Type", typeof(string));
fmt.AddSubField("Message", typeof(string));
}
}
}