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

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

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

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…
This Micro Tutorial demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

772 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