AT команды
Код:
OVERLAPPED ovl;
ovl.Offset = 0;
ovl.OffsetHigh = 0;
ovl.hEvent = 0;
HANDLE hCom;
hCom = CreateFile(L"\\\\.\\COM11", GENERIC_READ | GENERIC_WRITE, 0, NULL,
OPEN_EXISTING, FILE_FLAG_OVERLAPPED,NULL);
if(hCom == INVALID_HANDLE_VALUE)
printf("Cannot open com port %d", GetLastError());
wchar_t buf2[100];
wchar_t *buf;
DWORD read = 0;
DWORD write=1;
buf = L"AT";
WriteFile(hCom,buf,write,&write,&ovl);
WaitForSingleObject(hCom,INFINITE);
ReadFile(hCom,buf2,sizeof(buf),&read,&ovl);
ovl.Offset = 0;
ovl.OffsetHigh = 0;
ovl.hEvent = 0;
HANDLE hCom;
hCom = CreateFile(L"\\\\.\\COM11", GENERIC_READ | GENERIC_WRITE, 0, NULL,
OPEN_EXISTING, FILE_FLAG_OVERLAPPED,NULL);
if(hCom == INVALID_HANDLE_VALUE)
printf("Cannot open com port %d", GetLastError());
wchar_t buf2[100];
wchar_t *buf;
DWORD read = 0;
DWORD write=1;
buf = L"AT";
WriteFile(hCom,buf,write,&write,&ovl);
WaitForSingleObject(hCom,INFINITE);
ReadFile(hCom,buf2,sizeof(buf),&read,&ovl);
Спасибо drfaust, но не посмотрите мой код, WaitForSingleObject(hCom,INFINITE); для ожидания ответа от устройства, мне его еще нужно согласовать(скорость и т.д) чтоб с ним можно было работать, может кто сталкивался с подобным вопросом подскажите пожалуйста.
#include <windows.h>
#include <iostream>
#include <stdio.h>
using namespace std;
int main()
{
char szPort [] = "\\.\\COM3";
char wr [] = "ATD номер телефона";
OVERLAPPED overlap;
DWORD temp;
bool fl;
HANDLE hCom = CreateFile(szPort,GENERIC_READ | GENERIC_WRITE, 0, NULL,OPEN_EXISTING,0 /*FILE_FLAG_OVERLAPPED*/,NULL);
if(hCom == INVALID_HANDLE_VALUE)
{
cout << "Error opening port";
cin.get();
return 1;
}
else
{
cout << "Port succesfully opened!\n";
DCB dcb;
GetCommState(hCom,&dcb);
dcb.BaudRate = CBR_115200;
dcb.ByteSize = 8;
dcb.Parity = NOPARITY;
dcb.StopBits = ONESTOPBIT;
if (SetCommState(hCom,&dcb))
cout <<"Configuring OK.\n";
else
cout << "Configure error.\n";
}
overlap.hEvent = CreateEvent(NULL, true, true,NULL);
WriteFile(hCom, wr,sizeof(wr),&temp,&overlap);
DWORD signal = WaitForSingleObject(overlap.hEvent, INFINITE);
WaitForSingleObject(overlap.hEvent, INFINITE);
if((signal == WAIT_OBJECT_0) && (GetOverlappedResult(hCom, &overlap, &temp, true))) fl = true;
else fl = false;
//
CloseHandle(hCom);
cin.get();
return 0;
}