C++ program freezes during COM port read -


I am trying to write a simple program to send a letter to a program through a COM port and I Read the answers that you get. I think that I am working on the script, where I can send the command at least through a comm port, but when the ReadFile function starts, it is free. I have a comm timeout of 100 mms , So I do not think this port is closing, but I can be wrong. I am not getting any error, and when I compile there is no warning. I'm very new to C ++ (usually working with Python), so please be possible with your answers.

  // comtest.cpp: defines the entry point for the console application // # include "stdafx.h" #include & lt; Iostream & gt; #include & lt; String & gt; # Include & lt; Sstream & gt; # Include & lt; Dos.h & gt; # Include & lt; Stdio.h & gt; # Include & lt; Conio.h & gt; #include & lt; String.h & gt; #include & lt; Windows.h & gt; Int main (int argc, char ** argv) {std :: cout & lt; & Lt; "Top! \ N"; Four buffer [1]; Handle file; Commmimates timeout; DWORD read, written; DCB port; Four init [] = ""; // eg, "ATZ" to completely reset the modem // open the com port File = CreateFile (L "COM1", GENERIC_READ | GENERIC_WRITE, 0, NULL, OPEN_EXISTING, 0, NULL); Std :: cout & lt; & Lt; "File was created \ n"; // Get current DCB, and adjust some bit for our choice. Memeset (and port, 0, size (port)); Port.DCBlength = sizeof (port); // Set less timeout timeout on comm port.ReadIntervalTimeout = 100; Timeout Redtat timeout multiplayer = 1; Timeout RETTATTimeout Constant = 100; Timeout Write Length TimeMultiplier = 1; Timeout WriteTime Time Constant = 100; Int n = 10; While (N> 1) {std :: cout & lt; & Lt; "I'm in the loop!" & Lt; & Lt; N & lt; & Lt; "Left the loops \ n"; Four commands [1]; Four * commandbuff; Std :: cin & gt; & Gt; order; CommandBuff = & amp; Command [1]; Envelope (file, bowbuff, size, and writing, faucet); Sleep (1000); Std :: cout & lt; & Lt; "I just slept \ n"; Readfile (file, buffer, size (buffer), read more, tap); N--; } // Stop and go home. CloseHandle (file); Return 0;  

Your code does not really call, so any time to implement the defined timeout Not the way.


Comments

Popular posts from this blog

sqlite3 - UPDATE a table from the SELECT of another one -

c# - Showing a SelectedItem's Property -

javascript - Render HTML after each iteration in loop -