Serial Port Communication

Serial Port Communication

Post by Ling Lin » Tue, 19 Dec 1995 04:00:00



Hi!
I am  quite new to the SUN Solaris environment and I am having some
problem writing a C++ program to read and write to the SUN SPARC20 serial
port (port a). Below is the "simple" test program that I used :

    main()
    { char buffer[80];
      int fd, n;
      if ((fd=open("/dev/cua/a","O_RDWR))<0)
         printf("\n Can't open port");
      ioctl(fd,I_FLUSH, FLUSHW);
      n=read(FD,buffer,sizeof(buffer));
      ioctl(fd,I_FLUSH,FLUSHW);
      write(fd,buffer,n);
      close(fd);
    }

The device that I want to communicated with is a PC-based device.

I am not getting any response. :(

Can some one help?

Many Thanks.

Ling

 
 
 

Serial Port Communication

Post by Grant D. Pea » Thu, 21 Dec 1995 04:00:00




Quote:>Hi!
>I am  quite new to the SUN Solaris environment and I am having some
>problem writing a C++ program to read and write to the SUN SPARC20 serial
>port (port a). Below is the "simple" test program that I used :

>    main()
>    { char buffer[80];
>      int fd, n;
>      if ((fd=open("/dev/cua/a","O_RDWR))<0)
>         printf("\n Can't open port");
>      ioctl(fd,I_FLUSH, FLUSHW);
>      n=read(FD,buffer,sizeof(buffer));
>      ioctl(fd,I_FLUSH,FLUSHW);
>      write(fd,buffer,n);
>      close(fd);
>    }

>The device that I want to communicated with is a PC-based device.

>I am not getting any response. :(

>Can some one help?

What about setting the correct baud rate for starters?

 
 
 

1. Linux serial port communication - Need help!!!!!!!!!

I am currently writing a program under Linux which needs to
communicate to
the serial port. All the program needs to do is send a string of 0's
and
1's. I'd like for these values to represent a low and a high when
being
outputted to the serial port, instead of the ascii integer value of
'0'
and  '1'. It appears that my simple program outputs the ascii integer
value of the string being passed out, but that is not what I want it
to
do. All I want it to do is pass out a high when it sees a 1, and a low
it sees
a 0.

I was hoping someone has had experience with this in the past and will
be willing to help me out on this.

My simple program is below:

#include <termios.h>
#include <stdio.h>
#include <unistd.h>
#include <fcntl.h>
#include <sys/signal.h>
#include <sys/types.h>

int main()
{
  int fd;

  // Open the port
  fd = open("/dev/ttyS0",  O_WRONLY);

  // Set the speed and other if req
  system("stty 2400 </dev/ttyS0");

  // There is a better way than this
  if(fd == -1)
  {
    perror("open");
    exit(1);
  }

  // Send a message
  if(write(fd, "0", 10) == 10)
  {
    perror("write");
    exit(1);
  }

  close(fd);

Any help would be appreciated. Thank you.

2. Time inside Kernel

3. Linux serial port communication

4. Linux BSOD?

5. Serial port communication - Need help!!!

6. Blowfish for linux

7. Simple Serial Port Communications?

8. port forwarding 2 subdomains & 2 different IPs

9. Help with Serial port Communications on DSR/DTR lines

10. Newbie Q: Serial port communication with 'cu'

11. Serial port communication - Need help!!!

12. serial port communication