Advertisement
Guest User

AMP - not working

a guest
Nov 28th, 2018
216
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.94 KB | None | 0 0
  1. <?php
  2.  
  3. class Application
  4. {
  5.     public $socket;
  6.  
  7.     public function __construct()
  8.     {
  9.         return Amp\call(function () {
  10.             $this->socket = yield connect("tcp://192.168.4.2:8080");
  11.             return yield true;
  12.         });
  13.     }
  14.  
  15.     public function sendPrinterCommand($command)
  16.     {
  17.         return Amp\call(function () use ($command) {
  18.             yield $this->socket->write($command . "\r");
  19.             return yield $this->socket->read();
  20.         });
  21.     }
  22.  
  23.     public function run()
  24.     {
  25.         $result = yield $this->sendPrinterCommand('GJL'); // JBL|4|501|504|QR CODE 12mm|TESTE|
  26.         if (strpos($result, 'JBL') !== 0) {
  27.             die("\r\nGET JOB LIST: ERROR: {$result}\r\n");
  28.         }
  29.  
  30.         $jobs = array_filter(explode('|', trim($result)));
  31.         array_shift($jobs); // JBL
  32.         array_shift($jobs); // job count
  33.  
  34.         // does something with job list
  35.     }
  36. }
  37.  
  38. Loop::run(function () {
  39.     $app = yield new Application();
  40.     yield $app->run();
  41.     Loop::stop();
  42. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement