-
Notifications
You must be signed in to change notification settings - Fork 12
/
iSeries.cpp
723 lines (637 loc) · 21.2 KB
/
iSeries.cpp
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
//
// iSeries.cpp
//
#pragma message("Compile iSeries.cpp")
#include "StdAfx.h"
//#include "iSeries.h"
#include "MTCFanucAdapter.h"
#include "Globals.h"
// Michaloski
#include "GLogger.h"
//#include "EnumProc.h"
#include "StdStringFcn.h"
#ifdef iSERIESLAN
#if (_MSC_VER >= 1500 && _MSC_VER < 1600)
#pragma comment(lib, "./Distribution/30iHSSB/Fwlib32.lib")
#endif
#endif
#ifdef iSERIESHSSB
#if (_MSC_VER >= 1500 && _MSC_VER < 1600)
#ifdef i160
// no discernible difference to iseries?
#pragma comment(lib, "./Distribution/160iHSSB/Fwlib32.lib")
#else
#pragma comment(lib, "./Distribution/30iHSSB/Fwlib32.lib")
#endif
#endif
#endif
// This is here so the header file include can be cpp file specific
static ODBAXISNAME axisname[MAX_AXIS];
static double ComputeValue(long data, short dec)
{
return ((double) data ) / pow( 10.0, (double) dec);
}
CiSeries::CiSeries(FanucShdrAdapter* adapter): _adapter(adapter)
{
mLag=0;
}
CiSeries::~CiSeries(void)
{
}
int CiSeries::getAlarmInfo()
{
//char *almmsg[] = {
// "P/S 100 ALARM","P/S 000 ALARM",
// "P/S 101 ALARM","P/S ALARM (1-255)",
// "OT ALARM", "OH ALARM",
// "SERVO ALARM", "unknown ALARM",
// "APC ALARM", "SPINDLE ALARM",
// "P/S ALARM (5000-)"
//} ;
char *almmsg[] = {
"P/S alarm",
"Overtravel alarm",
"Servo alarm",
"(Not used)",
"Overheat alarm",
"Stroke limit - 1",
"Stroke limit - 2",
"Edit alarm",
"APC alarm",
"(Not used)",
"P/S 5000 ... alarm",
"(Not used)",
"(Not used)",
"(Not used)",
"External alarm",
"Reverse control alarm"};
short ret=0;
ODBALM buf ;
unsigned short idx ;
ret=cnc_alarm( _adapter->mFlibhndl, &buf ) ;
if (ret != EW_OK)
{
return LogErrorMessage("iSeries::getAlarmInfo() cnc_alarm FAILED\n", ret );
}
if ( buf.data == 0 )
{
_adapter->SetMTCTagValue("fault", "");
}
else
{
std::string sAlarm;
for ( idx = 0 ; idx < 11 ; idx++ )
{
if ( buf.data & 0x0001 )
sAlarm+= almmsg[idx] ;
buf.data >>= 1 ;
}
_adapter->SetMTCTagValue("fault", sAlarm);
}
return 0;
}
int CiSeries::getInfo()
{
short ret=0;
ODBSYS sysinfo;
if( EW_OK != ::cnc_sysinfo(_adapter->mFlibhndl, &sysinfo))
return GLogger.Warning(StdStringFormat("Error: iSeries::connect cnc_sysinfo FAILED %d\n", ret));
_adapter->_nAxes=atoi(sysinfo.axes);
GLogger.Info(StdStringFormat("iSeries::connect axes number %d\n", _adapter->_nAxes ));
if(_adapter->_nAxes >= MAX_AXIS)
{
GLogger.Warning(StdStringFormat("iSeries::connect axes number %d > MAX_AXIS OF HEADER!!!\n", _adapter->_nAxes ));
_adapter->disconnect();
}
if(_adapter->_nAxes< 3)
_adapter->_nAxes=3;
short n=_adapter->_nAxes;
ret = ::cnc_rdaxisname(_adapter->mFlibhndl, &n, axisname);
if (EW_OK != ret)
{
return GLogger.Warning(StdStringFormat("iSeries::connect cnc_rdaxisname FAILED %d\n", ret ));
}
for(int i=3; i< n; i++)
{
_adapter->axisnum[axisname[i].name] = i;
if(::toupper(axisname[i].name) < 'A' || ::toupper(axisname[i].name) > 'Z' )
break;
}
_adapter->_nAxes=n;
// Reads the number of spindles which CNC can control. It is not the number of mounted spindles.
// FWLIBAPI short WINAPI cnc_rdnspdl(unsigned short FlibHndl, short *spdl);
GLogger.LogMessage(StdStringFormat("Axis # %d\n", _adapter->_nAxes) , 3);
for(int i=0; i< n; i++)
{
GLogger.Info(StdStringFormat("\t%d : %c pos = %d\n", i, axisname[i].name, _adapter->axisnum[axisname[i].name]));
}
return EW_OK;
}
int CiSeries::getLine()
{
GLogger.LogMessage("iSeries::getLine Enter\n", 3);
std::string prognum,progname;
short ret;
if (!_adapter->mConnected)
return -1;
GLogger.Info("iSeries::getLine\n");
ODBSEQ block;
ret = cnc_rdseqnum(_adapter->mFlibhndl, &block ); // 15,16,18,21,0,powermate
if (ret == EW_OK)
{
_adapter->SetMTCTagValue("line", StdStringFormat("%d", block.data));
}
else
{
GLogger.Info(StdStringFormat("Error iSeries::cnc_rdseqnum=%d\n", ret));
}
ODBPRO buf ;
ret = cnc_rdprgnum( _adapter->mFlibhndl, &buf ) ; // 15,16,18,21,0,powermate
if (ret == EW_OK)
{
//prognum=StdStringFormat("O%04hd", buf.data); // mdata - Main program number. data- Running program number.
prognum=StdStringFormat("O%04d", buf.data); // mdata - Main program number. data- Running program number.
GLogger.Info(StdStringFormat("iSeries::cnc_rdprgnum prognum = %d\n", buf.mdata));
GLogger.Info(StdStringFormat("iSeries::cnc_rdprgnum prognum = %d\n",(int) (buf.mdata&0xFFFF)));
GLogger.Info(StdStringFormat("iSeries::cnc_rdprgnum prognum data = %d\n",(int) (buf.data&0xFFFF)));
}
else
{
GLogger.Info(StdStringFormat("Error CiSeries::cnc_rdprgnum=%d", ret));
LogErrorMessage(" CiSeries::cnc_rdprgnum FAILED\n", ret );
}
if(1) // Globals.ProgramLogic == "FirstComment")
{
short i, blk;
unsigned short num;
short top = 0;
char prg[BUFSIZE+1];
std::string sLine;
//do {
num = BUFSIZE;
ret = cnc_rdexecprog(_adapter->mFlibhndl,&num, &blk, prg);
if ( ret == EW_LENGTH )
{
LogErrorMessage(" iSeries::cnc_rdexecprog FAILED Length Error\n", ret );
goto error;
}
if ( ret )
{
LogErrorMessage("iSeries::cnc_rdexecprog NOSPECIFIC ERROR\n", ret );
goto error;
}
// Find first comment ( ) SHOULD BE ON FIRST LINE
// Extract comment, if not null assign to progname, which is output as program to MTConnect
{
//sLine = prg[i].comment;
sLine = prg; // [i].comment;
int n = sLine.find("(");
int m= sLine.find(")");
if(std::string::npos ==n && std::string::npos ==m)
{
LOGONCE GLogger.Fatal(StdStringFormat("Didn't find comment %s\n",sLine.c_str()));
goto error;
}
sLine= sLine.substr(n+1,m-n-1);
if(!sLine.empty() && sLine != "()")
{
// GLogger.Fatal(StdStringFormat("Program Name = %s\n",sLine.c_str()));
progname=sLine;
}
}
}
error:
if(!progname.empty())
{
_adapter->SetMTCTagValue("program", progname);
}
else if(!prognum.empty())
{
_adapter->SetMTCTagValue("program", prognum);
}
else
{
_adapter->SetMTCTagValue("program", "O1");
}
GLogger.LogMessage("iSeries::getLine Leave\n", 3);
return EW_OK;
}
int CiSeries::getPositions()
{
if (!_adapter->mConnected)
return -1;
GLogger.LogMessage("iSeries::getPositions Enter\n", HEAVYDEBUG);
//ODBPOS *PosData = static_cast<ODBPOS *>(alloca(_nAxes * sizeof(ODBPOS)));
/* type.
0 : absolute position
1 : machine position
2 : relative position
3 : distance to go
-1 : all type
*/
short data_num = MAX_AXIS;
short type = -1;
ODBPOS PosData[MAX_AXIS]; //Position Data
short ret = cnc_rdposition(_adapter->mFlibhndl, type, &data_num, &PosData[0]); // 15,16,18,21,0,powermate
if (ret == EW_OK)
{
// Fanuc ABC units are in degrees
try {
for(int i=0; i< data_num; i++)
{
GLogger.Info(StdStringFormat( "Axis %c%c%c%c Data=%d Dec=%d\n" , PosData[i].abs.name,(int)PosData[i].abs.data,(int)PosData[i].abs.dec ));
if(::toupper(PosData[i].abs.name) == 'X' && i==0)
_adapter->SetMTCTagValue("Xabs", StdStringFormat("%8.4f", ComputeValue( PosData[i].abs.data , PosData[i].abs.dec)));
if(::toupper(PosData[i].abs.name) == 'Y')
_adapter->SetMTCTagValue("Yabs", StdStringFormat("%8.4f", ComputeValue( PosData[i].abs.data , PosData[i].abs.dec)));
if(::toupper(PosData[i].abs.name) == 'Z')
_adapter->SetMTCTagValue("Zabs", StdStringFormat("%8.4f", ComputeValue( PosData[i].abs.data , PosData[i].abs.dec)));
if(::toupper(PosData[i].abs.name) == 'A')
_adapter->SetMTCTagValue("Aabs", StdStringFormat("%8.4f", ComputeValue( PosData[i].abs.data , PosData[i].abs.dec)));
if(::toupper(PosData[i].abs.name) == 'B')
_adapter->SetMTCTagValue("Babs", StdStringFormat("%8.4f", ComputeValue( PosData[i].abs.data , PosData[i].abs.dec)));
if(::toupper(PosData[i].abs.name) == 'C')
_adapter->SetMTCTagValue("Cabs", StdStringFormat("%8.4f", ComputeValue( PosData[i].abs.data , PosData[i].abs.dec)));
if(::toupper(PosData[i].abs.name) == 'U')
_adapter->SetMTCTagValue("Uabs", StdStringFormat("%8.4f", ComputeValue( PosData[i].abs.data , PosData[i].abs.dec)));
if(::toupper(PosData[i].abs.name) == 'V')
_adapter->SetMTCTagValue("Vabs", StdStringFormat("%8.4f", ComputeValue( PosData[i].abs.data , PosData[i].abs.dec)));
}
}
catch(...)
{
GLogger.LogMessage("CiSeries::getPositions Exception\n", 3);
}
//GLogger.LogMessage(StdStringFormat("CiSeries::getPositions %.3f %.3f %.3f\n",
// _adapter->mXact.getValue(), _adapter->mYact.getValue(), _adapter->mZact.getValue()) , GLogger.HEAVYDEBUG);
}
else
{
_adapter->disconnect();
return -1;
}
GLogger.LogMessage("iSeries::getPositions Done\n", HEAVYDEBUG);
return EW_OK;
}
int CiSeries::getToolInfo()
{
IODBTLCTL toolinfo;
short ret;
#ifdef TOOLING
if(Globals.nToolingFlag)
{
ret = cnc_rdtlctldata(_adapter->mFlibhndl, &toolinfo);
if(ret)
{
LOGONCE GLogger.Fatal(StdStringFormat("CiSeries::cnc_rdsvmeter Failed\n"));
return EW_OK;
}
if(toolinfo.slct&1)
_adapter->SetMTCTagValue("toolid", StdStringFormat("%d", toolinfo.used_tool));
else
_adapter->SetMTCTagValue("toolid", "");
}
#endif
return EW_OK;
}
int CiSeries::getLoads()
{
#ifdef LOADS
short ret;
if(Globals.nAxesLoadFlag)
{
ODBSVLOAD sv[MAX_AXIS];
short num = _adapter->_nAxes;
GLogger.LogMessage("iSeries::get Loads Enter\n", HEAVYDEBUG);
try {
ret = cnc_rdsvmeter(_adapter->mFlibhndl, &num, sv); // 15,16,18,21,0,powermate
if(ret)
{
LOGONCE GLogger.Fatal(StdStringFormat("CiSeries::cnc_rdsvmeter Failed\n"));
return EW_OK;
}
if(num>0)
_adapter->SetMTCTagValue("Xload",StdStringFormat("%8.4f", ComputeValue(sv[0].svload.data, sv[0].svload.dec)));
if(num>1)
_adapter->SetMTCTagValue("Yload",StdStringFormat("%8.4f", ComputeValue(sv[1].svload.data, sv[1].svload.dec)));
if(num>2)
_adapter->SetMTCTagValue("Zload",StdStringFormat("%8.4f", ComputeValue(sv[2].svload.data, sv[2].svload.dec)));
for(int i=3; i< _adapter->_nAxes; i++)
{
if(::toupper(sv[i].svload.name) == 'A')
_adapter->SetMTCTagValue("Aload",StdStringFormat("%8.4f", ComputeValue(sv[i].svload.data, sv[i].svload.dec)));
if(::toupper(sv[i].svload.name) == 'B')
_adapter->SetMTCTagValue("Bload",StdStringFormat("%8.4f", ComputeValue(sv[i].svload.data, sv[i].svload.dec)));
if(::toupper(sv[i].svload.name) == 'C')
_adapter->SetMTCTagValue("Cload",StdStringFormat("%8.4f", ComputeValue(sv[i].svload.data, sv[i].svload.dec)));
}
}
}
catch(...)
{
}
#endif
GLogger.Info("CiSeries::get Loads leave\n");
return EW_OK;
}
int CiSeries::getStatus()
{
GLogger.LogMessage("iSeries::getStatus Enter\n", 3);
if (!_adapter->mConnected)
return -1;
short ret;
IODBSGNL sgnl;
/// Difference 15i versus 16/18/.. i series
if (EW_OK == (ret=cnc_rdopnlsgnl(_adapter->mFlibhndl, 0xFFFF, &sgnl)))
{
std::string sFovr = StdStringFormat("%d", (int) sgnl.feed_ovrd );
// Broken?
//_adapter->SetMTCTagValue("path_feedrateovr", sFovr);
_adapter->SetMTCTagValue("path_feedrateovr", "100");
_adapter->SetMTCTagValue("Sovr", "100");
}
else
{
_adapter->SetMTCTagValue("Sovr", "100");
_adapter->SetMTCTagValue("path_feedrateovr", "100");
GLogger.Warning(StdStringFormat("Error: iSeries::cnc_rdopnlsgnl=%d\n", ret));
LogErrorMessage("Error: iSeries::cnc_rdopnlsgnl", ret);
}
//this one may fail
// bit 6 : Spindle override signal (only Series 15)
//if(EW_OK == cnc_rdopnlsgnl(_adapter->mFlibhndl, 0x40, &sgnl))
// _adapter->SetMTCTagValue("Sovr", StdStringFormat("%8.4f", sgnl.spdl_ovrd * 10.0));
ODBST status;
ret = cnc_statinfo(_adapter->mFlibhndl, &status);
if (ret == EW_OK)
{
GLogger.Info(StdStringFormat("Controller mode iSeries::cnc_statinfo=%d\n", status.aut));
// Series 16/18/21/0/Power Mate
if (status.aut == 0) // MDI for aut
_adapter->SetMTCTagValue("controllermode", "MANUAL");
else if (status.aut != 2) // Other than no selection or MDI
_adapter->SetMTCTagValue("controllermode", "AUTOMATIC");
else
_adapter->SetMTCTagValue("controllermode", "MANUAL");
/** run
Status of automatic operation 0 : ****(reset)
1 : STOP
2 : HOLD
3 : STaRT
4 : MSTR(during retraction and re-positioning of tool retraction and recovery, and operation of JOG MDI)
*/
GLogger.Info(StdStringFormat("Execution mode iSeries::cnc_statinfo=%d\n", status.run));
if(status.run == 0 )
_adapter->SetMTCTagValue("execution", "IDLE");
else if (status.run == 1 || status.run == 2) // STOP or HOLD is ePAUSED
_adapter->SetMTCTagValue("execution", "PAUSED");
else if (status.run >2) // STaRT
_adapter->SetMTCTagValue("execution", "EXECUTING");
//else if (status.run ==4)
// _adapter->SetMTCTagValue("execution", "PAUSED");
//else
// _adapter->SetMTCTagValue("execution", "PAUSED");
}
else
{
_adapter->disconnect();
}
GLogger.LogMessage("iSeries::getStatus Leave\n", 3);
return EW_OK;
}
void CiSeries::saveStateInfo()
{
lastFeed=_adapter->GetMTCTagValue("path_feedratefrt");
lastX=_adapter->GetMTCTagValue("Xabs");
lastY=_adapter->GetMTCTagValue("Yabs");
lastZ=_adapter->GetMTCTagValue("Zabs");
lastA=_adapter->GetMTCTagValue("Aabs");
lastB=_adapter->GetMTCTagValue("Babs");
}
int CiSeries::getSpeeds()
{
GLogger.LogMessage("iSeries::getSpeeds enter\n", 3);
if (!_adapter->mConnected)
return -1;
double spindlespeed=0, feedrate=0;
ODBSPEED speed;
/* Data type. 0 ( feed rate ), 1 ( spindle speed ) , -1 ( all ) */
short ret = cnc_rdspeed(_adapter->mFlibhndl, -1, &speed);
if (ret == EW_OK)
{
spindlespeed=speed.acts.data;
if(speed.acts.dec>0)
spindlespeed=spindlespeed / pow( 10.0, (double) speed.acts.dec);
feedrate=speed.actf.data;
if(speed.actf.dec>0)
feedrate=feedrate / pow( 10.0, (double) speed.actf.dec);
}
else // Error
{
GLogger.Warning(StdStringFormat("Error: iSeries::getSpeeds=%d\n", ret));
LogErrorMessage("Error: iSeries::cnc_rdspeed", ret);
}
if(spindlespeed==0)
{
std::string feed,X, Y, Z, A, B,mode,execution;
mode=_adapter->GetMTCTagValue("controllermode");
execution=_adapter->GetMTCTagValue("execution");
feed=_adapter->GetMTCTagValue("path_feedratefrt");
X=_adapter->GetMTCTagValue("Xabs");
Y=_adapter->GetMTCTagValue("Yabs");
Z=_adapter->GetMTCTagValue("Zabs");
A=_adapter->GetMTCTagValue("Aabs");
B=_adapter->GetMTCTagValue("Babs");
// If moving and in auto mode, assume spindle on
if( (mode == "AUTOMATIC" ) &&
(execution == "EXECUTING" )&&
(
lastFeed!=feed ||
lastX!=X ||
lastY!= Y ||
lastZ!=Z
//|| lastA!=A
//||lastB!=B
)
)
mLag=4; // 3 cycles - 3 seconds;
else
mLag--;
if(mLag<0) mLag=0;
if(mLag>0)
{
spindlespeed = 99.0; // _adapter->SetMTCTagValue("Srpm","99.0");
}
else
{
spindlespeed = 0; // _adapter->SetMTCTagValue("Srpm","0");
}
}
_adapter->SetMTCTagValue("path_feedratefrt", StdStringFormat("%8.4f", feedrate));
_adapter->SetMTCTagValue("Srpm", StdStringFormat("%8.4f", spindlespeed));
GLogger.LogMessage("iSeries::getSpeeds done\n", 3);
GLogger.LogMessage("iSeries::getSpindleLoad\n", 5);
#if 1
short nspd;
ret = cnc_rdnspdl(_adapter->mFlibhndl, &nspd);
if (ret != EW_OK)
{
LOGONCE GLogger.Fatal("iSeries::cnc_rdnspdl Failed\n");
return -1;
}
ODBSPN *load = static_cast<ODBSPN *>(alloca(nspd * sizeof(ODBSPN)));
//ODBSPLOAD load[MAX_SPINDLES]; /* 4 = maximum spinlde number */
ret = cnc_rdspload (_adapter->mFlibhndl, -1, load);
if (ret != EW_OK)
{
LOGONCE GLogger.Fatal(StdStringFormat("iSeries::cnc_rdspload Failed\n"));
return ret;
}
_adapter->SetMTCTagValue("Sload", StdStringFormat("%8.4f", load[0].data[0]));
#endif
GLogger.LogMessage("iSeries::getLoads Leave\n", 3);
return EW_OK;
}
int CiSeries::getVersion()
{
/** cnc_type
Kind of CNC (ASCII)
'15' : Series 15
'16' : Series 16
'18' : Series 18
'21' : Series 21
' 0' : Series 0
'PD' : Power Mate i-D
'PH' : Power Mate i-H
*/
if (!_adapter->mConnected)
return -1;
GLogger.LogMessage("FanucMTConnectAdapter::getVersion Enter\n", INFO);
ODBSYS sysinfo;
short ret = cnc_sysinfo(_adapter->mFlibhndl, &sysinfo); // 15,16,18,21,0,powermate
if (ret == EW_OK)
{
std::string versioninfo =StdStringFormat("CNC=%c%c Series=%c%c%c%c Version=%c%c%c%c ", sysinfo.cnc_type[0], sysinfo.cnc_type[1],
sysinfo.series[0],sysinfo.series[1],sysinfo.series[2],sysinfo.series[3],
sysinfo.version[0],sysinfo.version[1],sysinfo.version[2],sysinfo.version[3]
);
GLogger.Warning(versioninfo);
}
else
{
GLogger.Fatal(StdStringFormat("Error: FanucMTConnectAdapter::cnc_sysinfo=%d\n", ret));
}
return EW_OK;
}
void CiSeries::disconnect()
{
LOGONCE GLogger.Status(StdStringFormat("iSeries::disconnect Using Protocol=%s\n", Globals.FanucProtocol.c_str()));
_adapter->SetMTCTagValue("Sload","OFF");
if (_adapter->mConnected)
{
//_adapter->mPower.setValue(PowerState::eOFF);
if(_adapter->mFlibhndl)
cnc_freelibhndl(_adapter->mFlibhndl);
_adapter->mConnected = false;
_adapter->mFlibhndl=NULL;
}
}
int CiSeries::connect()
{
LOGONCE GLogger.Status(StdStringFormat("iSeries::connect Using Protocol=%s\n", Globals.FanucProtocol.c_str()));
short ret;
_adapter->mFlibhndl=0;
if(Globals.FanucProtocol == "HSSB")
{
GLogger.Fatal(StdStringFormat("iSeries::connect HSSB cnc_allclibhndl2 Port=%d\n", _adapter->mDevicePort ));
//GLogger << FATAL << "THIS EXECUTABLE DOES NOT HANDLE HSSB - EXCLUSIVELY Focas w/ Processing library for TCP/IP\n";
#ifdef iSERIESHSSB
ret = ::cnc_allclibhndl2(_adapter->mDevicePort,&_adapter->mFlibhndl);
#else
GLogger.Fatal( "THIS EXECUTABLE DOES NOT HANDLE LAN - EXCLUSIVELY Focas w/ Processing library for HSSB\n" );
return -1;
#endif
}
else
{
GLogger.Fatal(StdStringFormat("iSeries::connect LAN cnc_allclibhndl3 IP=%s Port=%d\n",Globals.FanucIpAddress.c_str(), _adapter->mDevicePort ));
#ifdef iSERIESLAN
try{
ret = ::cnc_allclibhndl3(Globals.FanucIpAddress.c_str(), _adapter->mDevicePort, 10, &_adapter->mFlibhndl);
}
catch(...)
{
GLogger.Fatal(StdStringFormat("iSeries::connect LAN cnc_allclibhndl3 Exception\n"));
}
#else
GLogger.Fatal( "THIS EXECUTABLE DOES NOT HANDLE LAN - EXCLUSIVELY Focas w/ Processing library for HSSB\n");
return -1;
#endif
}
GLogger.Fatal (StdStringFormat("iSeries::connect cnc_allclibhndl Result:%x\n " , ret ));
if (ret != EW_OK)
{
LogErrorMessage("iSeries::connect cnc_allclibhndl3 failed ",ret);
_adapter->SetMTCTagValue("avail","UNAVAILABLE");
_adapter->SetMTCTagValue("power","OFF");
_adapter->mConnected = false;
LOGONCE GLogger.Fatal(StdStringFormat("iSeries::connect FAILED Power = OFF\n", ret ));
return -1;
}
GLogger.LogMessage(StdStringFormat("iSeries::connect connected ON\n", ret ), HEAVYDEBUG);
_adapter->mConnected = true;
_adapter->SetMTCTagValue("power","ON");
_adapter->SetMTCTagValue("avail","AVAILABLE");
return 0;
}
int CiSeries::LogErrorMessage(std::string msg, short errcode)
{
if(errcode == EW_OK)
return 0;
std::stringstream str;
str<< msg + " Error on machine "<< Globals.FanucIpAddress << " : ";
switch(errcode)
{
case EW_PROTOCOL: str<< "EW_PROTOCOL - protocol error";break;
case EW_SOCKET: str<< "EW_SOCKET - Windows socket error ";break;
case EW_HANDLE: str<< "EW_HANDLE - DLL not exist error";break;
case EW_VERSION: str<< "EW_VERSION - CNC/PMC version missmatch";break;
case EW_UNEXP: str<< "EW_UNEXP - abnormal error"; break;
case EW_NODLL: str<< "EW_NODLL"; break;
case EW_BUS: str<< "EW_BUS - bus error"; break;
case EW_SYSTEM2: str<< "EW_SYSTEM2 - system error"; break;
case EW_HSSB: str<< "EW_HSSB - hssb communication error"; break;
case EW_SYSTEM: str<< "EW_SYSTEM"; break;
case EW_MMCSYS: str<< "EW_MMCSYS - emm386 or mmcsys install error"; break;
case EW_RESET: str<< "EW_RESET - reset or stop occured error"; break;
case EW_BUSY: str<< "EW_BUSY - busy error"; break;
case EW_PARITY: str<< " EW_PARITY - shared RAM parity error "; break;
case EW_FUNC: str<< "EW_FUNC - command prepare error"; ; // 1
/*case EW_NOPMC:*/ str<< " or EW_NOPMC - pmc not exist"; break; // 1
case EW_LENGTH: str<< "EW_LENGTH - data block length error"; break; // 2
case EW_NUMBER: str<< "EW_NUMBER - data number error"; // 3
/*case EW_RANGE:*/ str<< " or EW_RANGE -address range error"; break; // 3
case EW_ATTRIB: str<< "EW_ATTRIB - data attribute error"; //4
/*case EW_TYPE:*/ str<< " or EW_TYPE -data type error"; break; //4
case EW_DATA: str<< "EW_DATA - data error"; break; // 5
case EW_NOOPT: str<< "EW_NOOPT - No option The extended driver/library function is necessary."; break; //6
case EW_PROT: str<< "EW_PROT - write protect error"; break; //7
case EW_OVRFLOW: str<< "EW_OVRFLOW - memory overflow error"; break; //8
case EW_PARAM: str<< "EW_PARAM - cnc parameter not correct error"; break; //9
case EW_BUFFER: str<< "EW_BUFFER - buffer error"; break; //10
case EW_PATH: str<< "EW_PATH - path error"; break; //11
case EW_MODE: str<< "EW_MODE - cnc mode error"; break; //12
case EW_REJECT: str<< "EW_REJECT - execution rejected error"; break; //13
case EW_DTSRVR: str<< "EW_DTSRVR - data server error"; break; //14
case EW_ALARM: str<< "EW_ALARM - alarm has been occurred"; break; //15
case EW_STOP: str<< "EW_STOP -CNC is not running"; break; // 16
case EW_PASSWD: str<< "EW_PASSWD - protection data error "; break; // 17
default: str<< "Fanuc Error not identifed"; break;
}
str<< std::endl;
//GLogger.LogMessage(str.str().c_str(), INFO);
LOGONCE GLogger.Fatal(str.str().c_str());
//_adapter->SetMTCTagValue("status", str.str() );
_adapter->errmsg= str.str() ;
return -1;
}