Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
Q

Q150022

@Q150022
About
Posts
1
Topics
1
Shares
0
Groups
0
Followers
0
Following
0

Posts

Recent Best Controversial

  • Using the serial com port
    Q Q150022

    Hi, I am using the following code to talk to the 'Com1': int CommPort::CreatePort(_Port port , HANDLE *hCom) { DCB dcb; bool fSuccess; char *pcCommPort; CString buffer; buffer.Format("\\\\.\\%s", port.com); pcCommPort = new char[buffer.GetLength() + 1]; for(int i = 0; i <= buffer.GetLength(); i++) *(pcCommPort + i) = buffer.GetAt(i); *hCom = CreateFile(pcCommPort, GENERIC_READ | GENERIC_WRITE, 0, NULL, OPEN_EXISTING, 0, NULL); delete[] pcCommPort; if(*hCom == INVALID_HANDLE_VALUE) return -1; fSuccess = GetCommState(*hCom, &dcb); //Portkonfiguration mit GetCommState if(!fSuccess) return -1; dcb.BaudRate = port.dcb.BaudRate;//Konfigurationswerte des Ports dcb.ByteSize = port.dcb.ByteSize; dcb.Parity = port.dcb.Parity; dcb.StopBits = port.dcb.StopBits; dcb.fAbortOnError = true; dcb.fTXContinueOnXoff = true; fSuccess = SetCommState(*hCom, &dcb);//Portkonfiguration mit SetCommState if(!fSuccess) return -1; return 1; } So far so good. But if I try to read the port by using : bool CommPort::ReadPort(HANDLE hCom, CString *ScannText) { char buf[128]; DWORD lpNumberOfBytesRead; bool bReturn; bReturn = ReadFile(hCom, &buf, 128, &lpNumberOfBytesRead, NULL); buf[lpNumberOfBytesRead] = '\0'; *ScannText = buf; return bReturn; } I don't get the information of the port. I am able to read the port only if I connect to COM1 with hyperterminal. After connecting with hyperterminal the program runs without problems. But if I shut down my PC and start it again I will not be able to run my program. I must always start hyperterminal first. Is there anybody who can help?

    C / C++ / MFC com help question
  • Login

  • Don't have an account? Register

  • Login or register to search.
  • First post
    Last post
0
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups