public static void Setup(string ip, int port) { Connection_TCP conn = null; try { byte[] bytes = new byte[sensorTypeCommand.Length + setStartOfPrintPosition.Length]; Buffer.BlockCopy(sensorTypeCommand, 0, bytes, 0, sensorTypeCommand.Length); Buffer.BlockCopy(setStartOfPrintPosition, 0, bytes, sensorTypeCommand.Length, setStartOfPrintPosition.Length); conn = Connection_TCP.CreateClient(ip, port); var ok = conn.Open(); conn.Write(bytes); conn.WaitForEmptyBuffer(5000); conn.Close(); Thread.Sleep(3000); } catch { // ignore } finally { if (conn != null) { conn.Close(); } } }
public static void Calibrate(string ip, int port) { Connection_TCP conn = Connection_TCP.CreateClient(ip, port); var ok = conn.Open(); conn.Write(quickMediaCalibration); }
public static bool Print(byte[] bytes, string ip, int port) { bool result = false; Connection_TCP conn = null; try { DocumentDPL docDPL = new DocumentDPL(); ParametersDPL paramDPL = new ParametersDPL(); docDPL.ColumnOffset = 65; docDPL.RowOffset = 0; MemoryStream ms = new MemoryStream(); ms.Write(bytes, 0, bytes.Length); Bitmap anImage = new Bitmap(ms); anImage.RotateFlip(RotateFlipType.Rotate90FlipX); docDPL.WriteImage(anImage, DocumentDPL.ImageType.Other, 0, 0, paramDPL); byte[] printData = docDPL.GetDocumentImageData(); conn = Connection_TCP.CreateClient(ip, port); conn.Open(); uint bytesWritten = 0; uint bytesToWrite = 1024; uint totalBytes = (uint)printData.Length; uint remainingBytes = totalBytes; while (bytesWritten < totalBytes) { if (remainingBytes < bytesToWrite) { bytesToWrite = remainingBytes; } conn.Write(printData, (int)bytesWritten, (int)bytesToWrite); bytesWritten += bytesToWrite; remainingBytes = remainingBytes - bytesToWrite; } conn.WaitForEmptyBuffer(5000); conn.Close(); Thread.Sleep(1000); result = true; } catch { // ignore } finally { if (conn != null) { conn.Close(); } } return(result); }