Solved

USB parameters for ACM

Posted on 2001-09-02
3
546 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
3 Comments
 
LVL 5

Accepted Solution

by:
bryanh earned 100 total points
Comment Utility
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
Comment Utility
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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

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…
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
This tutorial demonstrates a quick way of adding group price to multiple Magento products.

771 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now