Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

Welcome to the new platform of Programmer's Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use its exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.

Using com ports with PHP

mehmetycmehmetyc Posts: 1Member
is there a way to use com ports with php scripts? I really have to reach to a mobile phone. does it needs a special library?

Comments

  • weapon__xweapon__x Posts: 138Member
    : is there a way to use com ports with php scripts? I really have to reach to a mobile phone. does it needs a special library?
    :
    :

    im no php expert myself but you might try to code it in c/c++ then just call the executable via php. i think u can use sytem("file.exe"), if i still remember it right.

  • fnoyanfnoyan Posts: 103Member
    is there a way to use com ports with php scripts? I really have to reach to a mobile phone. does it needs a special library?
    :
    :

    Hi

    to write data to COM port simply open the port by fopen and r/w your data.

    $fd = fopen ("COM1:", "r+");
    for details : http://www.php.net/manual/tr/function.fopen.php

    and another way is to write your own program. Here is a C program
    compile and use it. The code does not belong to me.
    The writer of code is Hidayet Dogan - hdogan@pleksus.com.tr

    int open_serial(char *dev, speed_t speed) {
    struct termios new_tio;
    int fd;

    if ((fd = open(dev, O_RDWR | O_NONBLOCK)) < 0) {
    perror("open() failed");
    exit(1);
    }

    if (tcgetattr(fd, &new_tio)) {
    perror("tcgetattr() failed");
    close(fd);
    exit(1);
    }

    cfmakeraw(&new_tio);
    new_tio.c_iflag = IGNBRK | IGNPAR;
    new_tio.c_cflag |= CLOCAL;
    cfsetospeed(&new_tio, speed);
    cfsetispeed(&new_tio, speed);
    tcsetattr(fd, TCSANOW, &new_tio);
    return fd;
    }

    taken from php.org.tr forum


Sign In or Register to comment.