से बाइनरी कमांड भेजना मुझे Arduino (Uno rev 3) और थर्मल प्रिंटर (यह मॉडल) के साथ खेलने में कुछ मज़ा आता है। Arduino मेरी स्थानीय मशीन (एक ईथरनेट शील्ड के माध्यम से) में हर 10 सेकंड का अनुरोध करता है और एसडी कार्ड पर प्रतिक्रिया (यदि 200) स्टोर करता है। इसके बाद यह इस पुस्तकालय https://github.com/adafruit/Adafruit-Thermal-Printer-Library का उपयोग करके इसे प्रिंट करता है।PHP से Arduino संचालित थर्मल प्रिंटर
अब तक मैंने इसे मूल पाठ को सही तरीके से मतदान, भंडारण और प्रिंटिंग किया है, लेकिन अब मैं कुछ अधिक उन्नत आदेशों (अंडरलाइन, उलटा इत्यादि) का उपयोग करने की कोशिश कर रहा हूं। मेरा अंतिम लक्ष्य छवियों को नीचे भेजना और सर्वर ala http://printer.gofreerange.com/ पर सभी प्रतिपादन को संभालना है।
समस्या यह है कि मैं जो आदेश भेज रहा हूं उसे पाठ वर्णों के रूप में आउटपुट किया गया है। कुछ आदेश काम करते हैं (लाइन फीड), लेकिन दूसरों को खराब कर दिया जाता है। मैंने Arduino कोड और मूल PHP स्क्रिप्ट दोनों को कॉल किया है जो इसे कॉल कर रहा है। कोई मदद?
Arduino:
#include <SPI.h>
#include <Ethernet.h>
#include <SD.h>
#include <SoftwareSerial.h>
#include "Adafruit_Thermal.h"
byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
const char host[] = "192.168.1.100";
char cacheFilename[] = "TMP";
const byte printer_RX_Pin = 8; // this is the green wire
const byte printer_TX_Pin = 9; // this is the yellow wire
const byte SD_Pin = 4; // the SD Card SPI pin
bool downloadWaiting = false;
bool statusOk = false;
unsigned long content_length = 0;
EthernetClient client;
Adafruit_Thermal printer(printer_RX_Pin, printer_TX_Pin);
void die(unsigned int times) {
while(true);
}
void checkForDownload() {
Serial.println("checkForDownload");
content_length = 0;
statusOk = false;
unsigned long length = 0;
if (SD.exists(cacheFilename)) {
if (!SD.remove(cacheFilename)) {
die(4);
}
}
File cache = SD.open(cacheFilename, FILE_WRITE);
if(client.connect(host, 80)) {
client.println("GET /printer.php HTTP/1.1");
client.print("Host: "); client.println(host);
client.println("User-Agent: arduino-ethernet");
client.println("Connection: close");
client.println();
bool parsingHeader = true;
while(client.connected()) {
while(client.available()) {
if (parsingHeader) {
client.find((char*)"HTTP/1.1 ");
char statusCode[] = "000";
client.readBytes(statusCode, 3);
statusOk = (strcmp(statusCode, "200") == 0);
client.find((char*)"Content-Length: ");
char c;
while (isdigit(c = client.read())) {
content_length = (content_length * 10) + (c - '0');
}
client.find((char*)"\n\r\n");
parsingHeader = false;
} else {
if(length < content_length) {
cache.write((byte)client.read());
length++;
} else {
client.read();
}
}
}
}
client.stop();
cache.seek(0);
if (statusOk && content_length > 0 && (content_length == length) && (content_length == cache.size())) {
downloadWaiting = true;
}
} else {
client.stop();
}
cache.close();
}
void printFromDownload() {
Serial.println("printFromDownload");
File cache = SD.open(cacheFilename);
byte b;
while (content_length--) {
printer.write((byte)cache.read());
}
printer.feed();
cache.close();
downloadWaiting = false;
}
void setup(){
pinMode(SD_Pin, OUTPUT);
if (!SD.begin(SD_Pin)) {
die(2);
}
if (Ethernet.begin(mac) == 0) {
die(3);
}
Serial.begin(9600);
printer.begin(255);
delay(1000);
}
void loop() {
if (downloadWaiting) {
printFromDownload();
delay(5000);
} else {
checkForDownload();
if (!downloadWaiting) {
delay(10000);
}
}
}
पीएचपी:
<?php
ob_start();
// Turn on Inverse mode
// Doesn't work
echo pack('S', 29);
echo pack('S', 66);
echo pack('S', 1);
$string = 'Testing 1, 2, 3';
foreach(str_split($string) as $char) {
echo pack('S', ord($char)); // works
}
// Turn off Inverse mode
echo pack('S', 29);
echo pack('S', 66);
echo pack('S', 0);
// Line feed
echo pack('S', 10); // works
$content = ob_get_clean();
$length = strlen($content);
header("Content-Length: $length");
echo $content;
प्रिंटर दूषित होने वाले PHP को कौन सा डेटा भेज रहा है? – chugadie