테스트 필요


[링크 : https://www.joinc.co.kr/w/man/4200/ReadFile]

[링크 : http://stackoverflow.com/questions/4063051/possible-to-have-a-timeout-on-readfile]

[링크 : https://msdn.microsoft.com/en-us/library/windows/desktop/bb540534(v=vs.85).aspx]



+

2017.04.12

timeout은 overlapped io를 설정해야만 활성화 되는건가?

[링크 : http://wwwi.tistory.com/215]

[링크 : http://goodjian.tistory.com/entry/시리얼-통신COM-포트에-읽기-쓰기-할때-타임아웃을-설정하자]

[링크 : http://jurang5.tistory.com/entry/시리얼-통신]

[링크 : https://msdn.microsoft.com/en-us/library/windows/desktop/aa363437(v=vs.85).aspx]


+

음.. overlap 설정안해줘도 COMMTIMEOUTS 에서 적절한 값(?)을 해주니 문제없네..

115200bps에서 

commto.ReadIntervalTimeout = 50;

commto.ReadTotalTimeoutConstant = 50;

commto.ReadTotalTimeoutMultiplier = 10;

commto.WriteTotalTimeoutConstant = 50;

commto.WriteTotalTimeoutMultiplier = 10; 

로 설정해 주니 적당히 되는 듯

[링크  : http://blog.daum.net/pg365/51]




+

2017.04.19

115200bps 에서 이렇게 설정해도 문제가 없네.. 응답이 빨라서 가능한건가?

commto.ReadIntervalTimeout = 5;

commto.ReadTotalTimeoutConstant = 5;

commto.ReadTotalTimeoutMultiplier = 10;

commto.WriteTotalTimeoutConstant = 50;

commto.WriteTotalTimeoutMultiplier = 10; 


Posted by 구차니
개소리 왈왈2017. 4. 6. 09:21

네이트온에 알람이 떠서 생각이 났는데

망할 스팸놈이 알림에 또 띄우다니..


비도 오는데 울적하네..


2008/11/25 - [개소리 왈왈] - 이제는 볼 수 없는 사람


'개소리 왈왈' 카테고리의 다른 글

조현아 vs 탑  (0) 2017.06.09
19대 대선 유권자 수  (0) 2017.05.09
대전 현충원 안장자 검색  (0) 2017.01.07
경기가 안좋긴 하나보네  (0) 2016.12.10
이상하다 꿈을 꾼건가..  (0) 2016.05.14
Posted by 구차니
Programming/C Win32 MFC2017. 4. 5. 15:38

GetLBText() 로 해당 인덱스의 문자열을 받아올 수 있다.


[링크 : http://six605.tistory.com/250]


Gets a string from the list box of a combo box.

int GetLBText( 

   int nIndex, 

   LPTSTR lpszText  

) const;

 

void GetLBText( 

   int nIndex, 

   CString& rString  

) const; 

[링크 : https://msdn.microsoft.com/en-us/library/zcy9kze7(v=vs.110).aspx]

Posted by 구차니

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

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 구차니

1200 미만으로는 생소하고...

56000이냐 57600이냐는 좀 헷갈리네..

아무튼 가끔 쓸데 있으니 일단 링크!


Standard baud rates supported by most serial ports:
 
  • 110
  • 300
  •  
  • 600
  • 1200
  •  
  • 2400
  • 4800
  •  
  • 9600
  • 14400
  •  
  • 19200
  • 28800
  •  
  • 38400
  • 56000
  •  
  • 57600
  • 115200


  • Standard baud rates supported by some serial ports:
     
  • 128000
  • 153600
  •  
  • 230400
  • 256000
  •  
  • 460800
  • 921600


  • [링크 : http://digital.ni.com/public.nsf/allkb/D37754FFA24F7C3F86256706005B9BE7]

    Posted by 구차니
    Programming/C Win32 MFC2017. 4. 5. 14:28

    MFC 에서 쓸려면

    Group을 설정해야 하는데

    여러개를 묶을때 처음 녀석을 Group True로 설정

    그리고 나머지는 False로 하고

    가장 처음 Group True로 된 녀석에게 변수를 추가해주는데

    대개는 DDX 사용하도록 권장하는 듯

    [링크 : http://armcc.tistory.com/67]


    수작업(!)으로 하려면

    라디오 버튼은 CButton을 사용하기 때문에

    GetCheckedRadioButton(first, last); 메소드를 이용해서 체크된 녀석의 ID를 받아오거나

    [링크 : http://toring92.tistory.com/137]


    여러개의 그룹을 수작업으로

    ((CButton*)GetDlgItem(IDC_RADIO1))->GetCheck() 이런식으로 일일이 체크해야 할 듯 하다.

    [링크 : http://stackoverflow.com/questions/1165619/mfc-radio-buttons-ddx-radio-and-ddx-control-behavior]

    Posted by 구차니

    c#이나 .net framework을 쓰면 간편한데

    win32로는 영 복잡할수 밖에 없는 듯?


    그런데 QueryDosDevice()를 쓰면 0ms 라는데

    1. CreateFile("COM" + 1->255) as suggested by Wael Dalloul
      ✔ Found com0com ports, took 234ms.

    2. QueryDosDevice()
      ✔ Found com0com ports, took 0ms.

    3. GetDefaultCommConfig("COM" + 1->255)
      ✔ Found com0com ports, took 235ms.

    4. "SetupAPI1" using calls to SETUPAPI.DLL
      ✔ Found com0com ports, also reported "friendly names", took 15ms.

    5. "SetupAPI2" using calls to SETUPAPI.DLL
      ✘ Did not find com0com ports, reported "friendly names", took 32ms.

    6. EnumPorts()
      ✘ Reported some non-COM ports, did not find com0com ports, took 15ms.

    7. Using WMI calls
      ✔ Found com0com ports, also reported "friendly names", took 47ms.

    8. COM Database using calls to MSPORTS.DLL
      ✔/✘ Reported some non-COM ports, found com0com ports, took 16ms.

    9. Iterate over registry key HKEY_LOCAL_MACHINE\HARDWARE\DEVICEMAP\SERIALCOMM
      ✔ Found com0com ports, took 0ms. This is apparently what SysInternals PortMon uses.

    [링크 : http://stackoverflow.com/.../how-do-i-get-a-list-of-available-serial-ports-in-win32]


    m_MyPort 변수만 다른걸로 바꿔써주면 잘 작동 하는 듯

    단, unicode 기반에서는 (LPSTR)대신 (LPWSTR)로 해주어야 에러가 나지 않는다.

    void SelectComPort() //added function to find the present serial 
    {
    
        TCHAR lpTargetPath[5000]; // buffer to store the path of the COMPORTS
        DWORD test;
        bool gotPort=0; // in case the port is not found
    
        for(int i=0; i<255; i++) // checking ports from COM0 to COM255
        {
            CString str;
            str.Format(_T("%d"),i);
            CString ComName=CString("COM") + CString(str); // converting to COM0, COM1, COM2
    
            test = QueryDosDevice(ComName, (LPSTR)lpTargetPath, 5000);
    
                // Test the return value and error if any
            if(test!=0) //QueryDosDevice returns zero if it didn't find an object
            {
                m_MyPort.AddString((CString)ComName); // add to the ComboBox
                gotPort=1; // found port
            }
    
            if(::GetLastError()==ERROR_INSUFFICIENT_BUFFER)
            {
                lpTargetPath[10000]; // in case the buffer got filled, increase size of the buffer.
                continue;
            }
    
        }
    
        if(!gotPort) // if not port
        m_MyPort.AddString((CString)"No Active Ports Found"); // to display error message incase no ports found
    
    }


    [링크 : http://stackoverflow.com/.../what-is-proper-way-to-detect-all-available-serial-ports-on-windows]

    Posted by 구차니
    프로그램 사용/gcc2017. 4. 4. 21:00

    GCC G++ 공식문서를 찾지 못했는데

    아무튼.. wchar_t 로 wide character형이 추가된것 외에는 차이가 없는듯

    kldp 쪽을 봐도 gcc에서는 UTF-32 4byte 로 된다는 정도만 있는것 봐서는

    MSVC에 비해 유니코드 대응이 미진하긴 미진 한 듯.


    wchar_t

    type for wide character representation (see wide strings). Required to be large enough to represent any supported character code point (32 bits on systems that support Unicode. A notable exception is Windows, where wchar_t is 16 bits and holds UTF-16 code units) It has the same size, signedness, and alignment as one of the integral types, but is a distinct type.


    [링크 : http://en.cppreference.com/w/cpp/language/types]

    [링크 : http://en.cppreference.com/w/cpp/keyword]

    '프로그램 사용 > gcc' 카테고리의 다른 글

    gcc variadic macro  (0) 2017.06.20
    문자열에 escape 로 특수문자 넣기  (0) 2017.06.19
    gcc 매크로 확장 define stringfication  (0) 2017.01.02
    gcc make CFLAGS=-D 관련  (0) 2016.11.17
    gcc -fPIC  (0) 2016.06.22
    Posted by 구차니
    Programming/C Win32 MFC2017. 4. 4. 20:41

    음.. CString에서 제공하는 메소드는 아래뿐이네.. GetData() 나 다른것들은 상속에 의해서 다른 클래스에서 온 듯

    operator LPCTSTR

    GetBuffer() 

    [링크 : https://msdn.microsoft.com/en-us/library/aa315043(v=vs.60).aspx]


    GetString()은 누구꺼냐.. CObject의 스멜이 나긴 한다만...

    (LPCTSTR)로 캐스팅하는 것과 거의 구현이 같은 GetString() 이란 메소드도 있습니다. 

    [링크 : https://indidev.net/forum/viewtopic.php?f=5&t=92]


    음.. 걍 void* 형으로 캐스팅?

    CString str = L"английский"; //Russian Language

    DWORD dwWritten=0;

    WriteFile(pHandle , (void*) str, str.GetLength()*sizeof(TCHAR),&dwWritten , NULL);

    [링크 : https://social.msdn.microsoft.com/.../how-to-send-unicode-characters-to-serial-port?forum=vcgeneral]


    LPSTR - Long Pointer STRing

    LPCSTR - LP Const STRing

    LPTSTR - LP Tchar STRing

    LPCTSTR - LPC Tchar STRing

    LPWSTR - LP Wchar STRing

    LPCWSTR - LP Const Wchar STRing

    [링크 : http://pelican7.egloos.com/v/1768951]


    char 형식의 좁은 문자 리터럴(예: 'a')

    wchar_t 형식의 와이드 문자 리터럴(예: L'a')

    char16_t 형식의 와이드 문자 리터럴(예: u'a')

    char32_t 형식의 와이드 문자 리터럴(예: U'a') 

    [링크 : https://msdn.microsoft.com/ko-kr/library/69ze775t.aspx]


    TEXT("")과 _T("")의 차이점은

    TEXT("")는 WinNT.h에서 #define했고

    _T("")는 tchar.h에서 TEXT가 4글자라서 _T이렇게 2글자로 #define했다. 

    [링크 : http://x108zero.blogspot.kr/2013/12/text-t-l.html]



    +

    tchar.h

    #define __T(x)      L ## x

    #define _T(x)       __T(x)


    음.. L 이야 Long에 대한 prefix literal 이니...까?



    'Programming > C Win32 MFC' 카테고리의 다른 글

    mfc ccombobox 문자열 받아오기  (0) 2017.04.05
    MFC 라디오버튼 사용하기  (0) 2017.04.05
    bit field와 컴파일러별 byte align  (0) 2017.03.27
    MFC CButton 마우스 클릭시 작동하기  (0) 2017.03.08
    GetHttpConnection()  (0) 2017.03.03
    Posted by 구차니

    시리얼포트 10번 이후 열기라는 글이 있어서 보니


    버그가 있어서 COM9 까진 그냥 여는데, 그 이후에는

    \\.\COM%d 식으로 표현을 해야 하는데 escape 문자를 넣어주어야 하니 이렇게 미친듯이 길어진다.


    hPort = CreateFile("\\\\.\\COM10", GENERIC_READ | GENERIC_WRITE, 0, 0, OPEN_EXISTING, 0, 0); 

    [링크 : http://stackoverflow.com/questions/11775185/open-a-com-port-in-c-with-number-higher-that-9]

    Posted by 구차니