ALT Linux Community general discussions
 help / color / mirror / Atom feed
From: "Прокопьев Евгений" <john@rmts.donpac.ru>
To: community@altlinux.ru
Subject: [Comm] Программирование для COM-порта
Date: Thu, 16 Jan 2003 15:40:11 +0300
Message-ID: <3E26A82B.2020608@rmts.donpac.ru> (raw)

Здравствуйте!

Как в программе на С устанавливать параметры COM-порта?

Ecть следующий код для оффтопика, необходимо написать его аналог:

#ifdef __WIN32__
   handle = CreateFile(port.c_str(), GENERIC_READ|GENERIC_WRITE, 0, 
NULL, OPEN_EXISTING, 0, NULL);

   if (handle == INVALID_HANDLE_VALUE)
     throw runtime_error("serial device "+port+" open error");

   DCB dcb;
   ZeroMemory(&dcb, sizeof(DCB));
   if (!GetCommState(handle, &dcb))
		throw runtime_error("serial device "+port+" get state error");

   dcb.DCBlength=sizeof(DCB);
   BuildCommDCB(params.c_str(), &dcb);

   dcb.BaudRate = 600;
   dcb.ByteSize = 8;
   dcb.Parity   = NOPARITY;
   dcb.StopBits = TWOSTOPBITS;

   if (!SetCommState(handle, &dcb))
     throw runtime_error("serial device "+port+" set state error");

   COMMTIMEOUTS  ct;
   ZeroMemory(&ct, sizeof(COMMTIMEOUTS));
   ct.ReadIntervalTimeout = MAXDWORD;
   ct.ReadTotalTimeoutMultiplier = ct.ReadTotalTimeoutConstant = 0;
   ct.WriteTotalTimeoutMultiplier = ct.WriteTotalTimeoutConstant = 0;
   SetCommTimeouts(handle, &ct);
#endif

-- 
С уважением, Прокопьев Евгений



             reply	other threads:[~2003-01-16 12:40 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2003-01-16 12:40 Прокопьев Евгений [this message]
2003-01-16 13:05 ` Sergey Vlasov
2003-01-16 13:49 ` [Comm] " Бессонов Ян

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=3E26A82B.2020608@rmts.donpac.ru \
    --to=john@rmts.donpac.ru \
    --cc=community@altlinux.ru \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link

ALT Linux Community general discussions

This inbox may be cloned and mirrored by anyone:

	git clone --mirror http://lore.altlinux.org/community/0 community/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 community community/ http://lore.altlinux.org/community \
		mandrake-russian@linuxteam.iplabs.ru community@lists.altlinux.org community@lists.altlinux.ru community@lists.altlinux.com
	public-inbox-index community

Example config snippet for mirrors.
Newsgroup available over NNTP:
	nntp://lore.altlinux.org/org.altlinux.lists.community


AGPL code for this site: git clone https://public-inbox.org/public-inbox.git