當前位置:首頁 » 編程軟體 » 安卓藍牙編程

安卓藍牙編程

發布時間: 2024-10-20 22:23:32

① android藍牙編程-如何實現自動連接上次連接過的藍牙從機模塊

每次只連接一個,傳完數據後,連接下一個.要多連接的話,直接創建無線網路來連接.藍牙能連接7個是因為只能保存藍牙只能保存匹配數是7個

② 編程軟體哪個好


對於"編程軟體哪個好"這個問題感興趣的朋友應該很多,這個也是目前大家比較關注的問題,那麼下面小好小編就收集了一些"編程軟體哪個好"相關軟體,來分享給大家希望能夠幫助到你哦。
1. Firebird(編程軟體) 軟體類型:電腦軟體
軟體介紹:
Firebird很容易讓您從單用戶,單資料庫升級到企業級的應用。一個firebird資料庫伺服器能夠管理多個獨立的資料庫,每一個資料庫同時可支持多個客戶端連結。
2. microbit編程軟體 軟體類型:安卓APP
軟體介紹:
microbit手機上編程app是特別實用的少兒編程手機軟體,特別適合新手來應用,可以利用手機藍牙手機傳輸程序流程,適用可視化編程並讓智能機器人實行這種命令,鍾愛的朋友們趕緊在線下載暢玩吧!
3. sCode(編程軟體) 軟體類型:安卓APP
軟體介紹:
sCode手機安卓版是一款變為學習程序編寫的客戶構建的學習助手,里邊為我們梳理了一系列程序編寫常見的編碼,便捷使用者應用的並且可以使你輕輕鬆鬆把握大量的程序編寫常見專業知識,一邊學習,一邊應用,必須的
4. 積木編程軟體 軟體類型:安卓APP
軟體介紹:
積木編程手機軟體是可以線上可以學習培訓編程的手機軟體,服務平台給客戶帶來了很多的編程學習培訓實例教程,手機軟體還適用線上編程,學習培訓形式多樣,讓客戶了解的時候不容易枯燥無味,即使你是零基礎的新手,還
5. 兒童編程軟體 軟體類型:電腦軟體
點擊下載
軟體介紹:
Scratch 是一個胡困禪專業對於小孩開發設計的數控編程軟體,根據栩栩如生一目褲塵瞭然的樂高積木方式,能夠增強小朋友們的程序編寫快樂尺睜,早日變成程序編寫大神。

③ android 藍牙開發,在使用APP inventor編程後連接的時候出現了藍牙許可權問題,該怎麼解決啊。急啊。

每個App裡面都有一個Androidmanifest.xml文件,我最近也遇到這個問題。摸索了好久才明白的。在你用App Inventor生成App以後,你可以用Apptool之類的工具把App解壓,裡面就有一個Androidmanifest.xml文件,你打開以後添加你需要允許的許可權,保存。再用Apptool反編譯一下,反編譯後的App要經過簽名才能在android上安裝,不然在大部分情況下的都是裝不上的。像你這個情況的話直接在裡面適當的位置添加<uses-permissionandroid:name="android.permission.BLUETOOTH_ADMIN" />就可以了

④ c++中藍牙編程的庫類

安裝PSDK就可以用了,之前有寫過一個類在MFC裡面調用,並能成功與藍牙手機通信,只不過是非標準的藍牙協議。代碼如下:
=====================h頭文件========================

#ifndef NS_BTH
#include "ws2bth.h" //如果沒有定義NS_BTH宏,則將PSDK頭文件包含進來
#endif

#ifndef BTH_ADDR
typedef ULONGLONG BTH_ADDR;
#endif

#ifndef SAFE_DELETE
#define SAFE_DELETE(pObj) {if(pObj) delete pObj; pObj = NULL;}
#endif

#ifndef SAFE_DELETERG
#define SAFE_DELETERG(pObj) {if(pObj) delete [] pObj; pObj = NULL;}
#endif

#define RECEIVE_OVER_COMMAND 0x00001000

typedef struct _tag_BthDev_Info
{
BTH_ADDR btAddr;
TCHAR szAddr[32];
TCHAR szName[128];

_tag_BthDev_Info()
{
memset(this, 0, sizeof(this));
}
}
BTHDEV_INFO;

class CGGBlueTooth
{
public:
CGGBlueTooth();
~CGGBlueTooth();

BOOL StartSearchBthDev(IN DWORD dwControlFlags);
BOOL GetNextBthDev(
IN OUT BTHDEV_INFO *pcBthDevInfo,
IN DWORD dwControlFlags = LUP_RETURN_NAME | LUP_RETURN_ADDR | LUP_FLUSHCACHE
);
BOOL EndSearchBthDev();

//Socket Api
BOOL Create(int af = AF_BTH, int type = SOCK_STREAM, int protocol = BTHPROTO_RFCOMM);
BOOL Close();

//If no error occurs, this function returns zero. If an error occurs, it returns SOCKET_ERROR
int Bind(BTH_ADDR sktAddr = 0, ULONG port = BT_PORT_ANY);
int Listen(IN int backlog);
int GetSockName(BTH_ADDR *psktAddr, ULONG *port);
int SetBthService(TCHAR *lpServiceName);
int Accept(CGGBlueTooth *pcBth);
int Connect(BTH_ADDR sktAddr, ULONG port, int nMSecond = -1);
int Send(LPVOID lpData, int len, int flags = 0);
int Recv(LPVOID lpData, int len, int flags = 0);
int SendAll(LPVOID lpData, int len, int flags = 0);
int RecvAll(LPVOID lpData, int len, int flags = 0);

private:
void HexMac2String(BTH_ADDR dw64Addr, TCHAR *pstrMac);

private:
HANDLE m_hLookup;
SOCKET m_hSocket;
SOCKADDR_BTH m_sktAddr;
};

==============cpp文件================

#include "stdafx.h"
#include "GGBlueTooth.h"
//#include "tchar.h"

CGGBlueTooth::CGGBlueTooth()
: m_hLookup(NULL)
, m_hSocket(NULL)
{
memset(&m_sktAddr, 0, sizeof(m_sktAddr));
}

CGGBlueTooth::~CGGBlueTooth()
{
EndSearchBthDev();
Close();
}

void CGGBlueTooth::HexMac2String(BTH_ADDR dw64Addr, TCHAR *pstrMac)
{
BYTE *pbAddr = (BYTE*)&dw64Addr;

_stprintf(
pstrMac, _T("%02X:%02X:%02X:%02X:%02X:%02X"),
pbAddr[5], pbAddr[4], pbAddr[3],
pbAddr[2], pbAddr[1], pbAddr[0]
);
}

BOOL CGGBlueTooth::StartSearchBthDev(IN DWORD dwControlFlags)
{
WSAQUERYSET wsaq;
ZeroMemory(&wsaq, sizeof(wsaq));
wsaq.dwSize = sizeof(wsaq);
wsaq.dwNameSpace = NS_BTH;
wsaq.lpcsaBuffer = NULL;

return WSALookupServiceBegin(&wsaq, dwControlFlags, &m_hLookup) == ERROR_SUCCESS ? TRUE : FALSE;
}

BOOL CGGBlueTooth::GetNextBthDev(
IN OUT BTHDEV_INFO *pcBthDevInfo,
IN DWORD dwControlFlags /* = LUP_RETURN_NAME | LUP_RETURN_ADDR | LUP_FLUSHCACHE*/
)
{
if (!m_hLookup || !pcBthDevInfo)
{
return FALSE;
}

memset(pcBthDevInfo->szAddr, 0, sizeof(pcBthDevInfo->szAddr));
memset(pcBthDevInfo->szName, 0, sizeof(pcBthDevInfo->szName));

union
{
CHAR buf[5000];
double __unused; // ensure proper alignment
};
LPWSAQUERYSET pwsaResults = (LPWSAQUERYSET)buf;
DWORD dwSize = sizeof(buf);
int nResult;

ZeroMemory(pwsaResults, sizeof(WSAQUERYSET));
pwsaResults->dwSize = sizeof(WSAQUERYSET);
pwsaResults->dwNameSpace = NS_BTH;
pwsaResults->lpBlob = NULL;

nResult = WSALookupServiceNext (m_hLookup, dwControlFlags, &dwSize, pwsaResults);
if (nResult == ERROR_SUCCESS)
{
pcBthDevInfo->btAddr = ((SOCKADDR_BTH *)pwsaResults->lpcsaBuffer->RemoteAddr.lpSockaddr)->btAddr;
BOOL bHaveName = pwsaResults->lpszServiceInstanceName && *(pwsaResults->lpszServiceInstanceName);

if (bHaveName)
{
HexMac2String(pcBthDevInfo->btAddr, pcBthDevInfo->szAddr);
_tcscpy(pcBthDevInfo->szName, pwsaResults->lpszServiceInstanceName);
}
return TRUE;
}

return FALSE;
}

BOOL CGGBlueTooth::EndSearchBthDev()
{
if (m_hLookup)
{
WSALookupServiceEnd(m_hLookup);
m_hLookup = NULL;
return TRUE;
}

return FALSE;
}

///===============================

BOOL CGGBlueTooth::Create(int af/* = AF_BTH*/, int type/* = SOCK_STREAM*/, int protocol/* = BTHPROTO_RFCOMM*/)
{
if (m_hSocket)
{
return FALSE;
}

m_hSocket = socket(af, type, protocol);
m_sktAddr.addressFamily = af;
m_sktAddr.serviceClassId = GUID_NULL;
return m_hSocket == INVALID_SOCKET ? FALSE : TRUE;
}

BOOL CGGBlueTooth::Close()
{
if (m_hSocket)
{
closesocket(m_hSocket);
return TRUE;
}
return FALSE;
}

int CGGBlueTooth::Bind(BTH_ADDR sktAddr/* = 0*/, ULONG port/* = BT_PORT_ANY*/)
{
m_sktAddr.btAddr = sktAddr;
m_sktAddr.port = port;
return bind(m_hSocket, (SOCKADDR *)&m_sktAddr, sizeof(m_sktAddr));
}

int CGGBlueTooth::Listen(int backlog)
{
return listen(m_hSocket, backlog);
}

int CGGBlueTooth::GetSockName(BTH_ADDR *psktAddr, ULONG *port)
{
int nLen = sizeof(m_sktAddr);
int nResult = getsockname(m_hSocket, (SOCKADDR *)&m_sktAddr, &nLen);
if (nResult == 0)
{
*psktAddr = m_sktAddr.btAddr;
*port = m_sktAddr.port;
}
return nResult;
}

GUID OBEXFileTransferServiceClass_UUID_EX = {0x00001106, 0x0000, 0x1000, 0x80, 0x00, 0x00, 0x80, 0x5F, 0x9B, 0x34, 0xFB};
int CGGBlueTooth::SetBthService(TCHAR * lpServiceName)
{
CSADDR_INFO sockInfo;
sockInfo.iProtocol = BTHPROTO_RFCOMM;
sockInfo.iSocketType = SOCK_STREAM;
sockInfo.LocalAddr.lpSockaddr = (SOCKADDR *)&m_sktAddr;
sockInfo.LocalAddr.iSockaddrLength = sizeof(m_sktAddr);
sockInfo.RemoteAddr.lpSockaddr = (SOCKADDR *)&m_sktAddr;
sockInfo.RemoteAddr.iSockaddrLength = sizeof(m_sktAddr);

WSAQUERYSET svcInfo = {0};
svcInfo.dwSize = sizeof(svcInfo);
svcInfo.dwNameSpace = NS_BTH;
svcInfo.lpszServiceInstanceName = lpServiceName;
svcInfo.lpServiceClassId = &OBEXFileTransferServiceClass_UUID_EX;
svcInfo.dwNumberOfCsAddrs = 1;
svcInfo.lpcsaBuffer = &sockInfo;

return WSASetService(&svcInfo, RNRSERVICE_REGISTER, 0);
}

int CGGBlueTooth::Accept(CGGBlueTooth *pcBth)
{
SOCKADDR_BTH ca;
int size = sizeof(ca);
pcBth->m_hSocket = accept (m_hSocket, (SOCKADDR *)&ca, &size);
pcBth->m_sktAddr = ca;
return pcBth->m_hSocket == INVALID_SOCKET ? SOCKET_ERROR : 0;
}

int CGGBlueTooth::Connect(BTH_ADDR sktAddr, ULONG port, int nMSecond/* = -1*/)
{
SOCKADDR_BTH sa = {0};
sa.addressFamily = AF_BTH;
sa.btAddr = sktAddr;
sa.port = port;

if (nMSecond == -1)
{
return connect(m_hSocket, (LPSOCKADDR)&sa, sizeof(SOCKADDR_BTH));
}

ULONG non_blocking = 1;
ULONG blocking = 0;

int nResult = ioctlsocket(m_hSocket, FIONBIO, &non_blocking);
if (nResult == SOCKET_ERROR)
{
return nResult;
}

nResult = SOCKET_ERROR;
if (connect(m_hSocket, (LPSOCKADDR)&sa, sizeof(SOCKADDR_BTH)) == SOCKET_ERROR)
{
struct timeval tv;
fd_set writefds;

// 設置連接超時時間
tv.tv_sec = nMSecond / 1000; // 秒數
tv.tv_usec = nMSecond % 1000; // 毫秒

FD_ZERO(&writefds);
FD_SET(m_hSocket, &writefds);

nResult = select((int)m_hSocket + 1, NULL, &writefds, NULL, &tv);
if(nResult > 0)
{
if(FD_ISSET(m_hSocket, &writefds))
{
int error = 0;
int len = sizeof(error);
//下面的一句一定要,主要針對防火牆
if(!(getsockopt(m_hSocket, SOL_SOCKET, SO_ERROR, (char *)&error, &len) != 0 || error != 0))
{
nResult = 0;
}
}
}
else if (nResult == 0)
{
nResult = -2;
}
}

if (ioctlsocket(m_hSocket, FIONBIO, &blocking) == SOCKET_ERROR)
{
nResult = SOCKET_ERROR;
}
return nResult;
}

int CGGBlueTooth::Send(LPVOID lpData, int len, int flags/* = 0*/)
{
return send(m_hSocket, (char *)lpData, len, flags);
}

int CGGBlueTooth::Recv(LPVOID lpData, int len, int flags/* = 0*/)
{
return recv(m_hSocket, (char *)lpData, len, flags);
}

int CGGBlueTooth::SendAll(LPVOID lpData, int len, int flags/* = 0*/)
{
int nCount = send(m_hSocket, (char *)lpData, len, flags);
if (nCount == SOCKET_ERROR && WSAGetLastError() != WSAEWOULDBLOCK)
{
return SOCKET_ERROR;
}

int nCommand = 0;
nCount = recv(m_hSocket, (char *)&nCommand, 4, flags);
if (nCount != 4 || nCommand != RECEIVE_OVER_COMMAND)
{
return SOCKET_ERROR;
}

return ERROR_SUCCESS;
}

int CGGBlueTooth::RecvAll(LPVOID lpData, int len, int flags/* = 0*/)
{
int nCount = -1, nCurRecv = 0, nMaxRead = 32 * 1024;

while (nCurRecv < len)
{
if (len - nCurRecv < nMaxRead)
{
nMaxRead = len - nCurRecv;
}

nCount = recv(m_hSocket, (char *)lpData + nCurRecv, nMaxRead, flags);

if (nCount == SOCKET_ERROR)
{
if (WSAGetLastError() == WSAEWOULDBLOCK)
{
Sleep(1);
continue;
}
else
{
return SOCKET_ERROR;
}
}

nCurRecv += nCount;
}

int nCommand = RECEIVE_OVER_COMMAND;
nCount = send(m_hSocket, (char *)&nCommand, 4, flags);
if (nCount == SOCKET_ERROR && WSAGetLastError() != WSAEWOULDBLOCK)
{
return SOCKET_ERROR;
}

return ERROR_SUCCESS;
}

⑤ android多連接藍牙編程,據說可以同時進行7個連接

你把你的代碼貼出來,在接收數據的時候是數據流接收,需要循環接收。

熱點內容
伺服器tt有什麼用 發布:2024-11-24 01:42:27 瀏覽:972
我的世界花語聽伺服器如何刷 發布:2024-11-24 01:38:05 瀏覽:566
用戶放棄編譯保存操作易語言 發布:2024-11-24 01:26:33 瀏覽:870
換個編譯器編譯代碼就報錯 發布:2024-11-24 01:19:38 瀏覽:328
蘋果手機如何像華為一樣掃一下找到無線密碼 發布:2024-11-24 01:15:36 瀏覽:952
T型存儲器 發布:2024-11-24 01:01:08 瀏覽:371
android操作串口 發布:2024-11-24 00:56:02 瀏覽:222
foxpro資料庫管理系統 發布:2024-11-24 00:44:53 瀏覽:822
python微信爬蟲 發布:2024-11-24 00:44:12 瀏覽:562
東北大腳本 發布:2024-11-24 00:42:26 瀏覽:533