Hi Anweil,
Thank you very much for your suggestion. That was my intention. I am struggling desparetly to get the connection working. I have written a basic program that opens a port on COM2 and then tries to just send an at command. So far i have been unsuccessful. The writing part is where i am getting stuck at the moment.
I have attached the code here. Can you give me any pointers on where i am going wrong?
#include <windows.h>
#include <stdio.h>
#include <iostream.h>
#include <tchar.h>
int main()
{
bool TestCom;
DWORD ModemStat;
int TestRes;
char TextSt[] = “AT+6122222222;\r”;
TCHAR TestString[] = “AT/r”;
DCB m_dcb; //DCB structure.
HANDLE hComm;
COMMTIMEOUTS commtimeouts; // COMMTIEMOUTS structure (not used yet)
OVERLAPPED m_overlap; //OVERLAPPED structure
LPOVERLAPPED_COMPLETION_ROUTINE Routine = LPOVERLAPPED_COMPLETION_ROUTINE(); // Routine to finalise write statment
cout << “Start of Program” << endl;
Sleep(2000);
hComm = CreateFile(“COM2”, GENERIC_READ | GENERIC_WRITE, 0,0, OPEN_ALWAYS,FILE_FLAG_OVERLAPPED, 0);
TestRes = GetCommModemStatus(hComm,&ModemStat);
if (TestRes==0) cout << “Status Failed” << endl;
else
{
cout << “Status Success” << endl;
cout << "Status is " << ModemStat << endl;
}
Sleep(5000);
m_dcb.BaudRate =9600;
m_dcb.ByteSize = 8;
m_dcb.Parity =0 ;
m_dcb.StopBits =0;
m_dcb.fBinary=TRUE;
m_dcb.fDsrSensitivity=false;
m_dcb.fParity=false;
m_dcb.fOutX=false;
m_dcb.fInX=false;
m_dcb.fNull=false;
m_dcb.fAbortOnError=TRUE;
m_dcb.fOutxCtsFlow=FALSE;
m_dcb.fOutxDsrFlow=false;
m_dcb.fDtrControl=DTR_CONTROL_DISABLE;
m_dcb.fDsrSensitivity=false;
m_dcb.fRtsControl=RTS_CONTROL_DISABLE;
m_dcb.fOutxCtsFlow=false;
m_dcb.fOutxCtsFlow=false;
TestRes = SetCommState(hComm,&m_dcb);
if (TestRes==0) cout << “UnSuccessful Config” << endl;
else cout << “Succesfully configured port” << endl;
cout << TestString << endl;
cout << "Size of TEXT (No of bytes) " << sizeof(TestString) << endl;
cout << *TestString << endl;
cout << &TestString << endl;
TestRes = WriteFileEx(hComm,&TestString,sizeof(TestString),&m_overlap,Routine);
if (TestRes != 0) cout << “The write was sent successfully” << endl;
else cout << "Unsucessful WRITE operation " << endl;
Sleep(5000);
cout<< Routine << endl;
cout << “Closing Port” << endl;
TestCom = CloseHandle(hComm);
if (TestCom) cout << “Port Closed Successfully” << endl;
else cout << “Error in closing port” << endl;
Sleep(5000);
return 0;
};
I get a message stating that the Write message wasn’t sent correctly? I am at a lost as to why this is occuring?
Regards
Jas