Re: Using internal modem?
Re: Using internal modem?
- Subject: Re: Using internal modem?
- From: Ondra Cada <email@hidden>
- Date: Mon, 10 Sep 2001 20:13:01 +0200
Busman,
>
>>>>> Busman (B) wrote at Sun, 9 Sep 2001 20:11:12 -0400:
B> the general idea is make a program (cocoa) or script (shell maybe) to
B> say, ok, now the modem will answer the pone at x rings, then when
B> exit, say, ok the modem will not answer the phone now... my next step
B> is set modem as incoming/outcoming sound port but that is the second
B> step :) ... any idea or maybe some info will be thanks...
If the /dev/modem.tty device is supported properly (which I HAVE NOT checked
myself) you should be able to write commands to it and to read them from
there. You can use NSFileHandle for that, but unless there is some new API of
which I don't know, you'll have to use posix API anyway, at least to set the
line parameters. Therefore it might be reasonable to resort to posix API
completely, and wrap it in classes at upper level of your code.
Here are some relevant parts of public code, which communicates with modem
properly in NeXTStep; although it _should_ work in OSX too, no guarantee:
=== cut here ===
extern int modem;
void open_line(char *device)
{
struct sgttyb tdis;
modem=open(device,O_RDWR);
if( ioctl(modem,TIOCGETP,&tdis) == -1 ) log("Can't execute ioctl
TIOCGETP");
tdis.sg_ispeed=SPD;
tdis.sg_ospeed=SPD;
tdis.sg_flags=RAW|TANDEM;
if( ioctl(modem,TIOCSETP,&tdis) == -1 ) log("Can't execute ioctl
TIOCSETP");
}
// writes out a string to modem
#define say(b) write(modem,b,strlen(b));write(modem,"\r\n",2);
// waits for a string from modem
int wait_forx(char *s,long t,int fd) {
static char tst[100];
static struct itimerval alrm,oalrm;
int b=0,a=0,ok,flg=0,len,gcnt=0;
siginterrupt(SIGALRM,1);
alrm.it_interval.tv_sec=0;
alrm.it_interval.tv_usec=0;
alrm.it_value.tv_sec=t/1000;
alrm.it_value.tv_usec=(t00)*1000;
if(setitimer(ITIMER_REAL,&alrm,&oalrm)==-1) fatal("error creating timer");
flg=0;
len=strlen(s);
tst[len]=0;
ok=0;
do {
a=read(fd,tst+((++b)%len),1);
if(a==-1) {
flg=1;
} else {
gcnt++;
if(tst[b%len]==s[ok]) ok++;
else ok=0;
}
}
while(ok!=len && !flg);
alrm.it_value.tv_sec=0;
alrm.it_value.tv_usec=0;
if(setitimer(ITIMER_REAL,&alrm,&oalrm)==-1)
fatal("error removing timer");
return ok;
}
=== cut here ===
B> And by the way... with an application made in java or Objective, with
B> appkit, there a way to send commands like in the terminal? or maybe
B> execute a shell script?..
I guess you want to read NSTask.html.
---
Ondra Cada
OCSoftware: email@hidden
http://www.ocs.cz
private email@hidden
http://www.ocs.cz/oc