USB parameters for ACM

Posted on 2001-09-02
Last Modified: 2011-04-14
Hello all,

I'm writing a little program which communicates with the modem using AT commands.
I'm using a proprietery USB modem (CDC - ACM).
Under windows(2000) everything works fine, but when I tried doing the same under linux things stopped working...
Here's the code:

int retval;
int fd = open("/dev/input/ttyACM0",  O_RDWR | O_NOCTTY);
if ( fd == -1 )
while( true) {
  retval = write(fd,"atz\r",4);
  if ( retval == -1 )
  retval = read(fd,respBuff,255);
  if ( retval == -1 )
  respBuff[retval] = '\0';
} /* while */

The response which should be (and is under windows):
<end of response>
Under linux sometimes there is no reponse (especially in the 1st time I'm sending the string) although I can see that the modem got the command and returned OK.
And usually I get weired responses like:
and sometime more then 100 A's!!!
The modem is perfectly fine (works perfect under windows).

I found out that if I add the following to my code (after the open) the problem is solved:

struct termios newtio;
bzero(&newtio, sizeof(newtio));
newtio.c_cflag = CRTSCTS | CS8 | CLOCAL | CREAD;
newtio.c_iflag = 0;
newtio.c_cc[VTIME]    = 0;
newtio.c_cc[VMIN]     = 1;
tcflush(m_fd, TCIFLUSH);

What was the original problem?
Still sometimes there are problems with the response, is there any better settings?
Any more tips on this issue?


Question by:giligen

Accepted Solution

bryanh earned 100 total points
ID: 6449237
Nothing jumps out at me, but TTYs are complicated, and I know what I'd do to try to reach an answer:  Since you have a working and non-working cases, just narrow the difference until you figure out the crucial variable.  Instead of just setting the tty attributes to the settings that work, use tcgettr(), then change some settings and leave some the same, then tcsetattr().

By the way, perhaps an easier way to experiment is to use the stty command.  Stty's job is to issue a tcsetattr (or tcgetattr).  You can set the settings before running your program.

The only annoying thing about stty is that, on every version I've seen, it does the settings on Standard Input, and you have to use the shell to open your modem as Standard Input, and the shell does a blocking open.  That means that if certain things are set wrong on the tty, you can't open it as Standard Input, so you can't change the setting!  I wrote a little program to open Standard Input nonblocking for just this reason, though I find it hard to believe someone didn't have another solution for it already.
LVL 20

Expert Comment

ID: 9916159
No comment has been added lately, so it's time to clean up this TA.
I will leave the following recommendation for this question in the Cleanup topic area:

Accept: bryanh {http:#6449237}

Please leave any comments here within the next seven days.

EE Cleanup Volunteer

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

The purpose of this article is to fix the unknown display problem in Linux Mint operating system. After installing the OS if you see Display monitor is not recognized then we can install "MESA" utilities to fix this problem or we can install additio…
The purpose of this article is to demonstrate how we can upgrade Python from version 2.7.6 to Python 2.7.10 on the Linux Mint operating system. I am using an Oracle Virtual Box where I have installed Linux Mint operating system version 17.2. Once yo…
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …
Established in 1997, Technology Architects has become one of the most reputable technology solutions companies in the country. TA have been providing businesses with cost effective state-of-the-art solutions and unparalleled service that is designed…

820 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question