Skip to content
This repository has been archived by the owner on Aug 23, 2021. It is now read-only.

Commit

Permalink
Merge branch 'release/v1.1.3'
Browse files Browse the repository at this point in the history
  • Loading branch information
karronoli committed Jan 24, 2018
2 parents 9d74645 + 34aa527 commit 5c8003f
Show file tree
Hide file tree
Showing 9 changed files with 295 additions and 227 deletions.
4 changes: 2 additions & 2 deletions TinySato/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,5 +31,5 @@
//
// すべての値を指定するか、下のように '*' を使ってビルドおよびリビジョン番号を
// 既定値にすることができます:
[assembly: AssemblyVersion("1.1.2.*")]
[assembly: AssemblyFileVersion("1.1.2")]
[assembly: AssemblyVersion("1.1.3.*")]
[assembly: AssemblyFileVersion("1.1.3")]
42 changes: 22 additions & 20 deletions TinySato/TinySato.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,11 @@ public class Printer : IDisposable
{
private bool disposed = false;
protected bool send_at_dispose_if_not_yet_sent = false;
protected int operation_start_index = 0;
protected int operation_start_index = 1;
protected IntPtr printer = IntPtr.Zero;
protected List<byte[]> operations = new List<byte[]> { };
protected List<byte[]> operations = new List<byte[]> {
new byte[] { Convert.ToByte(STX) }
};
protected int soft_offset_x = 0;
protected int soft_offset_y = 0;

Expand Down Expand Up @@ -77,29 +79,29 @@ public void SetGapSizeBetweenLabels(int y)
{
if (!(0 <= y && y <= 64))
throw new TinySatoException("Specify 0-64 dots.");
Insert(0, OPERATION_A);
Insert(1, ESC + string.Format("TG{0:D2}", y));
Insert(2, OPERATION_Z);
Insert(operation_start_index + 0, OPERATION_A);
Insert(operation_start_index + 1, ESC + string.Format("TG{0:D2}", y));
Insert(operation_start_index + 2, OPERATION_Z);
operation_start_index += 3;
}

public void SetDensity(int density, DensitySpec spec)
{
if (!(1 <= density && density <= 5))
throw new TinySatoException("Specify 1-5 density");
Insert(0, OPERATION_A);
Insert(1, ESC + string.Format("#E{0:D1}{1}", density, spec.ToString("F")));
Insert(2, OPERATION_Z);
Insert(operation_start_index + 0, OPERATION_A);
Insert(operation_start_index + 1, ESC + string.Format("#E{0:D1}{1}", density, spec.ToString("F")));
Insert(operation_start_index + 2, OPERATION_Z);
operation_start_index += 3;
}

public void SetSpeed(int speed)
{
if (!(1 <= speed && speed <= 5))
throw new TinySatoException("Specify 1-5 speed");
Insert(0, OPERATION_A);
Insert(1, ESC + string.Format("CS{0:D2}", speed));
Insert(2, OPERATION_Z);
Insert(operation_start_index + 0, OPERATION_A);
Insert(operation_start_index + 1, ESC + string.Format("CS{0:D2}", speed));
Insert(operation_start_index + 2, OPERATION_Z);
operation_start_index += 3;
}

Expand Down Expand Up @@ -128,9 +130,9 @@ public void SetPaperSize(int height, int width)
throw new TinySatoException("Specify 1-9999 dots for height.");
if (!(1 <= width && width <= 9999))
throw new TinySatoException("Specify 1-9999 dots for width.");
Insert(0, OPERATION_A);
Insert(1, ESC + string.Format("A1{0:D4}{1:D4}", height, width));
Insert(2, OPERATION_Z);
Insert(operation_start_index + 0, OPERATION_A);
Insert(operation_start_index + 1, ESC + string.Format("A1{0:D4}{1:D4}", height, width));
Insert(operation_start_index + 2, OPERATION_Z);
operation_start_index += 3;
}

Expand All @@ -149,9 +151,9 @@ public void SetPageNumber(uint number_of_pages)

public void SetSensorType(SensorType type)
{
Insert(0, OPERATION_A);
Insert(1, ESC + string.Format("IG{0:D1}", (int)type));
Insert(2, OPERATION_Z);
Insert(operation_start_index + 0, OPERATION_A);
Insert(operation_start_index + 1, ESC + string.Format("IG{0:D1}", (int)type));
Insert(operation_start_index + 2, OPERATION_Z);
operation_start_index += 3;
}

Expand Down Expand Up @@ -196,8 +198,8 @@ public int AddStream()
throw new Win32Exception(Marshal.GetLastWin32Error());
if (!Win32.EndPagePrinter(printer))
throw new Win32Exception(Marshal.GetLastWin32Error());
operation_start_index = 0;
this.operations.Clear();
operation_start_index = 0;
}
catch (Win32Exception inner)
{
Expand All @@ -217,7 +219,6 @@ public int Send()
{
operations.Insert(operation_start_index,
Encoding.ASCII.GetBytes(OPERATION_A));
operations[0] = (new byte[] { Convert.ToByte(STX) }).Concat(operations[0]).ToArray();
operations.Add(Encoding.ASCII.GetBytes(OPERATION_Z + ETX));

var flatten = operations.SelectMany(x => x).ToArray();
Expand All @@ -232,8 +233,9 @@ public int Send()
throw new Win32Exception(Marshal.GetLastWin32Error());
if (!Win32.EndPagePrinter(printer))
throw new Win32Exception(Marshal.GetLastWin32Error());
operation_start_index = 0;
this.operations.Clear();
this.operations.Add(new byte[] { Convert.ToByte(STX) });
operation_start_index = this.operations.Count();
}
catch (Win32Exception inner)
{
Expand Down

0 comments on commit 5c8003f

Please sign in to comment.