LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Labview connect over sockets with php

Hello, i´ve a simply led.

 

I would control value of led over sockets using PHP programming language. My question is, where are documentation and examples? I found many examples between 2 or more Labview applications but not in PHP. I don´t found documentation that explins information to send to Labview application from PHP sockets...

 

It´s possible? 

 

Thanks!

0 Kudos
Message 1 of 15
(6,230 Views)
There is no native supprt in LabVIEW for the PHP protocol. You would have to use the native TCP VIs and implement the PHP protocol yourself. PHP uses HTTP as the underlying protocol and LabVIEWS HTTP implementation is primarily for use with the LabVIEW application acting as a web service. It is not really designed to drive an external web page. The HTTP VIs are part of the Internet Toolkit. I suggest you also take a look at those since they may help some.


Mark Yedinak
Certified LabVIEW Architect
LabVIEW Champion

"Does anyone know where the love of God goes when the waves turn the minutes to hours?"
Wreck of the Edmund Fitzgerald - Gordon Lightfoot
0 Kudos
Message 2 of 15
(6,222 Views)

Yes i know this. I would implement led management over sockets TCP because my version of Labview (8.5) don´t support WebServices, but i don´t found documentation for this.

 

You said that i have to implement protocol, i will investigate this.

 

Thanks.

 

 

Message Edited by PedroTeixeira1985 on 12-15-2009 03:39 AM
0 Kudos
Message 3 of 15
(6,209 Views)
The Internet Toolkit has had limited HTTP support since version 7.1 or possibly even earlier. I would take a look at that since it may help. Otherwise you would have to implement not only the PHP protocol but some subset of the HTTP protocol as well.


Mark Yedinak
Certified LabVIEW Architect
LabVIEW Champion

"Does anyone know where the love of God goes when the waves turn the minutes to hours?"
Wreck of the Edmund Fitzgerald - Gordon Lightfoot
0 Kudos
Message 4 of 15
(6,205 Views)

Hello, in this moment i did an example that read value of string labview from PHP.

 

Now, i need send data from php tolabview but i don´t could makethis... I´ve this schema on labview:

 

labview.png

 

In PHP i´ve this:

 

        $socket = socket_create(AF_INET, SOCK_STREAM, 0);
        socket_bind($socket, "127.0.0.1");
        socket_connect($socket, "127.0.0.1", 4005);
       
        $msg = "Test Message";
       
        $sock_data = socket_write($socket, $msg, strlen($msg));
   
        $res = "Data sended with response $sock_data.";

 

        echo $res;

 

 

Any idea?

 

Thanks.

0 Kudos
Message 5 of 15
(6,136 Views)

Hello, it work! I changed the number of bytes that TCP READ read. When string is equals "a", it set led to true:

 

lb_circuit.png

 

PHP Code:

         $socket = socket_create(AF_INET, SOCK_STREAM, SOL_TCP);
        socket_bind($socket, "127.0.0.1");
        socket_connect($socket, "127.0.0.1", 4005);
        
        if(strcmp($data,"")==0){
            $msg = "Default msg";
        } else {
            $msg = $data;
        }
        $size = strlen($msg);
        
        $sock_data = socket_write($socket, $msg, strlen($msg));
    
        $res = "Data sended ($size) with response $sock_data.";

 

 

But now, a get this error when TCP close:

 

lb_error.png

 

But i don´t understand because i´ve defined my IP in VI Server:Machine Access .

 

Any idea?

Message 6 of 15
(6,084 Views)

Has you found a solution to solve this error? I am very interested in your VI because I am doing something similar

 

Thanks

0 Kudos
Message 7 of 15
(5,875 Views)

Hello Islero, you need to do a VI as image of my last post and you can use the PHP code.

 

Just change lenght of the String received on VI, for example if you send a string with "a" change value 16 to 1.

0 Kudos
Message 8 of 15
(5,858 Views)
Great!! it works. Thanks
0 Kudos
Message 9 of 15
(5,837 Views)

Hey Pedro,

 

I'm using Apache, PHP 5.3 and LabVIEW 2009. I'm doing mostly the same thing you are and have it working, but then again you do too. Error 66 means the client closed the connection, which is what you want. So in your LabVIEW code, you can watch for error 66 and filter it out because it means everything worked well (the PHP script called socket_close or exited).

 

As a sidebar, does anyone have any good architectural ideas for a communication scheme between a webserver and LabVIEW? Right now I'm using session IDs and a socket communication protocol that goes something like this:

 

 

  1. PHP opens socket and sends session ID and command
  2. LabVIEW reads command and replies with either data or executes some functionality and returns the results
  3. PHP reads back reply and closes socket
  4. LabVIEW should end up with error 66 signifying PHP script called socket_close($socket);
But that would require lots of sockets being opened and closed, and I don't know how it will handle simultaneous connections gracefully. If anyone has an idea for better architecture, I'd love some suggestions. 

 

Thanks,

Mac

0 Kudos
Message 10 of 15
(5,549 Views)