ilreza2050
سه شنبه 22 فروردین 1391, 20:32 عصر
باسلام
کسی از مهندسا میدونه کد شناخت پورت Com1یاcom2و... تو نرم افزار دلفیXE2 چیه؟ (اگه کسی میدونه بگه چیکارکنم که مثلا وقتی یه buttonرو میزنم بتونه موبایلی که وصل شده به کامپیوتر رو بشناسه)
درضمن از کامپوننت هم نمیخوام استفاده کنم، مثلا کامپوننت Kylix.... :لبخند: از اینا نمیخوام استفاده کنم
ممنون
Vahid.Shatery
سه شنبه 22 فروردین 1391, 22:21 عصر
با سلام
باید با استفاده از دستورات AT Command این کار را انجام بدین .
دانلود دستورات ATCommand را می تونید از این سایت بگیرین.
http://blueonee.com/articles/groups/groupid/14/lang/fa
ilreza2050
جمعه 25 فروردین 1391, 10:46 صبح
لینک دانلودش خرابه :گریه:
جایه دیگه بلد نیستی برم دان کنم؟ ///// ممنون
Felony
جمعه 25 فروردین 1391, 12:50 عصر
با کد زیر میتونید لیست دستگاه های متصل به پورت Com و LPT رو به دست بیارید ، باقی  کار هم که چندان پیچیده نیست :
Var
  istr: string;
  isize, j: dword;
begin
   setlength(istr, 4000) ;
   isize := QueryDosDevice(nil, @istr[1], 4000) ;
   for j := 1 to isize do
     if istr[j] = #0 then istr[j] := #10;
   memo1.lines.CommaText := istr;
end;
ilreza2050
جمعه 25 فروردین 1391, 23:35 عصر
ممنون
این کد رو امتحان کردم ونوشتمش تو یه buttonو وقتی که دکمه رو فشارمیدم فقط تو memoیی  که آوردم  مینویسه global //// همین مهندس! :افسرده:
اگه بیشتر راهنمایی کنی ممنون میشم ازت
BORHAN TEC
شنبه 26 فروردین 1391, 09:45 صبح
برای بدست آوردن لیست پورتهای com از کد زیر استفاده کن. این کد حتی Friendly Name مربوط به پورتهای Com را نیز می گوید:
function TSmart.SetupEnumAvailableComPorts: TStringList;
var
  RequiredSize: Cardinal;
  GUIDSize: DWORD;
  Guid: TGUID;
  DevInfoHandle: HDEVINFO;
  DeviceInfoData: TSPDevInfoData;
  MemberIndex: Cardinal;
  PropertyRegDataType: DWORD;
  RegProperty: Cardinal;
  RegTyp: Cardinal;
  Key: Hkey;
  Info: TRegKeyInfo;
  S1, S2: string;
  hc: THandle;
begin
  Result := Nil;
  // If we cannot access the setupapi.dll then we return a nil pointer.
  if not LoadsetupAPI then
    Exit;
  try
    // get 'Ports' class guid from name
    GUIDSize := 1; // missing from original code - need to tell function that the Guid structure contains a single GUID
    if SetupDiClassGuidsFromName('Ports', @Guid, GUIDSize, RequiredSize) then
      begin
        // get object handle of 'Ports' class to interate all devices
        DevInfoHandle := SetupDiGetClassDevs(@Guid, Nil, 0, DIGCF_PRESENT);
        if Cardinal(DevInfoHandle) <> Invalid_Handle_Value then
          begin
            try
              MemberIndex := 0;
              Result := TStringList.Create;
              // iterate device list
              repeat
                FillChar(DeviceInfoData, SizeOf(DeviceInfoData), 0);
                DeviceInfoData.cbSize := SizeOf(DeviceInfoData);
                // get device info that corresponds to the next memberindex
                if Not SetupDiEnumDeviceInfo(DevInfoHandle, MemberIndex,
                  DeviceInfoData) then
                  break;
                // query friendly device name LIKE 'BlueTooth Communication Port (COM8)' etc
                RegProperty := SPDRP_FriendlyName;
                { SPDRP_Driver, SPDRP_SERVICE, SPDRP_ENUMERATOR_NAME,SPDRP_PHYSICAL_DEVICE_OBJECT _NAME,SPDRP_FRIENDLYNAME, }
                SetupDiGetDeviceRegistryProperty(DevInfoHandle, DeviceInfoData,
                  RegProperty, PropertyRegDataType, NIL, 0, RequiredSize);
                SetLength(S1, RequiredSize);
                if SetupDiGetDeviceRegistryProperty
                  (DevInfoHandle, DeviceInfoData, RegProperty,
                  PropertyRegDataType, @S1[1], RequiredSize, RequiredSize) then
                  begin
                    Key := SetupDiOpenDevRegKey(DevInfoHandle, DeviceInfoData,
                      DICS_FLAG_GLOBAL, 0, DIREG_DEV, KEY_READ);
                    if Key <> Invalid_Handle_Value then
                      begin
                        FillChar(Info, SizeOf(Info), 0);
                        // query the real port name from the registry value 'PortName'
                        if RegQueryInfoKey
                          (Key, nil, nil, nil, @Info.NumSubKeys,
                          @Info.MaxSubKeyLen, nil, @Info.NumValues,
                          @Info.MaxValueLen, @Info.MaxDataLen, nil,
                          @Info.FileTime) = ERROR_SUCCESS then
                          begin
                            RequiredSize := Info.MaxValueLen + 1;
                            SetLength(S2, RequiredSize);
                            if RegQueryValueEx
                              (Key, 'PortName', Nil, @RegTyp, @S2[1],
                              @RequiredSize) = ERROR_SUCCESS then
                              begin
                                If (pos('COM', S2) = 1) then
                                  begin
                                    // Test if the device can be used
                                    hc := CreateFile
                                      (pchar('\\.\' + S2 + #0),
                                      GENERIC_READ or GENERIC_WRITE, 0, nil,
                                      OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, 0);
                                    if hc <> Invalid_Handle_Value then
                                      begin
                                        Result.Add
                                        (Strpas(pchar(S2)) + ': = ' + Strpas
                                        (pchar(S1)));
                                        CloseHandle(hc);
                                      end;
                                  end;
                              end;
                          end;
                        RegCloseKey(Key);
                      end;
                  end;
                Inc(MemberIndex);
              until False;
              // If we did not found any free com. port we return a NIL pointer.
              if Result.Count = 0 then
                begin
                  Result.Free;
                  Result := NIL;
                end
                finally
                  SetupDiDestroyDeviceInfoList(DevInfoHandle);
                end;
            end;
          end;
        finally
          UnloadSetupApi;
        end;
      end;
ilreza2050
شنبه 26 فروردین 1391, 23:57 عصر
آقاممنون
میشه 1توضیح بدی ک باید کجااین کدرو بنویسم (functionش رو می2نم ک کجابنویسم، بقیشو چیکارکنم؟ کجابنویسمشون)
اگه ممکنه توضیح بیشتری بده وراهنمایی بیشتری کن:افسرده:
بازم ممنون
vBulletin® v4.2.5, Copyright ©2000-1404, Jelsoft Enterprises Ltd.