LinuxQuestions.org
Review your favorite Linux distribution.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Hardware
User Name
Password
Linux - Hardware This forum is for Hardware issues.
Having trouble installing a piece of hardware? Want to know if that peripheral is compatible with Linux?

Notices


Reply
  Search this Thread
Old 10-18-2015, 05:15 PM   #1
MCinAZ
LQ Newbie
 
Registered: Jun 2008
Location: Arizona
Distribution: Debian
Posts: 22

Rep: Reputation: 2
USB serial interface - initial read(2) ops fail, "Resource temporarily unavailable"


I have a small MCU-based circuit which uses a Microchip MCP220 serial/USB interface to provide a USB data link. The link runs at 38.4 kbaud, and for the most part is very reliable. When connected to a host running either Debian 7 or Linux Mint 17, "/dev/ttyACM0" appears after 10 - 15 seconds. Once the device node has been created, minicom can be used to establish a connection and communications from that point forward work 100% of the time.

Our application requires the ability to connect to the MCU board regardless of the state of the serial link. In other words, the application may be re-establishing communication with the board after being restarted when the link hasn't been disturbed, a connection attempt may be the first time after both the application has launched and the board has been powered on, or the board may be disconnected then reconnected while the application is running.

I've written a simple C program with a loop which attempts to open the device once per second until either success or a termination count is reached. When the program is launched a few seconds before the USB cable is connected (or the MCU board is powered on), the call to open(2) eventually succeeds. A read operation is next attempted to purge any characters which may be in the queue, then crtl-C is transmitted to the MCU board to put it in a known state. After that, some additional commands are transmitted and the responses received are examined to ensure that all is well. O_NONBLOCK is set when the port is opened so that the program won't hang if there are no characters to purge, though I've tried several combinations of other flags which don't affect the problem described below.

I'm running into problems when the device node is opened the first time after connection. The call to open() succeeds, however subsequent read() calls fail. error(3) reports "Resource temporarily unavailable". This occurs an indefinite number of times, so in this case temporary doesn't imply that eventually read operations will succeed. If I run minicom, even if I do nothing more than launch the program then immediately exit without transferring any data, my program will work thereafter. It's evident that minicom is performing some operation that I'm missing, however I've so far not been able to determine what that might be. If anyone can provide some insights, I'd be most grateful.

-- Mike --
 
Old 10-18-2015, 06:23 PM   #2
berndbausch
LQ Addict
 
Registered: Nov 2013
Location: Tokyo
Distribution: Mostly Ubuntu and Centos
Posts: 6,316

Rep: Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002
This error means that read() or write() would block if you hadn't set O_NONBLOCK in open().

Check if there are messages in the message buffer. They would be written to /var/log/syslog, or just run dmesg when you conduct your tests.

Perhaps the driver allows setting a debug flag to generate more messages.

Device control is usually done with ioctl() system calls. If you don't know the right sequence of actions to put your board in a workable state, perhaps you are successful by snopping what minicom is doing. You could run minicom under strace(1) and focus on ioctl() calls.
 
Old 10-19-2015, 02:19 AM   #3
blue_z
Member
 
Registered: Jul 2015
Location: USA
Distribution: Ubuntu, Lubuntu, Mint, custom embedded
Posts: 104

Rep: Reputation: Disabled
Quote:
Originally Posted by MCinAZ View Post
O_NONBLOCK is set when the port is opened so that the program won't hang if there are no characters to purge ...
Why not use tcflush(fd, TCIFLUSH) instead of a nonblocked read to purge?

Quote:
Originally Posted by MCinAZ View Post
It's evident that minicom is performing some operation that I'm missing, however I've so far not been able to determine what that might be.
What have you tried in that regard?
Did you look at the source code for minicom?
Did you try an strace on minicom?

Regards
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] "bash: fork: Resource temporarily unavailable" now occurring, did not before RandomTroll Linux - Software 3 04-18-2013 07:56 PM
"fatal IO error 11 (Resource temporarily unavailable) on X server" with two windows 10_GOTO_10 Linux - Software 0 08-05-2011 02:44 PM
Samba "mount error(11): Resource temporarily unavailable" RWallett Linux - Server 1 07-01-2010 01:00 PM
Cifs "mount error 11 = Resource temporarily unavailable" humbletech99 Linux - Networking 1 09-26-2006 12:04 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Hardware

All times are GMT -5. The time now is 04:38 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration