귀찮아서 대충 구현했는데..

char 배열을 써야지 CString::GetBuffer(n) 으로 버퍼를 받아오니 이상해지네..


설정은 좀더 찾아 봐야겠지만, 자동으로timeout 걸리면서 최대 20자 까지 읽도록 설정이 된 것 같다.


{

CString port;

port = _T("\\\\.\\") + port;

HANDLE m_hCommPort = ::CreateFile(port, GENERIC_READ | GENERIC_WRITE, 0, 0, OPEN_EXISTING, 0/*FILE_FLAG_OVERLAPPED*/, 0);


DCB dcb = {0};

dcb.DCBlength = sizeof(DCB);


if (!::GetCommState (m_hCommPort,&dcb))

{

TRACE ("CSerialCommHelper : Failed to Get Comm State Reason: %d",

  GetLastError());

return E_FAIL;

}

dcb.BaudRate    = 115200

dcb.ByteSize    = 8;

dcb.Parity      = 0;

dcb.StopBits    = ONESTOPBIT;

if (!::SetCommState (m_hCommPort,&dcb))

{

ASSERT(0);

TRACE ( "CSerialCommHelper : Failed to Set Comm State Reason: %d",

GetLastError());

return E_FAIL;

}


CString hex_query="ffeeddccbbaa00";

DWORD iolen;

int iRet = WriteFile (m_hCommPort, hex_query, hex_query.GetLength(),&iolen ,NULL);


char temp[20];

int abRet = ReadFile(m_hCommPort, &temp ,20, &iolen, NULL) ;

temp[iolen] = '0x00';


CloseHandle(m_hCommPort);

return 0;



[링크 : http://blog.daum.net/chowood/8039404]

    [링크 : http://forum.falinux.com/zbxe/index.php?document_srl=572257]

    [링크 : http://forum.falinux.com/zbxe/index.php?document_srl=572404]

    [링크 : http://forum.falinux.com/zbxe/index.php?document_srl=572588]

    [링크 : http://forum.falinux.com/zbxe/index.php?document_srl=572862]

[링크 : https://www.codeproject.com/Articles/2682/Serial-Communication-in-Windows]

신고
Posted by 구차니

댓글을 달아 주세요