Jump to content
Sign in to follow this  

Заблокировать ком порт

Recommended Posts


Для того чтобы устройство на ttyACM0 правильно функционировало, необходимо чтобы программа открывала его в монопольном режиме, например

program открывает /dev/ttyACM0, тогда команда echo "aaaa" > /dev/ttyACM0 должна закончиться неудачей. Minicom это делает, а у меня не получается.

Вот код открытия:

fd = open(device, O_RDWR | O_EXCL );	  if (fd == -1)	  {	   /*	* Could not open the port.	*/	perror(device);		  //return NULL;	  }	//fcntl(fd, F_SETFL, FNDELAY);		struct flock lock;	lock . l_type = F_WRLCK;	lock . l_whence = SEEK_SET;	lock . l_start = 0;	lock . l_len = 0;	if (fcntl (fd, F_SETLK, & lock) < 0) {	  perror(device);	  //return NULL;	}	int status;		ioctl(fd, TIOCMGET, &status);	status &= ~TIOCM_RTS;	status &= ~TIOCM_DTR;	status &= ~TIOCM_CTS;	status &= ~TIOCM_DSR;	if (ioctl(fd, TIOCMSET, &status))	{	  perror("ioctl");	  //return 0;	}	struct termios options;	/*	 * Get the current options for the port...	 */	tcgetattr(fd, &options);	cfsetispeed(&options, baud_rate);	cfsetospeed(&options, baud_rate);		options.c_cflag &= ~PARENB;	options.c_cflag &= CSTOPB;	options.c_cflag &= ~CSIZE;	options.c_cflag |= CS8;	options.c_cflag &= ~CRTSCTS;	options.c_oflag &= ~OPOST; //raw output		options.c_lflag &= ~(ICANON | ECHO | ISIG);	/*	 * Enable the receiver and set local mode...	 */	options.c_cflag |= (CLOCAL | CREAD | baud_rate);		/*	 * Set the timeouts VMIN is the minimum amount of characters to read	 */		//options.c_cc[VMIN] = 0;		/*	 * The amount of time to wait for the amount of data specified by VMIN in tenths of a second	 */		//options.c_cc[VTIME] = 0;	/*	 * Set the new options for the port...	 */	tcsetattr(fd, TCSANOW, &options);

Подскажите, что не так. Либо кусок кода.где работает блокировка. Спасибо

Share this post

Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Sign in to follow this  

  • Create New...