cần giúp
//portname= "//./" +portname;
HANDLE hComm = CreateFile(TEXT("COM3:"),
GENERIC_READ|GENERIC_WRITE, 0, NULL, OPEN_EXISTING,
FILE_ATTRIBUTE_NORMAL, NULL);
if(hComm == INVALID_HANDLE_VALUE)
{
MessageBox(TEXT("CHUA KET NOI THANH CONG???"), TEXT("Error!"), MB_OK);
return false;
}
else
{
MessageBox(TEXT("Ket noi thanh cong"), TEXT("Bat dau thuc hien dieu khien"), MB_OK);
return true;
}
}
///////////////////////////////////////////////////////////////////////////
//ConfigurePort
//////////////////////////////////////////////////////////////////////////
BOOL CSerialCom::ConfigurePort(DWORD BaudRate, BYTE ByteSize,
DWORD Parity, BYTE fParity, BYTE StopBits)
{
////////////////////////////////////////
//structure containing the device configuration settings when the function returns.
//If the call is successful, the function returns a TRUE value
////////////////////////////////////////
COMMPROP commProp;
memset(&commProp, 0, sizeof(COMMPROP));
GetCommProperties(hComm, &commProp);
//////////////////////////////////////////
//DCB m_dcb;
memset(&m_dcb, 0, sizeof(DCB));
/////////////////////////////////////////
BOOL fSuccess = FALSE;
memset(&m_dcb, 0, sizeof(DCB));
// The the current communication port settings
if(GetCommState(hComm, &m_dcb))
{
// Can we change the settings? Let's check the commProp
if(commProp.dwSettableParams && SP_BAUD) {
m_dcb.BaudRate = BAUD_9600;
m_dcb.Parity = 0;
m_dcb.fParity = PARITY_NONE;
m_dcb.StopBits = ONESTOPBIT;
m_dcb.ByteSize = 8;
fSuccess = SetCommState(hComm, &m_dcb);
}
return true;
}
if(fSuccess==0)
{
MessageBox(TEXT("Could not modify the port's settings"),TEXT("Error!"), MB_OK);
}
else
MessageBox(TEXT("thanh cong"),TEXT("thanh cong"), MB_OK);
return true;
--------------->>>> tại sao ko thể thanh công được??