Solved

USB parameters for ACM

Posted on 2001-09-02
3
559 Views
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) {
  getchar();
  retval = write(fd,"atz\r",4);
  if ( retval == -1 )
     ...
  sleep(1);
  retval = read(fd,respBuff,255);
  if ( retval == -1 )
     ...
  respBuff[retval] = '\0';
  printf("respBuff:%s\n",respBuff);
} /* while */

The response which should be (and is under windows):
ATZ
OK
<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:
AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAATZ
OK
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);
tcsetattr(m_fd,TCSANOW,&newtio);

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

Thanks,
          Gilad.



0
Comment
Question by:giligen
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 5

Accepted Solution

by:
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.
0
 
LVL 20

Expert Comment

by:jmcg
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.
PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER!

jmcg
EE Cleanup Volunteer
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Have you ever been frustrated by having to click seven times in order to retrieve a small bit of information from the web, always the same seven clicks, scrolling down and down until you reach your target? When you know the benefits of the command l…
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…
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…
Suggested Courses

752 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