Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- class Application
- {
- public $socket;
- public function __construct()
- {
- return Amp\call(function () {
- $this->socket = yield connect("tcp://192.168.4.2:8080");
- return yield true;
- });
- }
- public function sendPrinterCommand($command)
- {
- return Amp\call(function () use ($command) {
- yield $this->socket->write($command . "\r");
- return yield $this->socket->read();
- });
- }
- public function run()
- {
- $result = yield $this->sendPrinterCommand('GJL'); // JBL|4|501|504|QR CODE 12mm|TESTE|
- if (strpos($result, 'JBL') !== 0) {
- die("\r\nGET JOB LIST: ERROR: {$result}\r\n");
- }
- $jobs = array_filter(explode('|', trim($result)));
- array_shift($jobs); // JBL
- array_shift($jobs); // job count
- // does something with job list
- }
- }
- Loop::run(function () {
- $app = yield new Application();
- yield $app->run();
- Loop::stop();
- });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement