Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

USB parameters for ACM

Posted on 2001-09-02
3
Medium Priority
?
567 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
2 Comments
 
LVL 5

Accepted Solution

by:
bryanh earned 400 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

Ask an Anonymous Question!

Don't feel intimidated by what you don't know. Ask your question anonymously. It's easy! Learn more and upgrade.

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…
Please read the paragraph below before following the instructions in the video — there are important caveats in the paragraph that I did not mention in the video. If your PaperPort 12 or PaperPort 14 is failing to start, or crashing, or hanging, …
Loops Section Overview
Suggested Courses

782 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