대부분의 툴들이..
USB 시리얼 뽑으면 먹통이 되는 경우가 많은데
그거 해결용으로 검색중..
[링크 : https://stackoverflow.com/.../identify-disconnect-event-with-a-windows-usb-virtual-com-port]
FTDI의 경우에는 이렇게 보내는 주는 듯?
class CAboutDlg : public CDialog { void CD2XXNotifyDlg::OnPaint(); BOOL CD2XXNotifyDlg::OnDeviceChange(UINT EventType, DWORD dwData); protected: DECLARE_MESSAGE_MAP() }; void CAboutDlg::DoDataExchange(CDataExchange* pDX){} BEGIN_MESSAGE_MAP(CD2XXNotifyDlg, CDialog) ON_WM_PAINT() ON_WM_DEVICECHANGE() END_MESSAGE_MAP() void CD2XXNotifyDlg::OnPaint() {} BOOL CD2XXNotifyDlg::OnDeviceChange(UINT EventType, DWORD dwData)
{} |
[링크 : http://www.ftdichip.com/.../AN_152_Detecting_USB_%20Device_Insertion_and_Removal.pdf]
MFC 클래스 위저드에는 WM_DEVICECHANGE가 없는데 afxmsg.h 에는 존재한다.
#define ON_WM_DEVICECHANGE() \ { WM_DEVICECHANGE, 0, 0, 0, AfxSig_bwl, \ (AFX_PMSG)(AFX_PMSGW) \ (static_cast< BOOL (AFX_MSG_CALL CWnd::*)(UINT, DWORD_PTR) > ( &ThisClass :: OnDeviceChange)) }, |
case WM_DEVICECHANGE:
{
//
// This is the actual message from the interface via Windows messaging.
// This code includes some additional decoding for this particular device type
// and some common validation checks.
//
// Note that not all devices utilize these optional parameters in the same
// way. Refer to the extended information for your particular device type
// specified by your GUID.
//
PDEV_BROADCAST_DEVICEINTERFACE b = (PDEV_BROADCAST_DEVICEINTERFACE) lParam;
TCHAR strBuff[256];
// Output some messages to the window.
switch (wParam)
{
case DBT_DEVICEARRIVAL:
msgCount++;
StringCchPrintf(
strBuff, 256,
TEXT("Message %d: DBT_DEVICEARRIVAL\n"), msgCount);
break;
case DBT_DEVICEREMOVECOMPLETE:
msgCount++;
StringCchPrintf(
strBuff, 256,
TEXT("Message %d: DBT_DEVICEREMOVECOMPLETE\n"), msgCount);
break;
case DBT_DEVNODES_CHANGED:
msgCount++;
StringCchPrintf(
strBuff, 256,
TEXT("Message %d: DBT_DEVNODES_CHANGED\n"), msgCount);
break;
default:
msgCount++;
StringCchPrintf(
strBuff, 256,
TEXT("Message %d: WM_DEVICECHANGE message received, value %d unhandled.\n"),
msgCount, wParam);
break;
}
OutputMessage(hEditWnd, wParam, (LPARAM)strBuff); } |
[링크 : https://msdn.microsoft.com/en-us/library/windows/desktop/aa363432(v=vs.85).aspx]
뽑으면 0x0007->0x8004 순서로 발생하고
꼽으면 0x0007->0x0007->0x8000->0x0007 으로 발생한다.
(근데 뽑는건 꼽는거에 비해서 반응이 많이 느리거나 안될때도 있음)
DBT_DEVNODES_CHANGED 0x0007 DBT_DEVICEARRIVAL 0x8000 DBT_DEVICEREMOVECOMPLETE 0x8004 |
[링크 : https://msdn.microsoft.com/en-us/library/windows/desktop/aa363480(v=vs.85).aspx]
+
여긴 일단 .net 쪽
[링크 : https://stackoverflow.com/.../usb-serial-port-unplugged-but-still-in-the-list-of-ports]
[링크 : https://stackoverflow.com/.../com-port-disappears-when-unplugging-usb]