Click here to Skip to main content
14,934,103 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I want to sent STX ETX ASCCI Code to a printer using PHP.The manual refers 02h for STX and 03h for ETX .How van i send it

What I have tried:

<?php

$sock = socket_create(AF_INET, SOCK_STREAM, 0);
if(!($sock = socket_create(AF_INET, SOCK_STREAM, 0)))
{
	$errorcode = socket_last_error();
    $errormsg = socket_strerror($errorcode);
    
    die("Couldnt create socket: [$errorcode] $errormsg ");
}

echo "Socket created";
if(!socket_connect($sock , '192.168.100.002' , 3000))
{
	$errorcode = socket_last_error();
    $errormsg = socket_strerror($errorcode);
    
    die("Could not connect: [$errorcode] $errormsg");
}

echo "Connection established ";


$message1 = "\x02";
$message2 = "K ";

$message3 = "\x03" ;
$message=$message1.$message2.$message3;
$message1="Salam";



//Send the message to the server
if( ! socket_send ( $sock , $message , strlen($message) , 0))
{
	$errorcode = socket_last_error();
    $errormsg = socket_strerror($errorcode);
    
    die("Could not send data: [$errorcode] $errormsg ");
}

echo "Message send successfully ";

//Now receive reply from server
if(socket_recv ( $sock , $buf , 2045 , MSG_WAITALL ) === FALSE)
{
	$errorcode = socket_last_error();
    $errormsg = socket_strerror($errorcode);
    
    die("Could not receive data: [$errorcode] $errormsg ");
}

//print the received message
echo $buf;



?>
Posted

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900