-
Notifications
You must be signed in to change notification settings - Fork 12
/
MTCFanucAdapter.h
247 lines (222 loc) · 5.2 KB
/
MTCFanucAdapter.h
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
//
// MTCFanucAgenth : Defines the entry point for the console application.
//
// This software was developed by U.S. Government employees as part of
// their official duties and is not subject to copyright. No warranty implied
// or intended.
#pragma once
#include <vector>
#include <string>
#include <boost\thread.hpp>
#include "atlutil.h"
#include "Config.h"
#include "GLogger.h"
#include <windows.h>
#include <atlbase.h>
#include "atlutil.h"
#include "StdStringFcn.h"
#include "Config.h"
#include "StdStringFcn.h"
//#include "AppEventLog.h"
#include "Globals.h"
#include "adapter.hpp"
#include "device_datum.hpp"
#include "service.hpp"
#include "condition.hpp"
class CiSeries;
class CFS15D;
class CF15B;
class FanucShdrAdapter : public Adapter, public MTConnectService
{
public:
PowerState mPower;
Availability mAvail;
std::string errmsg;
struct Item
{
std::string _alias;
std::string _tagname;
std::string _type;
std::string _subtype;
std::string _value;
std::string _lastvalue;
VARENUM vt;
Event _event;
Item(std::string name="", std::string devicename="") : _event(name.c_str(),devicename.c_str() ){}
};
struct ItemsType : public std::vector<Item * >
{
Item * FindAlias(std::string name)
{
for(int i =0; i< this->size(); i++)
{
if(at(i)->_alias == name)
return at(i);
}
return NULL;
}
Item * FindTag(std::string name)
{
for(int i =0; i< this->size(); i++)
{
Item * item = at(i);
if(at(i)->_tagname == name)
return item;
}
return NULL;
}
std::string GetSymbolValue(std::string szEnumTag, std::string defaultVal)
{
for(int i =0; i< this->size(); i++)
{
if(at(i)->_type != "Enum")
continue;
if(at(i)->_alias == szEnumTag)
return at(i)->_value;
}
return defaultVal;
}
} items;
void WarningMsg( std::string err)
{
AtlTrace(err.c_str());
if(mDebug>3)
{
GLogger.Warning(err);
//EventLogger.LogEvent(err);
}
}
void ErrMsg( std::string err)
{
AtlTrace(err.c_str());
if(mDebug>0)
{
GLogger.Fatal(err);
//EventLogger.LogEvent(err);
}
}
void AbortMsg( std::string err)
{
AtlTrace(err.c_str());
errmsg+=err;
//EventLogger.LogEvent(err);
GLogger.Fatal(err);
// std::string cmd = StdStringFormat("cmd /c net stop \"%s\" ", adapter->name().c_str());
// taskmgr.Launch(cmd, 000);
}
void AddItem(std::string tag, std::string value)
{
Item * item;
item = new Item(tag, Globals.szDeviceName);
//if(!Globals.szDeviceName.empty())
//{
// strncpy(item->_event.mDeviceName,Globals.szDeviceName.c_str(),NAME_LEN);
// item->_event.prefixName(item->_event.mDeviceName);
//}
item->_tagname=tag;
item->_type="Event";
item->_lastvalue=item->_value=value;
item->_event.setValue(value.c_str());
item->_event.mHasValue=true;
addDatum(item->_event);
// strncpy(item->_event.mName,tag.c_str(),NAME_LEN);
items.push_back(item);
}
void SetMTCTagValue( std::string tag, std::string value)
{
if(tag=="avail") return;
if(tag=="avail")
{
if(value=="UNAVAILABLE")
mAvail.unavailable();
else
mAvail.available();
return;
}
else if(tag=="power")
{
if(value=="ON")
mPower.setValue(PowerState::eON);
else
mPower.setValue(PowerState::eOFF);
return;
}
Item* item = items.FindTag(tag);
if(item==NULL)
{
//EventLogger.LogEvent(StdStringFormat("SetMTCTagValue tag %s not found\n", tag.c_str()));
GLogger.Warning(StdStringFormat("SetMTCTagValue tag %s not found\n", tag.c_str()));
return;
}
item->_lastvalue=item->_value;
item->_value=value;
}
std::string GetMTCTagValue(std::string tag)
{
if(tag=="avail")
{
if(mConnected)
return "AVAILABLE";
return "UNAVAILABLE";
}
else if(tag=="power")
{
if(mPower.getValue() == PowerState::eON)
return "ON";
return "OFF";
}
Item * item=items.FindTag(tag);
if(item!=NULL)
{
GLogger.Warning(StdStringFormat("SetMTCTagValue tag %s not found\n", tag.c_str()));
//EventLogger.LogEvent(StdStringFormat("SetMTCTagValue tag %s not found\n", tag.c_str()));
return item->_value;
}
return "";
}
//EventLogging eventlog;
int mPort;
int mSleep;
static int mDebug;
unsigned short mFlibhndl;
int _nAxes;
std::map<char,int> axisnum;
//std::string mDeviceIP;
std::string sHeartbeat;
int heartbeat;
int mDevicePort;
bool mConnected;
//////////////////////////////////////////////////////////////////
FanucShdrAdapter(int aPort, int aSleep=1000);
virtual HRESULT Configure();
virtual void Clear();
virtual void CreateItems();
std::string getProgramName(char * buf) ;
virtual void initialize(int aArgc, const char *aArgv[]);
virtual void start();
virtual void stop();
virtual void gatherDeviceData();
virtual void disconnect();
virtual void update();
#ifdef F15i
CFS15D * _FS15D;
friend CFS15D;
#endif
#ifdef F15M
CF15B * _F15M;
friend CF15B;
#endif
#ifdef iSERIES
CiSeries * _iSeries;
friend CiSeries;
#endif
////////////////////////////////////////////////////////////////////
bool ResetAtMidnite();
CWorkerThread<> _resetthread;
struct CResetThread : public IWorkerThreadClient
{
HRESULT Execute(DWORD_PTR dwParam, HANDLE hObject);
HRESULT CloseHandle(HANDLE){ ::CloseHandle(_hTimer); return S_OK; }
HANDLE _hTimer;
} _ResetThread;
};