#include "pch.h" #include "Device.h" #include "LSWDevices.h" #include LSWDevices::cLSWDevice::cLSWDevice() { } LSWDevices::cLSWDevice::~cLSWDevice() { } LSWDevices::cLSWDevices::cLSWDevices() { DeviceList = gcnew System::Collections::Generic::List(); } LSWDevices::cLSWDevices::~cLSWDevices() { //DeviceList->Clear(); } void LSWDevices::cLSWDevices::AddFilter(System::Collections::Generic::List^ Filter) { for each (String^ var in Filter) { pin_ptr wch = PtrToStringChars(var); cAddFilter( const_cast(wch) ); } } void LSWDevices::cLSWDevices::Scan(int type, System::Collections::Generic::List^ Filter) { int maxFilter = 0; DevicesFound = nullptr; DeviceScanStart(type); if (Filter != nullptr) { maxFilter = Filter->Count; AddFilter(Filter); DevicesFound = gcnew System::Collections::Generic::Dictionary(maxFilter) ; } int i = DeviceIndex; int rv = DeviceScan(); int minrv = 0; if (Filter != nullptr && Filter->Count > 0) minrv = 1; while (rv >=0) { if (rv >= minrv) { cLSWDevice^ d = gcnew cLSWDevice(); d->DeviceInstanceID = gcnew System::String(szDeviceInstanceID); d->Device_FriendlyName = gcnew System::String(Device_FriendlyName); d->BusReportedDeviceDesc = gcnew System::String(BusReportedDeviceDesc); d->Device_Manufacturer = gcnew System::String(Device_Manufacturer); d->DeviceDisplay_Category = gcnew System::String(DeviceDisplay_Category); d->Hardware_ID = gcnew System::String(Hardware_ID); d->PortName = gcnew System::String(PortName); d->Firmware = GetFirmware(); DeviceList->Add(d); if (rv > 0 && rv<= maxFilter && DevicesFound->CountContainsKey(rv-1)) DevicesFound->Add(rv-1, d); } ++DeviceIndex; rv = DeviceScan(); } DeviceScanEnd(); } String^ LSWDevices::cLSWDevices::GetFirmware() { String^ result = nullptr; wchar_t* firmware = nullptr; if (!_tcsncmp(BusReportedDeviceDesc, TEXT("TWN"), 3)) { wchar_t* e = BusReportedDeviceDesc + _tcslen(BusReportedDeviceDesc); wchar_t* x = wcsrchr(BusReportedDeviceDesc, (wchar_t)'/'); if (x != nullptr) { firmware = _tcsdup(x + 1); result= gcnew System::String(firmware); } } return result; } int LSWDevices::cLSWDevices::GetComPortElatec(String^% ElatecPort, String^% ElatecFirmware) { //LSWDevices.LSWDevices a; String^ comport = nullptr; System::Collections::Generic::List^ f = gcnew System::Collections::Generic::List(); f->Add(fElatec); cLSWDevices^ cDev = gcnew cLSWDevices(); cDev->Scan(0, f); if (cDev->DevicesFound->Count == 1) { ElatecPort = cDev->DevicesFound[0]->PortName; ElatecFirmware = cDev->DevicesFound[0]->Firmware; } cDev->~cLSWDevices(); return cDev->DevicesFound->Count; } int LSWDevices::cLSWDevices::GetComPortEdosElatec(String^ %eDosPort, String^ %ElatecPort, String^% ElatecFirmware) { int r = 0; String^ comport = nullptr; System::Collections::Generic::List^ f = gcnew System::Collections::Generic::List(); f->Add(fEdos); f->Add(fElatec); cLSWDevices^ cDev = gcnew cLSWDevices(); cDev->Scan(0, f); r = cDev->DevicesFound->Count; if (cDev->DevicesFound->Count == 2) { eDosPort = cDev->DevicesFound[0]->PortName; ElatecPort = cDev->DevicesFound[1]->PortName; ElatecFirmware = cDev->DevicesFound[1]->Firmware; } else { eDosPort = nullptr; ElatecPort = nullptr; } cDev->~cLSWDevices(); return r; }