Hello, i want to develope an application on a windows mobile that communicate over serial port. i want to program it on c/c++.
this the code that i used
#include <stdio.h>
#include <tchar.h>
#include <windows.h>
#include <assert.h>
int _tmain(int argc, _TCHAR* argv[])
{FILE *fp;
HANDLE m_hUsbCom ;
LPTSTR portName = TEXT("COM4");
m_hUsbCom = CreateFile (
portName , GENERIC_READ | GENERIC_WRITE, 0, NULL, OPEN_EXISTING, 0, NULL);
if ( m_hUsbCom == INVALID_HANDLE_VALUE )
{
fp = fopen("error.txt", "w+");
fclose(fp);
}
else
{
fp = fopen("succed ", "w+");
fclose(fp);
}
}
The problem that i could'nt open the port ??? why
please help
What I have tried:
#include <stdio.h>
#include <tchar.h>
#include <windows.h>
#include <assert.h>
int _tmain(int argc, _TCHAR* argv[])
{FILE *fp;
HANDLE m_hUsbCom ;
LPTSTR portName = TEXT("COM4");
m_hUsbCom = CreateFile (
portName , // Pointer to the name of the port
GENERIC_READ | GENERIC_WRITE, // Access (read/write) mode
0, // Share mode
NULL, // Pointer to the security attribute
OPEN_EXISTING, // How to open the serial port
0, // Port attributes
NULL); // Handle to port with attribute to copy
if ( m_hUsbCom == INVALID_HANDLE_VALUE )
{
fp = fopen("error.txt", "w+");
fclose(fp);
}
else
{
fp = fopen("succed ", "w+");
fclose(fp);
}
}