Using com ports with PHP - Programmers Heaven

Howdy, Stranger!

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

Categories

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 - [email protected]

    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.