C and C++

Moderators: None (Apply to moderate this forum)
Number of threads: 28629
Number of posts: 94611

This Forum Only
Post New Thread
Single Post View       Linear View       Threaded View      f

Report
I/O in com port Posted by suki_yip on 25 Feb 2004 at 3:28 AM
I am using Linux and writing C program, and I want to know how to output from com port with the string, say "atdt123456".

I am using this program, but it doesn't work

#include <stdio.h>
#include <sys/ioctl.h>
#include <sys/stat.h>
#include <fcntl.h>

int main(void) {

FILE *fd;
char msg[19]={'a','t','d','t',' ','1','2','3','4','5','6','\r','\n'};

fd=fopen("/dev/ttyS1", "w");

if (fd<0) {
print ("Error: Couldn't open serial port\n");
return 1;
}

fputs(msg,fd);

close(fd);
}

Report
Re: I/O in com port Posted by macpherson on 25 Feb 2004 at 12:29 PM
: I am using Linux and writing C program, and I want to know how to output from com port with the string, say "atdt123456".
:
: I am using this program, but it doesn't work
:
: #include <stdio.h>
: #include <sys/ioctl.h>
: #include <sys/stat.h>
: #include <fcntl.h>
:
: int main(void) {
:
: FILE *fd;
: char msg[19]={'a','t','d','t',' ','1','2','3','4','5','6','\r','\n'};
: msg[13] = 0;

: fd=fopen("/dev/ttyS1", "w");
:
: if (fd<0) {
: print ("Error: Couldn't open serial port\n");
: return 1;
: }
:
: fputs(msg,fd);
:
: close(fd);
: }
:
:

Report
it doesn't work also Posted by suki_yip on 25 Feb 2004 at 6:29 PM
After I added that command, it doesn't work also
Report
Re: it doesn't work also Posted by dwccgc on 25 Feb 2004 at 7:05 PM
Maybe this site can help you.

http://www.comptechdoc.org/os/linux/programming/c/linux_pgcserial.html



: After I added that command, it doesn't work also
:

Report
Can you suggest any program Posted by suki_yip on 25 Feb 2004 at 8:00 PM
As it is very urgent for me
what i want is dial a number by using modem throught C program
my modem device is /dev/ttyS1
and the AT command is "ATDT123456"

thanks very much
Report
Re: it doesn't work also Posted by suki_yip on 27 Feb 2004 at 2:31 AM
The website is not compilable.


: Maybe this site can help you.
:
: http://www.comptechdoc.org/os/linux/programming/c/linux_pgcserial.html
:
:
:
: : After I added that command, it doesn't work also
: :
:
:

Report
Re: I/O in com port Posted by gustavosserra on 25 Feb 2004 at 9:26 PM
Uhm... I do not know, but try this. It is your code with some modifications.
include <stdio.h>
#include <sys/ioctl.h>
#include <sys/stat.h>
#include <fcntl.h>
         
int main(void) {
  FILE *fd;
  char msg[30] = "atdt 123456\r\n";
  fd=fopen("/dev/ttyS1", "r+");
  if(fd == NULL){
    printf("Error: Couldn't open serial port\n");
    return 1;
  }         
  fputs(msg,fd);
  close(fd);
  return 0;
}


Hope that works!
: I am using Linux and writing C program, and I want to know how to output from com port with the string, say "atdt123456".
:
: I am using this program, but it doesn't work
:
: #include <stdio.h>
: #include <sys/ioctl.h>
: #include <sys/stat.h>
: #include <fcntl.h>
:
: int main(void) {
:
: FILE *fd;
: char msg[19]={'a','t','d','t',' ','1','2','3','4','5','6','\r','\n'};
:
: fd=fopen("/dev/ttyS1", "w");
:
: if (fd<0) {
: print ("Error: Couldn't open serial port\n");
: return 1;
: }
:
: fputs(msg,fd);
:
: close(fd);
: }
:
:

Report
I cannot work also Posted by suki_yip on 26 Feb 2004 at 12:50 AM
Really thanks for you help
but it does not work also although it is compilable.

As it is very urgent, pls help me or arise any suggestion freely.

: Uhm... I do not know, but try this. It is your code with some modifications.
:
: include <stdio.h>
: #include <sys/ioctl.h>
: #include <sys/stat.h>
: #include <fcntl.h>
:          
: int main(void) {
:   FILE *fd;
:   char msg[30] = "atdt 123456\r\n";
:   fd=fopen("/dev/ttyS1", "r+");
:   if(fd == NULL){
:     printf("Error: Couldn't open serial port\n");
:     return 1;
:   }         
:   fputs(msg,fd);
:   close(fd);
:   return 0;
: }

:
: Hope that works!
: : I am using Linux and writing C program, and I want to know how to output from com port with the string, say "atdt123456".
: :
: : I am using this program, but it doesn't work
: :
: : #include <stdio.h>
: : #include <sys/ioctl.h>
: : #include <sys/stat.h>
: : #include <fcntl.h>
: :
: : int main(void) {
: :
: : FILE *fd;
: : char msg[19]={'a','t','d','t',' ','1','2','3','4','5','6','\r','\n'};
: :
: : fd=fopen("/dev/ttyS1", "w");
: :
: : if (fd<0) {
: : print ("Error: Couldn't open serial port\n");
: : return 1;
: : }
: :
: : fputs(msg,fd);
: :
: : close(fd);
: : }
: :
: :
:
:

Report
It is urgent Posted by suki_yip on 26 Feb 2004 at 8:33 PM
Pls help me as i have to finish it very soon
Report
Re: I/O in com port Posted by interrupthandl on 27 Feb 2004 at 3:57 AM
why dont u use interrupts services for COM I/O

: I am using Linux and writing C program, and I want to know how to output from com port with the string, say "atdt123456".
:
: I am using this program, but it doesn't work
:
: #include <stdio.h>
: #include <sys/ioctl.h>
: #include <sys/stat.h>
: #include <fcntl.h>
:
: int main(void) {
:
: FILE *fd;
: char msg[19]={'a','t','d','t',' ','1','2','3','4','5','6','\r','\n'};
:
: fd=fopen("/dev/ttyS1", "w");
:
: if (fd<0) {
: print ("Error: Couldn't open serial port\n");
: return 1;
: }
:
: fputs(msg,fd);
:
: close(fd);
: }
:
:

Report
What is interrupt service for com i/o Posted by suki_yip on 28 Feb 2004 at 11:18 PM
do you have sample or suggest??????

Report
Re: What is interrupt service for com i/o Posted by interrupthandl on 29 Feb 2004 at 4:21 AM
This message was edited by interrupthandl at 2004-2-29 4:55:36

:see Ray Duncan's "interrupt manual".
Bioscom() is the common fucntion used in dos.look for equivalent compiler func.



Report
Re: What is interrupt service for com i/o Posted by suki_yip on 29 Feb 2004 at 5:05 AM
Although i have include the library of <bios.h>
but when i compile it, it say bioscom is an undefined varaible
why it is happened??
Report
Re: What is interrupt service for com i/o Posted by interrupthandl on 29 Feb 2004 at 10:57 AM
This message was edited by interrupthandl at 2004-2-29 10:59:34

perhaps ur linux version is not supporting Bios.h.Make ur own function
using Comm. interrupts from Ray dunc... search the web u will get entire collection.Also check ur syntax with ur compilers syntax.



: Although i have include the library of <bios.h>
: but when i compile it, it say bioscom is an undefined varaible
: why it is happened??
:



Report
Re: What is interrupt service for com i/o Posted by suki_yip on 29 Feb 2004 at 7:41 PM
Although it is demanding, i really need the program now. As i cannot seach that website from internet, would you mind to write a simple program for me.

ps:I have try <bios.h> and <canio.h>, but it seems that my version of linux is not support these two. Thanks
Report
Re: What is interrupt service for com i/o Posted by stober on 29 Feb 2004 at 7:51 PM
This message was edited by stober at 2004-2-29 19:52:4

I don't think any version of unix or linux supports bios.h. That is an old MS-DOS header file. I just searched my linux computer and that file is not on it.

: perhaps ur linux version is not supporting Bios.h.Make ur own function
: using Comm. interrupts from Ray dunc... search the web u will get entire collection.Also check ur syntax with ur compilers syntax.
:
:
:
: : Although i have include the library of <bios.h>
: : but when i compile it, it say bioscom is an undefined varaible
: : why it is happened??
: :
:
:



Report
Re: What is interrupt service for com i/o Posted by interrupthandl on 29 Feb 2004 at 10:01 PM
This message was edited by interrupthandl at 2004-2-29 22:8:25

i meant perhaps there is some problem in path of the file or other which suki_yip is not able to diagnose.Please dont take it literally.my language command is a bit weak.then its better to write ur own method.

Regards


: This message was edited by stober at 2004-2-29 19:52:4

: I don't think any version of unix or linux supports bios.h. That is an old MS-DOS header file. I just searched my linux computer and that file is not on it.
:
: : perhaps ur linux version is not supporting Bios.h.Make ur own function
: : using Comm. interrupts from Ray dunc... search the web u will get entire collection.Also check ur syntax with ur compilers syntax.
: :
: :
: :
: : : Although i have include the library of <bios.h>
: : : but when i compile it, it say bioscom is an undefined varaible
: : : why it is happened??
: : :
: :
: :
:
:
:
:



Report
Re: What is interrupt service for com i/o Posted by suki_yip on 29 Feb 2004 at 11:44 PM
in fact, when i search my computer, there is a >bios.h> there, then i include the path also, but the bioscom() is undefinited veriable
Report
Re: What is interrupt service for com i/o Posted by brtklt on 1 Mar 2004 at 12:41 AM
: in fact, when i search my computer, there is a >bios.h> there, then i include the path also, but the bioscom() is undefinited veriable
:
I found bios.h as well but it was in my kernel source directory. I think it's a kernel header file, and not part of gcc. I looked at the file and the only thing it contained was a single line:

#define CONFIG_PCI_BIOS 1
Report
Re: What is interrupt service for com i/o Posted by interrupthandl on 1 Mar 2004 at 4:15 AM
here is actual source , but i dont know whether this will work on linux or not.it should.


/* bios.h

Access to bios services.

Copyright (c) 1987, 1991 by Borland International
All Rights Reserved.
*/

#if !defined(__BIOS_H)
#define __BIOS_H

#if !defined(__DEFS_H)
#include <_defs.h>
#endif

/* diskinfo_t structure for _bios_disk() */

struct diskinfo_t {
unsigned drive, head, track, sector, nsectors;
void far *buffer;
};

/* cmd values for _bios_disk() */

#define _DISK_RESET 0 /* controller hard reset */
#define _DISK_STATUS 1 /* status of last operation */
#define _DISK_READ 2 /* read sectors */
#define _DISK_WRITE 3 /* write sectors */
#define _DISK_VERIFY 4 /* verify sectors */
#define _DISK_FORMAT 5 /* format track */

/* cmd values for _bios_keybrd() */

#define _KEYBRD_READ 0 /* read key */
#define _NKEYBRD_READ 0x10 /* read key - enhanced */
#define _KEYBRD_READY 1 /* check key ready */
#define _NKEYBRD_READY 0x11 /* check key ready - enhanced */
#define _KEYBRD_SHIFTSTATUS 2 /* get shift status */
#define _NKEYBRD_SHIFTSTATUS 0x12 /* get shift status - enhanced */

/* cmd values for _bios_printer() */

#define _PRINTER_WRITE 0 /* send a byte to printer */
#define _PRINTER_INIT 1 /* initialize printer */
#define _PRINTER_STATUS 2 /* read printer status */

/* cmd values for _bios_serialcom() */

#define _COM_INIT 0 /* set communication parms to a byte */
#define _COM_SEND 1 /* send a byte to port */
#define _COM_RECEIVE 2 /* read character from port */
#define _COM_STATUS 3 /* get status of port */

/* byte values for _COM_INIT cmd of _bios_serialcom() */

#define _COM_CHR7 0x02 /* 7 data bits */
#define _COM_CHR8 0x03 /* 8 data bits */
#define _COM_STOP1 0x00 /* 1 stop bit */
#define _COM_STOP2 0x04 /* 2 stop bits */
#define _COM_NOPARITY 0x00 /* no parity */
#define _COM_EVENPARITY 0x18 /* even parity */
#define _COM_ODDPARITY 0x08 /* odd parity */
#define _COM_110 0x00 /* 110 baud */
#define _COM_150 0x20 /* 150 baud */
#define _COM_300 0x40 /* 300 baud */
#define _COM_600 0x60 /* 600 baud */
#define _COM_1200 0x80 /* 1200 baud */
#define _COM_2400 0xa0 /* 2400 baud */
#define _COM_4800 0xc0 /* 4800 baud */
#define _COM_9600 0xe0 /* 9600 baud */

/* cmd values for _bios_timeofday() */

#define _TIME_GETCLOCK 0 /* get clock count */
#define _TIME_SETCLOCK 1 /* set clock count */

/* register structure definitions for int86(), int86x() */

#ifndef _REG_DEFS
#define _REG_DEFS

struct WORDREGS {
unsigned int ax, bx, cx, dx, si, di, cflag, flags;
};

struct BYTEREGS {
unsigned char al, ah, bl, bh, cl, ch, dl, dh;
};

union REGS {
struct WORDREGS x;
struct BYTEREGS h;
};

struct SREGS {
unsigned int es;
unsigned int cs;
unsigned int ss;
unsigned int ds;
};

struct REGPACK {
unsigned r_ax, r_bx, r_cx, r_dx;
unsigned r_bp, r_si, r_di, r_ds, r_es, r_flags;
};

#endif /* _REG_DEFS */

#ifdef __cplusplus
extern "C" {
#endif

/* New MSC-compatible BIOS functions.
*/
unsigned _Cdecl _bios_equiplist(void);
unsigned _Cdecl _bios_disk(unsigned __cmd, struct diskinfo_t *__dinfo);
unsigned _Cdecl _bios_keybrd(unsigned __cmd);
unsigned _Cdecl _bios_memsize(void);
unsigned _Cdecl _bios_printer(unsigned __cmd, unsigned __port, unsigned __abyte);
unsigned _Cdecl _bios_serialcom(unsigned __cmd, unsigned __port, unsigned __abyte);
unsigned _Cdecl _bios_timeofday(unsigned __cmd, long *__timeval);

/* Old-style BIOS functions.
*/
int _Cdecl bioscom(int __cmd, char __abyte, int __port);
int _Cdecl biosdisk(int __cmd, int __drive, int __head, int __track,
int __sector, int __nsects, void *__buffer);
int _Cdecl biosequip(void);
int _Cdecl bioskey(int __cmd);
int _Cdecl biosmemory(void);
int _Cdecl biosprint(int __cmd, int __abyte, int __port);
long _Cdecl biostime(int __cmd, long __newtime);

/* Miscellaneous prototypes for MSC compatibility
*/
int _Cdecl int86(int __intno, union REGS *__inregs, union REGS *__outregs);
int _Cdecl int86x(int __intno, union REGS *__inregs,
union REGS *__outregs, struct SREGS *__segregs);
#ifdef __cplusplus
}
#endif

#endif /* __BIOS_H */
Report
Re: What is interrupt service for com i/o Posted by suki_yip on 1 Mar 2004 at 6:26 AM
i want to ask how biocom() can help me, as i see it is just use to initialise the serial port and config it, such as the baud rate or whether parity bit used or not.............

I am using linux with C language
In fact, i want to open by port /dev/ttyS1
for this part, i think i can do this by fopen() or open(), i am sure that i open for the right port.

the next thing i want to do i send a AT command, such as ATDT123455, where 123456 is telephone number. However, it doesn't work. Is there any suggestions???
Report
Re: What is interrupt service for com i/o Posted by stober on 1 Mar 2004 at 12:31 PM
The functions in that file are usless in unix/linux. Those are for MS-DOS. When in Rome do as the Romans do -- do it the unix way. I don't recall how its done (its been over 10 years since I worked on unix) but the ports are set using ioctl (or something like that) calls. You'll have to look in the man pages, look them up in a unix programming book, or maybe a google search will help.
Report
Re: I/O in com port Posted by interrupthandl on 1 Mar 2004 at 11:05 AM
This message was edited by interrupthandl at 2004-3-1 11:14:6

This message was edited by interrupthandl at 2004-3-1 11:13:10

frankly suki i have never worked in linux but , i have now understood ur problem.

on dos we do like this

ofstream _outputFile;// outstream object file

_outputFile.open(" COM1"); // NAMING CONVENTION IS
// COM1 or AUX for first serial port
// COM2 ''''''''''' second'''''''''

_outputFile.put(ch_to_be_written);


// USing STANDARD OUT PUT FUNCTION

hope this solves ur problem


Report
Re: I/O in com port Posted by tom_sw on 1 Mar 2004 at 11:49 AM
I would suggest double checking that device address ("/dev/ttyS1"). I dealt with a similar problem several years ago, and the answer was that I had to use a different device - even though the documentation seemed to indicate ttyS1. I cannot remember the details (such as the device address that actually worked ), but hopefully that may help.
There should be a command to get a status from the comm port or modem. Try sending that to various device ports until you get a response, then use that device.

: I am using Linux and writing C program, and I want to know how to output from com port with the string, say "atdt123456".
:
: I am using this program, but it doesn't work
:
: #include <stdio.h>
: #include <sys/ioctl.h>
: #include <sys/stat.h>
: #include <fcntl.h>
:
: int main(void) {
:
: FILE *fd;
: char msg[19]={'a','t','d','t',' ','1','2','3','4','5','6','\r','\n'};
:
: fd=fopen("/dev/ttyS1", "w");
:
: if (fd<0) {
: print ("Error: Couldn't open serial port\n");
: return 1;
: }
:
: fputs(msg,fd);
:
: close(fd);
: }
:
:

Report
Re: I/O in com port Posted by dwccgc on 1 Mar 2004 at 3:32 PM
Do you have permission to access the port?

Check out this article
http://www.tldp.org/HOWTO/IO-Port-Programming-2.html#ss2.2

At the bottom of this page there is a programming example.
http://www.tldp.org/HOWTO/IO-Port-Programming.html



: I am using Linux and writing C program, and I want to know how to output from com port with the string, say "atdt123456".
:
: I am using this program, but it doesn't work
:
: #include <stdio.h>
: #include <sys/ioctl.h>
: #include <sys/stat.h>
: #include <fcntl.h>
:
: int main(void) {
:
: FILE *fd;
: char msg[19]={'a','t','d','t',' ','1','2','3','4','5','6','\r','\n'};
:
: fd=fopen("/dev/ttyS1", "w");
:
: if (fd<0) {
: print ("Error: Couldn't open serial port\n");
: return 1;
: }
:
: fputs(msg,fd);
:
: close(fd);
: }
:
:

Report
Re: I/O in com port Posted by brtklt on 1 Mar 2004 at 6:19 PM
I just tried to post a message that contained source code to a wardialer that works specifically for linux. I spent a few minutes looking at the code and it's pretty simple to open and initialize a modem. Unfornuately the source was too long to post on here. If you'd like to view the source you can leave your email and I'll send you the package.
Report
Re: I/O in com port Posted by suki_yip on 1 Mar 2004 at 7:30 PM
Really thanks for your help and support
my e-mail address is suki_yip@hotmail.com



: I just tried to post a message that contained source code to a wardialer that works specifically for linux. I spent a few minutes looking at the code and it's pretty simple to open and initialize a modem. Unfornuately the source was too long to post on here. If you'd like to view the source you can leave your email and I'll send you the package.
:

Report
Thanks for your support and help Posted by suki_yip on 2 Mar 2004 at 7:27 PM
really thanks for your support,
in fact, my supervisors are not good, and they do not give any advice to me. and for me, i am just a beginner of C language user. Really thanks for your help.

Now i need to do another part first, but i will test that program in the future. But in fact, for the shokdial, i have download the 2nd version at the begining, but it doesn't work, and i don't know whether the 4th version works or not.

Really thanks for your continuous help:)
Report
Re: Thanks for your support and help Posted by brtklt on 3 Mar 2004 at 5:25 AM
Read my previous post. If you look at the defines in the file shockdial.c it has the com port as cua0. You probably need to change the define accordingly as suggested in the comments in that file near the beginning. You might also want to download the source to the chat program that's for your linux distribution.
1 2  Next



 

Recent Jobs

Official Programmer's Heaven Blogs
Web Hosting | Browser and Social Games | Gadgets

Popular resources on Programmersheaven.com
Assembly | Basic | C | C# | C++ | Delphi | Flash | Java | JavaScript | Pascal | Perl | PHP | Python | Ruby | Visual Basic
© Copyright 2011 Programmersheaven.com - All rights reserved.
Reproduction in whole or in part, in any form or medium without express written permission is prohibited.
Violators of this policy may be subject to legal action. Please read our Terms Of Use and Privacy Statement for more information.
Operated by CommunityHeaven, a BootstrapLabs company.