• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 302
  • Last Modified:

Writing to Infra red/COM port using Embedded C++

Hi Guys,
Has anyone any pointers or know any web links with sample code for writing data to Infra Red Port or any of the COM ports on Pocket PC.

For Example to have a screen with a text box on it and to print the contents of the Text Box to an Infra Red printer


Cheers



B Cunney
0
Barry Cunney
Asked:
Barry Cunney
1 Solution
 
abelblaine111Commented:
Here is a link with some code for you.

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnfiles/html/msdn_serial.asp

and here is some basic sample code for the pocket pc.  m_hCommPort is a HANDLE defined in the class

char* str = "";
DWORD numWrite;
DWORD numRead;
BOOL success = FALSE;

m_hCommPort = CreateFile(
     TEXT("COM1"),
     GENERIC_READ | GENERIC_WRITE,
     0,// comm devices must be opened w/exclusive-access
     NULL,      // no security attributes
     OPEN_EXISTING,//comm devices must use OPEN_EXISTING
     0,     // not overlapped I/O
     NULL   // hTemplate must be NULL for comm devices
     );
     if (m_hCommPort == INVALID_HANDLE_VALUE)
        AfxMessageBox(TEXT("Invalid Handle Value"));
     
     strcpy(str, "s");

     success = WriteFile(m_hCommPort, str, strlen(str), &numWrite, 0);
     
     if (!success)
          AfxMessageBox(TEXT("error in Write File"));
     
     Sleep(3000); //Delay for transmissionsuccess =

     char str2[65530];
     
     ReadFile(m_hCommPort, str2, 65530, &numRead, 0);
     if (!success)
          AfxMessageBox(TEXT("Error in Read File"));
     else
     {
          CString j(numRead);
          AfxMessageBox(j);
     }
     CloseHandle(m_hCommPort);

Hope those help.
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now