ALT Linux Community general discussions
 help / color / mirror / Atom feed
* [Comm] Программирование для COM-порта
@ 2003-01-16 12:40 Прокопьев Евгений
  2003-01-16 13:05 ` Sergey Vlasov
  2003-01-16 13:49 ` [Comm] " Бессонов Ян
  0 siblings, 2 replies; 3+ messages in thread
From: Прокопьев Евгений @ 2003-01-16 12:40 UTC (permalink / raw)
  To: community

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

Как в программе на С устанавливать параметры 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

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



^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2003-01-16 13:49 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2003-01-16 12:40 [Comm] Программирование для COM-порта Прокопьев Евгений
2003-01-16 13:05 ` Sergey Vlasov
2003-01-16 13:49 ` [Comm] " Бессонов Ян

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