رتبه موضوع:
  • 0 رای - 0 میانگین
  • 1
  • 2
  • 3
  • 4
  • 5
چگونگی برقراری ارتباط بیسیم Wi-Fi or bletooth or RF or another
#1
با سلام

لطفا اگر اطلاعاتی در زمینه برقراری ارتباط بیسیم به وسیله کامپیوتر با سایر دستگاه های خارجی دارید در این قسمت قرار بدید

با سپاس
پاسخ
سپاس شده توسط
#2
با سلام ببینید دوست عزیز مفاهیم ارتباط با پورت ها و ... کلا ارتباط بی سیم در سیستم عامل های مختلف متفاوت است شما ابتدا باید هدف خود را به روشنی معین کنید

من یک مثال میگذارم امیدوارم مشکل حل شود
کد پی‌اچ‌پی:
[align=left]// If you have 1 or more bluetooth dongles attached to the system.

// this will select the first one, then it will perform a scan for

// all devices within range of that dongle and print out all the

// information available about each device. then move on to the next

// dongle and repeat the process, etc. doesn't actually DO much apart

// from find devices and display their information.

 

#include <stdlib.h>

#include <stdio.h>

// Link to ws2_32.lib

#include <Winsock2.h>

#include <Ws2bth.h>

// Link to Bthprops.lib

#include <BluetoothAPIs.h>

 

BLUETOOTH_FIND_RADIO_PARAMS m_bt_find_radio = {sizeof(BLUETOOTH_FIND_RADIO_PARAMS)};

 

BLUETOOTH_RADIO_INFO m_bt_info = {sizeof(BLUETOOTH_RADIO_INFO),0,};

 

BLUETOOTH_DEVICE_SEARCH_PARAMS m_search_params = {

  
sizeof(BLUETOOTH_DEVICE_SEARCH_PARAMS),

  
1,

  
0,

  
1,

  
1,

  
1,

  
15,

  
NULL

};

 

BLUETOOTH_DEVICE_INFO m_device_info = {sizeof(BLUETOOTH_DEVICE_INFO),0,};

 

// Note:

// Radio - is the thing plugged in/attached to the local machine.

// Device - is the thing that is connected to via the Bluetooth connection.

 

int main(int argcchar **args)

{

            
HANDLE m_radio NULL;

            
HBLUETOOTH_RADIO_FIND m_bt NULL;

            
HBLUETOOTH_DEVICE_FIND m_bt_dev NULL;

            
int m_radio_id;

            
int m_device_id;

            
DWORD mbtinfo_ret;

 

            
// Iterate for available bluetooth radio devices in range

            // Starting from the local

            
while(TRUE)

            {

                        
m_bt BluetoothFindFirstRadio(&m_bt_find_radio, &m_radio);

 

                        if(
m_bt != NULL)

                                    
printf("BluetoothFindFirstRadio() is OK!\n");

                        else

                                    
printf("BluetoothFindFirstRadio() failed with error code %d\n"GetLastError());

 

                        
m_radio_id 0;

 

                        do {

                                    
// Then get the radio device info....

                                    
mbtinfo_ret BluetoothGetRadioInfo(m_radio, &m_bt_info);

                                    if(
mbtinfo_ret == ERROR_SUCCESS)

                                                
printf("BluetoothGetRadioInfo() looks fine!\n");

                                    else

                                                
printf("BluetoothGetRadioInfo() failed wit herror code %d\n"mbtinfo_ret);

 

                                    
wprintf(L"Radio %d:\r\n"m_radio_id);

                                    
wprintf(L"\tInstance Name: %s\r\n"m_bt_info.szName);

                                    
wprintf(L"\tAddress: %02X:%02X:%02X:%02X:%02X:%02X\r\n"m_bt_info.address.rgBytes[5],

                                                
m_bt_info.address.rgBytes[4], m_bt_info.address.rgBytes[3], m_bt_info.address.rgBytes[2],

                                                    
m_bt_info.address.rgBytes[1], m_bt_info.address.rgBytes[0]);

                                    
wprintf(L"\tClass: 0x%08x\r\n"m_bt_info.ulClassofDevice);

                                    
wprintf(L"\tManufacturer: 0x%04x\r\n"m_bt_info.manufacturer);

 

                                    
m_search_params.hRadio m_radio;

                                    
ZeroMemory(&m_device_infosizeof(BLUETOOTH_DEVICE_INFO));

                                    
m_device_info.dwSize sizeof(BLUETOOTH_DEVICE_INFO);

 

                                    
// Next for every radio, get the device

                                    
m_bt_dev BluetoothFindFirstDevice(&m_search_params, &m_device_info);

 

                                    if(
m_bt_dev != NULL)

                                                
printf("\nBluetoothFindFirstDevice() is working!\n");

                                    else

                                                
printf("\nBluetoothFindFirstDevice() failed with error code %d\n"GetLastError());

 

                                    
m_radio_id++;

                                    
m_device_id 0;

 

                                    
// Get the device info

                                    
do

                                    {

                                                
wprintf(L"\n\tDevice %d:\r\n"m_device_id);

                                                
wprintf(L"  \tInstance Name: %s\r\n"m_device_info.szName);

                                                
wprintf(L"  \tAddress: %02X:%02X:%02X:%02X:%02X:%02X\r\n"m_device_info.Address.rgBytes[5],

                                                            
m_device_info.Address.rgBytes[4], m_device_info.Address.rgBytes[3], m_device_info.Address.rgBytes[2],

                                                            
m_device_info.Address.rgBytes[1], m_device_info.Address.rgBytes[0]);

                                                
wprintf(L"  \tClass: 0x%08x\r\n"m_device_info.ulClassofDevice);

                                                
wprintf(L"  \tConnected: %s\r\n"m_device_info.fConnected L"true" L"false");

                                                
wprintf(L"  \tAuthenticated: %s\r\n"m_device_info.fAuthenticated L"true" L"false");

                                                
wprintf(L"  \tRemembered: %s\r\n"m_device_info.fRemembered L"true" L"false");

                                                
m_device_id++;

 

                                                
// Well, the found device information can be used for further socket

                                                // operation such as creating a socket, bind, listen, connect, send, receive etc..

                                                 // If no more device, exit the loop

                                                
if(!BluetoothFindNextDevice(m_bt_dev, &m_device_info))

                                                            break;

 

                                    } while(
BluetoothFindNextDevice(m_bt_dev, &m_device_info));

 

                                    
// NO more device, close the device handle

                                    
if(BluetoothFindDeviceClose(m_bt_dev) == TRUE)

                                                
printf("\nBluetoothFindDeviceClose(m_bt_dev) is OK!\n");

                                    else

                                                
printf("\nBluetoothFindDeviceClose(m_bt_dev) failed with error code %d\n"GetLastError());

 

                        } while(
BluetoothFindNextRadio(&m_bt_find_radio, &m_radio));

 

                        
// No more radio, close the radio handle

                        
if(BluetoothFindRadioClose(m_bt) == TRUE)

                                    
printf("BluetoothFindRadioClose(m_bt) is OK!\n");

                        else

                                    
printf("BluetoothFindRadioClose(m_bt) failed with error code %d\n"GetLastError());

 

                        
// Exit the outermost WHILE and BluetoothFindXXXXRadio loops if there is no more radio

                        
if(!BluetoothFindNextRadio(&m_bt_find_radio, &m_radio))

                                    break;

 

                        
// Give some time for the 'signal' which is a typical for crap wireless devices

                        
Sleep(1000);

            }

            return 
0;

}

 [/
align

حالا برای دستگاه دوم بنویسید
کد پی‌اچ‌پی:
[align=left]

#include <BluetoothAPIs.h>

 

int main(int argcchar **argv)

{

            
HANDLE hRadiohDeviceFind;

            
BLUETOOTH_DEVICE_INFO_STRUCT deviceInfo;

            
BLUETOOTH_DEVICE_SEARCH_PARAMS deviceSearchParams;

            
BLUETOOTH_RADIO_INFO radioInfo;

            
GUID guidServices[10];

            
DWORD numServicesresult;

            
int i 1;

 

            
BLUETOOTH_FIND_RADIO_PARAMS btfrp = { sizeof(BLUETOOTH_FIND_RADIO_PARAMS) };

            
HBLUETOOTH_RADIO_FIND hFind BluetoothFindFirstRadio(&btfrp, &hRadio);

 

            if (
hFind != NULL)

            {

                        
printf("BluetoothFindFirstRadio() is working!\n");

                        do

                        {

                                    
// Do something with the radio handle...

                                    
radioInfo.dwSize sizeof(radioInfo);

 

                                    if (
BluetoothGetRadioInfo(hRadio, &radioInfo) == ERROR_SUCCESS)

                                    {

                                                
printf("BluetoothGetRadioInfo() is OK!\n");

                                                
printf(" Radio found: %S\n"radioInfo.szName);

                                    }

                                    else

                                                
printf("BluetoothGetRadioInfo() failed with error code %d\n"GetLastError());

 

                                    
deviceInfo.dwSize sizeof(deviceInfo);

                                    
memset(&deviceSearchParams0sizeof(deviceSearchParams));

                                    
deviceSearchParams.dwSize sizeof(deviceSearchParams);

 

                                    
// deviceSearchParams.fReturnAuthenticated = TRUE;

                                    
deviceSearchParams.fReturnRemembered TRUE;

                                    
//deviceSearchParams.fReturnUnknown = TRUE;

                                    //deviceSearchParams.fReturnConnected = TRUE;

                                    
deviceSearchParams.hRadio hRadio;

 

                                    
hDeviceFind BluetoothFindFirstDevice(&deviceSearchParams, &deviceInfo);

                                    if (
hDeviceFind != NULL)

                                    {

                                                
printf("BluetoothFindFirstDevice() is OK!\n");

                                                do

                                                {

                                                            
printf(" Device found - Name: %S\n"deviceInfo.szName);

                                                            
printf(" Device found - Address: %X\n"deviceInfo.Address);

                                                            
printf(" Device found - Device Class: %ul\n"deviceInfo.ulClassofDevice);

 

                                                            
numServices sizeof(guidServices);

 

                                    
// guidServices should contains a complete list of enabled service GUIDs.

                                    
result BluetoothEnumerateInstalledServices(hRadio, &deviceInfo, &numServicesguidServices);

 

                                    if (
result == ERROR_SUCCESS)

                                    {

                                                
printf("BluetoothEnumerateInstalledServices() should be fine!\n");

                                                
printf(" ...GUID services\n");

                                    }

                                    else

                                                
printf("BluetoothEnumerateInstalledServices() failed with error code %d\n"result);

 

                           }

                           while(
BluetoothFindNextDevice(hDeviceFind, &deviceInfo));

 

                           
BluetoothFindDeviceClose(hDeviceFind);

               }

 

                                    
// Need to re-allocate, else BluetoothGetDeviceInfo() will fail

                                    
memset(&deviceInfo0sizeof(deviceInfo));

                                    
deviceInfo.dwSize sizeof(deviceInfo);

 

                                    if (
BluetoothGetDeviceInfo(hRadio, &deviceInfo))

                                    {

                                                
printf("BluetoothGetDeviceInfo() is OK!\n");

                                                
printf(" ...More operations...\n");

                                                
// BluetoothUpdateDeviceRecord() - change name, BluetoothRemoveDevice() etc.

                                    
}

                                    else

                                                
printf("BluetoothGetDeviceInfo() failed with error code %d\n"GetLastError());

 

                                    
CloseHandle(hRadio);

                        } while( 
BluetoothFindNextRadio(hFind, &hRadio));

                        
BluetoothFindRadioClose(hFind);

            }

            return 
0;

}

 

Build and run the project.

 

Another Bluetooth Program Example Using Win32 PSDKA sample output

 

 
[/align
[عکس: <a href=www.Mojsazan.com.gif]" class="mycode_img" />
پاسخ
سپاس شده توسط worm
#3
بله تفاوت هم به دلیل تفاوت در معماری های مختلف قطعات هستش

منتهی ما معمولا برای ویندوز یا لینوکس برنامه مینویسیم دیگه

اگر منابعی برای کار با هرکدوم از این 2 سیستم عامل دارید قرار بدین ما استفاده میکنیم
پاسخ
سپاس شده توسط
#4
.NET Wireless Programming

[عکس: 51YYP%2BKqn7L._BO2,204,203,200_PIsitb-st..._OU01_.jpg]

لینک کتاب

Wireless Programming
[عکس: 5197N8NDXHL._SL500_AA300_.jpg]
لینک کتاب
[عکس: 51KS%2B9rdGAL._BO2,204,203,200_PIsitb-st..._OU01_.jpg]
لینک کتاب
[عکس: <a href=www.Mojsazan.com.gif]" class="mycode_img" />
پاسخ
سپاس شده توسط worm ، morteza ghaem ، alamdar_313


موضوعات مشابه ...
موضوع نویسنده پاسخ بازدید آخرین ارسال
Smile چطوری ارتباط سریال در ویژوال استودیو داشته باشم hassan_kh 0 3,333 07-11-2015, 09:40 PM
آخرین ارسال: hassan_kh

پرش به انجمن:


کاربران در حال بازدید این موضوع: 1 مهمان