【发布时间】:2014-06-19 11:35:52
【问题描述】:
我在 C++ 上写过小程序,她切换调制解调器 2G\3G 模式。 它不起作用:-(
程序从调制解调器读取数据,如果发送 AT-Comands 调制解调器没有应答。
请帮帮我;-)
// 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;
}
【问题讨论】:
标签: c++ usb at-command modem