Reputation: 21
I have write small programm on C++, she switch modem 2G\3G mode. its not work :-(
progrm read data form modem, if send AT-Comands modem not answer.
please help me ;-)
// huawei_mode_switcher
#include <windows.h>
#include <iostream>
#include <stdlib.h>
using namespace std;
int main(){
LPCTSTR sPortName = "//./COM13";
char data[] = "AT^SYSCFG=13,1,3FFFFFFF,2,4";
DWORD dwSize = sizeof(data);
DWORD dwBytesWritten;
HANDLE hSerial = CreateFile(sPortName,GENERIC_READ | GENERIC_WRITE,0,0,OPEN_EXISTING,FILE_ATTRIBUTE_NORMAL,0);
if(hSerial==INVALID_HANDLE_VALUE){
if(GetLastError()==ERROR_FILE_NOT_FOUND)
{
cout << "com port zanyat\n";
}
cout << "other error\n";
}
else {
BOOL iRet = WriteFile (hSerial,data,dwSize,&dwBytesWritten,NULL);
Sleep(100);
while(1)
{
DWORD iSize;
char sReceivedChar;
while (true)
{
ReadFile(hSerial, &sReceivedChar, 1, &iSize, 0);
if (iSize > 0)
cout << sReceivedChar;
}
}
}
system("pause");
return 0;
}
Upvotes: 1
Views: 1467
Reputation: 15511
This line
DWORD dwSize = sizeof(data);
sets dwSize
to the size of the string including the null-character at the end, which I don't think you want to send. And the command must end with the \r
character. Try:
char data[] = "AT^SYSCFG=13,1,3FFFFFFF,2,4\r";
DWORD dwSize = strlen(data); // use strlen instead of sizeof
(See hlovdal's comment below for reference. Also http://en.wikipedia.org/wiki/Hayes_command_set#The_basic_Hayes_command_set.)
Upvotes: 2