8 static System::Collections::Generic::List<USDigital::A2^> encoders;
9 static System::Collections::Generic::Dictionary<unsigned char, USDigital::A2^> addresses;
10 static unsigned initialized = 0;
11 static long activeCOM = 0;
16 System::String^ comPortString =
"COM" + System::Convert::ToString(comPort);
18 USDigital::SEIBusManager mgr;
19 USDigital::SEIBus^ mSEIBus = mgr.GetBus(comPortString);
20 mSEIBus->ScanSettings->LimitDeviceCount = devicesExpected;
21 mSEIBus->Initialize((USDigital::InitializationFlags)
mode);
23 for (
int i = 0;
i < mSEIBus->Devices->Length;
i++)
25 USDigital::A2^ a2Dev = (USDigital::A2^)mSEIBus->Devices[
i];
26 Globals::encoders.Add(a2Dev);
27 Globals::addresses.Add(a2Dev->Address, a2Dev);
29 Globals::activeCOM = comPort;
34 const unsigned bufferSize = 5000;
35 char lpTargetPath[bufferSize];
36 for (
long i = 0;
i < 255;
i++)
39 DWORD test = QueryDosDevice(str.c_str(), lpTargetPath, bufferSize);
48 catch (System::UnauthorizedAccessException^)
56 #define CatchAndReturn1 \ 57 catch (System::Exception^ exc) \ 59 System::Console::WriteLine("A managed exception occurred in InitializeSEI!\n{0}", exc->ToString()); \ 63 System::Console::WriteLine("An unknown exception occurred in InitializeSEI!"); \ 69 if (Globals::initialized > 0)
71 ++Globals::initialized;
79 for (
int retryCount = 0; retryCount < mRetryLimit; retryCount++)
91 System::Console::WriteLine(
"SEI Retrying...Current number of devices: {0}",
GetNumberOfDevices());
92 Globals::encoders.Clear();
93 Globals::addresses.Clear();
101 Globals::initialized = 1;
109 return Globals::initialized;
114 return Globals::encoders.Count;
117 long GetDeviceInfo(
long devnum,
long& serialnum,
long& addr,
char* model,
char* firmwareVersion)
121 USDigital::A2^ dev = Globals::encoders[devnum];
123 serialnum = dev->SerialNumber;
124 if (model !=
nullptr)
126 char* temp = (
char*)System::Runtime::InteropServices::Marshal::StringToHGlobalAnsi(dev->Model).ToPointer();
128 System::Runtime::InteropServices::Marshal::FreeHGlobal((System::IntPtr)temp);
130 if (firmwareVersion !=
nullptr)
132 char* temp = (
char*)System::Runtime::InteropServices::Marshal::StringToHGlobalAnsi(dev->Model).ToPointer();
133 strcpy(firmwareVersion, temp);
134 System::Runtime::InteropServices::Marshal::FreeHGlobal((System::IntPtr)temp);
143 --Globals::initialized;
144 if (Globals::initialized == 0)
146 Globals::encoders.Clear();
147 Globals::addresses.Clear();
150 System::String^ comPortString =
"COM" + System::Convert::ToString(Globals::activeCOM);
151 USDigital::SEIBusManager mgr;
152 USDigital::SEIBus^ mSEIBus = mgr.GetBus(comPortString);
154 Globals::activeCOM = 0;
162 if (Globals::encoders.Count > 0)
163 if (Globals::encoders[0]->SEIBus->Strobe())
184 if (Globals::addresses.TryGetValue(
address, dev))
186 if (dev->SetOrigin())
198 if (Globals::addresses.TryGetValue(
address, dev))
201 bool success = dev->GetCounterMode(
value);
217 if (Globals::addresses.TryGetValue(
address, dev))
219 if (dev->SetCounterMode(
mode))
231 if (Globals::addresses.TryGetValue(
address, dev))
234 bool success = dev->GetResolution(
value);
250 if (Globals::addresses.TryGetValue(
address, dev))
252 if (dev->SetCounterMode(res))
264 if (Globals::addresses.TryGetValue(
address, dev))
268 USDigital::A2::A2EncoderStatus status;
270 bool success = dev->GetCount(
value, status);
286 if (Globals::addresses.TryGetValue(
address, dev))
288 if (dev->SetCount(pos))
long GetDeviceInfo(long devnum, long &serialnum, long &addr, char *model, char *firmwareVersion)
std::string to_string(ClariusAvailability avail)
void enumerateEncoders(long comPort, long mode, int devicesExpected)
void enumerateEncodersAll(long mode, int devicesExpected)
long InitializeSEI(long comm, long mode, int devicesExpected)
long A2GetMode(long address, long *mode)
long A2SetOrigin(long address)
long A2SetPosition(long address, long pos)
long A2GetPosition(long address, long *pos)
const char const char * value
long A2SetMode(long address, long mode)
long A2SetResolution(long address, long res)
long GetNumberOfDevices()
long A2GetResolution(long address, long *res)