Bonjour, je débute a laravel, j'ai crée un model voici le code :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
 
<?php
 
namespace App;
 
use Illuminate\Database\Eloquent\Model;
use Response;
 
class RfidEncodage extends Model
{
    private static $socket;
 
    public function __construct( $host, $port) {
        static::$socket = socket_create(AF_INET, SOCK_STREAM, SOL_TCP);
 
        if (static::$socket === false)
            return "error";
        else {
                try{
                    $result = socket_connect(static::$socket, $host, $port);
                }catch (\Exception $e) {
                    return "==> <font color='red'>Connexion au Encodeur à échouer</font><br>".$e->getMessage()."";
                }
                if (Response::json($result) == true){
                    return "==>  <font color='green'>Connexion au Encodeur Réussie . . .</font>";
                }else{
                    return "==> <font color='red'>Connexion au Encodeur à échouer.</font>";
                }
            if ($result === false) {
                return "error " . socket_strerror(socket_last_error(static::$socket));
            } 
        }
    }
    public function read() {
 
        try{
            return socket_read(static::$socket, 1024);
        }catch (\Exception $e) {
            return "==> <font color='red'>une erreur s'est produite lors du lecture!</font><br>".$e->getMessage()."";
        }
    }
    public function send($data) {
 
        try{
        socket_write(static::$socket, $data, strlen($data.chr(0)));
        }catch (\Exception $e) {
            return "==> <font color='red'>une erreur s'est produite!</font><br>".$e->getMessage()."";
        }
    }
    public function close() {
 
        socket_close(static::$socket);
        return "==>  <font color='green'>Connexion au Encodeur Fermer . . .</font>";
    }
    public function strToHex($string)
    {
        $hex='';
        for ($i=0; $i <= 16; $i++)
        {
            if($i < strlen($string)){
            $hex .= dechex(ord($string[$i]));
            $hex .= ' ';
            }
            if($i > strlen($string)){
            $hex .= "ff ";
            }
 
        }
        return $hex;
    }
 
    public function hexToStr($hex)
    {
        $string='';
        for ($i=0; $i < strlen($hex)-1; $i+=2)
        {
            $string .= chr(hexdec($hex[$i].$hex[$i+1]));
        }
        return $string;
 
 
    }
 
}
dans mon controller j'ai fait comme ça:

Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
 
$rfid = new RfidEncodage("127.0.0.1",3306);
$rfid->send("<ENCODE>");
Le problème c'est que ça me retourne [ ] portant j'ai bien des message qui doive être afficher.
Merci