با سلام،
پایه کد قرار داده شده در زیر، کدی مبتنی بر C# است که در اینجا قرار گرفته است. در پروژه ای نیاز بود تا کدی معادل را به زبان Oxygene داشته باشم و با تبدیل کد مربوطه به Oxygene با کمک ابزار Oxidizer و کمی اصلاحات موفق به اینکار شدم. این هم از کد:
namespace GetUsbPorts_Oxygene;
interface
uses
System,
System.Collections.Generic,
System.Linq,
System.Text ,
System.Collections.Generic,
System.Management; // need to add System.Management to your project references.
type
ConsoleApp = class
public
class method Main(args: array of String);
class method GetUSBDevices: List<USBDeviceInfo>;
end;
USBDeviceInfo = assembly class
public
constructor(deviceID: System.String);
property DeviceID: System.String;
end;
implementation
constructor USBDeviceInfo(deviceID: System.String);
begin
self.DeviceID := deviceID
end;
class method ConsoleApp.GetUSBDevices: List<USBDeviceInfo>;
begin
var devices: List<USBDeviceInfo> := new List<USBDeviceInfo>();
var collection: ManagementObjectCollection;
using searcher := new ManagementObjectSearcher('Select * From Win32_USBHub') do
collection := searcher.Get();
for each device in collection do begin
devices.Add(new USBDeviceInfo(System.String(device.GetPropertyValu e('DeviceID'))))
end;
collection.Dispose();
exit devices
end;
class method ConsoleApp.Main(args: array of System.String);
begin
var usbDevices := GetUSBDevices();
for each usbDevice in usbDevices do begin
Console.WriteLine('Device ID: {0}', usbDevice.DeviceID)
end;
Console.Read()
end;
end.
موفق باشید...