Commit 9a23782e 刘韬

添加TSC打印参数设置

1 个父辈 31f50a5d
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Drawing.Printing;
using System.Threading;
using System.Windows.Forms;
......@@ -245,6 +246,7 @@ namespace BLL
}
catch (Exception ex)
{
throw ex;
}
}
}
......@@ -467,13 +469,14 @@ namespace BLL
using (PrintDialog dlg = new PrintDialog())
{
PrinterSettings printerSettings = new PrinterSettings();
dlg.PrinterSettings.DefaultPageSettings.PaperSize = new PaperSize("C", 236, 157);
if (dlg.ShowDialog() != DialogResult.OK) return;
System.Drawing.Printing.PrintDocument print = new System.Drawing.Printing.PrintDocument {
dlg.PrinterSettings.DefaultPageSettings.PaperSize = new PaperSize("C", (int)(Common.Label[labelIdx].Size_mm.Width * 4.11), (int)(Common.Label[labelIdx].Size_mm.Height * 4.11));
//dlg.PrinterSettings.DefaultPageSettings.PrinterResolution.Kind = PrinterResolutionKind.High;
dlg.PrinterSettings.DefaultPageSettings.PrinterSettings.PrinterResolutions.Add(new PrinterResolution { Kind = PrinterResolutionKind.High });
if (dlg.ShowDialog() != DialogResult.OK)
return;
PrintDocument print = new PrintDocument {
PrinterSettings = dlg.PrinterSettings
};
//print.PrinterSettings.DefaultPageSettings.Color = false;
print.PrintPage += PrintTest_PrintPage;
print.DefaultPageSettings.Landscape = dlg.PrinterSettings.DefaultPageSettings.Landscape;
print.Print();
......@@ -889,6 +892,8 @@ namespace BLL
private void PrintTest_PrintPage(object sender, System.Drawing.Printing.PrintPageEventArgs e)
{
e.Graphics.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.None;
e.Graphics.InterpolationMode = InterpolationMode.NearestNeighbor;
for (int i = 0; i < Common.Label[labelIdx].Field.Count; i++)
{
Model.ClsLabelField field = Common.Label[labelIdx].Field[i];
......
......@@ -267,6 +267,7 @@ namespace Model
if (Type == LabelFieldType.Text) return;
ZXing.BarcodeWriter writer = new ZXing.BarcodeWriter();
writer.Options.Height = (int)300 / 2;
ZXing.QrCode.QrCodeEncodingOptions qrCodeEncodingOptions = new ZXing.QrCode.QrCodeEncodingOptions()
{
DisableECI = true,
......@@ -340,6 +341,10 @@ namespace Model
if (Type == LabelFieldType.Text) return;
ZXing.BarcodeWriter writer = new ZXing.BarcodeWriter();
writer.Options.Height = (int)size.Height * 1;
writer.Options.Width = (int)size.Width * 1;
writer.Options.NoPadding = true;
writer.Options.Margin = 0;
ZXing.QrCode.QrCodeEncodingOptions qrCodeEncodingOptions = new ZXing.QrCode.QrCodeEncodingOptions()
{
DisableECI = true,
......@@ -347,6 +352,7 @@ namespace Model
Width = (int)size.Width,
Height = (int)size.Width,
Margin = 1,
NoPadding = true,
PureBarcode = true
};
ZXing.PDF417.PDF417EncodingOptions pDF417EncodingOptions = new ZXing.PDF417.PDF417EncodingOptions()
......@@ -366,20 +372,22 @@ namespace Model
writer.Options.PureBarcode = true;
//writer.Options.Margin = 0;
//writer.Options.Height = (int)size.Height;
writer.Options.Width = (int)size.Width;
switch (Type)
{
case LabelFieldType.Code39:
writer.Format = ZXing.BarcodeFormat.CODE_39;
writer.Options.NoPadding = true;
Image = writer.Write(content);
break;
case LabelFieldType.Code93:
writer.Format = ZXing.BarcodeFormat.CODE_93;
writer.Options.NoPadding = true;
Image = writer.Write(content);
break;
case LabelFieldType.Code128:
writer.Format = ZXing.BarcodeFormat.CODE_128;
writer.Options.NoPadding = true;
Image = writer.Write(content);
break;
case LabelFieldType.DataMatrix:
......
......@@ -28,7 +28,6 @@ namespace Asa
Common.LabelPrint = new BLL.LabelPrint();
this.dir = dir;
Common.LabelPrint.Load(dir);
}
/// <summary>
......@@ -309,15 +308,15 @@ namespace Asa
/// </summary>
/// <param name="key"></param>
/// <returns>是否打印成功</returns>
public bool PrintToTsc1(Dictionary<string, string> key, out TscStauts tscStauts)
public bool PrintToTsc1(Dictionary<string, string> key, TscConfig tscConfig, out TscStauts tscStauts)
{
tscStauts = CheckTscStatus();
if (tscStauts != 0)
{
var err = (TscStauts)tscStauts;
Console.WriteLine($"Error: {err}");
return false;
}
//tscStauts = CheckTscStatus();
//if (tscStauts != 0)
//{
// var err = (TscStauts)tscStauts;
// Console.WriteLine($"Error: {err}");
// return false;
//}
var t = Task.Run(() =>
{
Bitmap bmp = null;
......@@ -328,26 +327,26 @@ namespace Asa
var nn = Common.PxToMM(bmp.Height);
TSCSDK.driver TSCLIB_DLL = new TSCSDK.driver();
TSCLIB_DLL.openport("TSC TTP-342 Pro");
TSCLIB_DLL.openport(tscConfig.PrinterName);
//TSCLIB_DLL.sendcommand("GETSENSOR(\"PEEL\")");
TSCLIB_DLL.sendcommand("\0x27!?");
Task.Delay(1000).Wait();
//TSCLIB_DLL.sendcommand("\0x27!?");
//Task.Delay(1000).Wait();
///IntPtr aaa = Marshal.AllocHGlobal(256);
byte[] b = new byte[256];
IntPtr aaa = System.Runtime.InteropServices.Marshal.UnsafeAddrOfPinnedArrayElement(b, 0);
TSCSDK.driver.ReadPrinter(TSCLIB_DLL.hPrinter, aaa, 255, out int reby);
//byte[] b = new byte[256];
//IntPtr aaa = System.Runtime.InteropServices.Marshal.UnsafeAddrOfPinnedArrayElement(b, 0);
//TSCSDK.driver.ReadPrinter(TSCLIB_DLL.hPrinter, aaa, 255, out int reby);
//Marshal.Copy(aaa, b, 0, 256);
//Marshal.FreeHGlobal(aaa);
var bbbb = Encoding.Unicode.GetString(b);
//var bbbb = Encoding.Unicode.GetString(b);
TSCLIB_DLL.sendcommand($"SIZE {mm:0.00} mm, {nn:0.00} mm");
TSCLIB_DLL.sendcommand("GAP 3 mm,0.3 mm");
TSCLIB_DLL.sendcommand("SET CUTTER OFF");
TSCLIB_DLL.sendcommand($"GAP {tscConfig.Gap} mm,{tscConfig.GapOffset} mm");
TSCLIB_DLL.sendcommand("SET CUTTER ON");
TSCLIB_DLL.sendcommand("SET RIBBON OFF"); //使用碳带
TSCLIB_DLL.sendcommand("SET ENCODER OFF"); //碳带编码器检测
TSCLIB_DLL.sendcommand("OFFSET -10 mm"); //出纸偏移
TSCLIB_DLL.sendcommand("SPEED 9"); //速度最大15
TSCLIB_DLL.sendcommand("DENSITY 12"); //浓度
TSCLIB_DLL.sendcommand("DIRECTION 1");
TSCLIB_DLL.sendcommand($"OFFSET {tscConfig.Offset} mm"); //出纸偏移
TSCLIB_DLL.sendcommand($"SPEED {tscConfig.Speed}"); //速度最大15
TSCLIB_DLL.sendcommand($"DENSITY {tscConfig.Density}"); //浓度最大15
TSCLIB_DLL.sendcommand($"DIRECTION {tscConfig.Direction}");
TSCLIB_DLL.sendcommand("SET PEEL OFF");
TSCLIB_DLL.clearbuffer();
TSCLIB_DLL.sendpicture(0, 0, bmp);
......@@ -415,5 +414,36 @@ namespace Asa
b = 1<<1,
c = 1<<2,
}
public class TscConfig {
/// <summary>
/// 打印机名称
/// </summary>
public string PrinterName = "TSC TTP-342 Pro";
/// <summary>
/// 纸张间隙mm,默认3mm
/// </summary>
public double Gap = 3;
/// <summary>
/// 纸张间隙偏移量mm,默认0.3mm
/// </summary>
public double GapOffset = 0.3;
/// <summary>
/// 打印方向 1横向,0纵向,默认1
/// </summary>
public int Direction = 1;
/// <summary>
/// 出纸偏移量mm,默认-10mm
/// </summary>
public double Offset = -10;
/// <summary>
/// 打印速度1-15,默认9
/// </summary>
public int Speed = 9;
/// <summary>
/// 打印浓度 1-15,默认12
/// </summary>
public int Density = 12;
}
}
......@@ -47,11 +47,11 @@
<Reference Include="System.Data" />
<Reference Include="System.Net.Http" />
<Reference Include="System.Xml" />
<Reference Include="zxing, Version=0.16.5.0, Culture=neutral, PublicKeyToken=4e88037ac681fe60, processorArchitecture=MSIL">
<HintPath>..\packages\ZXing.Net.0.16.5\lib\net461\zxing.dll</HintPath>
<Reference Include="zxing, Version=0.16.9.0, Culture=neutral, PublicKeyToken=4e88037ac681fe60, processorArchitecture=MSIL">
<HintPath>..\packages\ZXing.Net.0.16.9\lib\net461\zxing.dll</HintPath>
</Reference>
<Reference Include="zxing.presentation, Version=0.16.5.0, Culture=neutral, PublicKeyToken=4e88037ac681fe60, processorArchitecture=MSIL">
<HintPath>..\packages\ZXing.Net.0.16.5\lib\net461\zxing.presentation.dll</HintPath>
<Reference Include="zxing.presentation, Version=0.16.9.0, Culture=neutral, PublicKeyToken=4e88037ac681fe60, processorArchitecture=MSIL">
<HintPath>..\packages\ZXing.Net.0.16.9\lib\net461\zxing.presentation.dll</HintPath>
</Reference>
</ItemGroup>
<ItemGroup>
......
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="ZXing.Net" version="0.16.5" targetFramework="net461" />
<package id="ZXing.Net" version="0.16.9" targetFramework="net462" />
</packages>
\ No newline at end of file
......@@ -37,12 +37,14 @@
this.pictureBox1 = new System.Windows.Forms.PictureBox();
this.button5 = new System.Windows.Forms.Button();
this.btn_tsc = new System.Windows.Forms.Button();
this.cb_labelname = new System.Windows.Forms.ComboBox();
this.advanceConfigEdit1 = new ConfigHelper.AdvanceConfigEdit();
((System.ComponentModel.ISupportInitialize)(this.pictureBox1)).BeginInit();
this.SuspendLayout();
//
// button1
//
this.button1.Location = new System.Drawing.Point(154, 127);
this.button1.Location = new System.Drawing.Point(142, 68);
this.button1.Name = "button1";
this.button1.Size = new System.Drawing.Size(123, 49);
this.button1.TabIndex = 0;
......@@ -52,7 +54,7 @@
//
// textBox1
//
this.textBox1.Location = new System.Drawing.Point(374, 127);
this.textBox1.Location = new System.Drawing.Point(362, 68);
this.textBox1.Name = "textBox1";
this.textBox1.Size = new System.Drawing.Size(162, 21);
this.textBox1.TabIndex = 1;
......@@ -60,7 +62,7 @@
//
// button2
//
this.button2.Location = new System.Drawing.Point(374, 181);
this.button2.Location = new System.Drawing.Point(362, 122);
this.button2.Name = "button2";
this.button2.Size = new System.Drawing.Size(100, 23);
this.button2.TabIndex = 2;
......@@ -70,7 +72,7 @@
//
// button3
//
this.button3.Location = new System.Drawing.Point(154, 182);
this.button3.Location = new System.Drawing.Point(142, 123);
this.button3.Name = "button3";
this.button3.Size = new System.Drawing.Size(123, 49);
this.button3.TabIndex = 3;
......@@ -80,7 +82,7 @@
//
// textBox2
//
this.textBox2.Location = new System.Drawing.Point(374, 154);
this.textBox2.Location = new System.Drawing.Point(362, 95);
this.textBox2.Name = "textBox2";
this.textBox2.Size = new System.Drawing.Size(162, 21);
this.textBox2.TabIndex = 4;
......@@ -88,7 +90,7 @@
//
// button4
//
this.button4.Location = new System.Drawing.Point(374, 276);
this.button4.Location = new System.Drawing.Point(362, 217);
this.button4.Name = "button4";
this.button4.Size = new System.Drawing.Size(100, 23);
this.button4.TabIndex = 5;
......@@ -98,7 +100,7 @@
//
// pictureBox1
//
this.pictureBox1.Location = new System.Drawing.Point(502, 224);
this.pictureBox1.Location = new System.Drawing.Point(509, 123);
this.pictureBox1.Name = "pictureBox1";
this.pictureBox1.Size = new System.Drawing.Size(251, 163);
this.pictureBox1.TabIndex = 6;
......@@ -106,7 +108,7 @@
//
// button5
//
this.button5.Location = new System.Drawing.Point(154, 237);
this.button5.Location = new System.Drawing.Point(142, 178);
this.button5.Name = "button5";
this.button5.Size = new System.Drawing.Size(123, 47);
this.button5.TabIndex = 7;
......@@ -116,7 +118,7 @@
//
// btn_tsc
//
this.btn_tsc.Location = new System.Drawing.Point(154, 322);
this.btn_tsc.Location = new System.Drawing.Point(82, 377);
this.btn_tsc.Name = "btn_tsc";
this.btn_tsc.Size = new System.Drawing.Size(123, 42);
this.btn_tsc.TabIndex = 8;
......@@ -124,11 +126,28 @@
this.btn_tsc.UseVisualStyleBackColor = true;
this.btn_tsc.Click += new System.EventHandler(this.btn_tsc_Click);
//
// cb_labelname
//
this.cb_labelname.FormattingEnabled = true;
this.cb_labelname.Location = new System.Drawing.Point(82, 351);
this.cb_labelname.Name = "cb_labelname";
this.cb_labelname.Size = new System.Drawing.Size(160, 20);
this.cb_labelname.TabIndex = 9;
//
// advanceConfigEdit1
//
this.advanceConfigEdit1.Location = new System.Drawing.Point(283, 303);
this.advanceConfigEdit1.Name = "advanceConfigEdit1";
this.advanceConfigEdit1.Size = new System.Drawing.Size(404, 273);
this.advanceConfigEdit1.TabIndex = 10;
//
// Form1
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(800, 450);
this.ClientSize = new System.Drawing.Size(885, 588);
this.Controls.Add(this.advanceConfigEdit1);
this.Controls.Add(this.cb_labelname);
this.Controls.Add(this.btn_tsc);
this.Controls.Add(this.button5);
this.Controls.Add(this.pictureBox1);
......@@ -159,6 +178,8 @@
private System.Windows.Forms.PictureBox pictureBox1;
private System.Windows.Forms.Button button5;
private System.Windows.Forms.Button btn_tsc;
private System.Windows.Forms.ComboBox cb_labelname;
private ConfigHelper.AdvanceConfigEdit advanceConfigEdit1;
}
}
......@@ -23,9 +23,10 @@ namespace PrintLabel_Test
private void Form1_Load(object sender, EventArgs e)
{
print = new Asa.PrintLabel(Application.StartupPath + "\\Label",100);
print = new Asa.PrintLabel(Application.StartupPath + "\\Label",300);
print.PrintStatusChanged += Print_PrintStatusChanged;
loadlabelname();
}
private void Print_PrintStatusChanged(Asa.PrintLabel.PrinterStatus sta, string msg)
......@@ -36,6 +37,7 @@ namespace PrintLabel_Test
private void button1_Click(object sender, EventArgs e)
{
print.EditLabel();
loadlabelname();
}
private void button2_Click(object sender, EventArgs e)
......@@ -74,10 +76,21 @@ namespace PrintLabel_Test
print.SetResolution(300);
print.GetLabelName();
print.LoadLabel(textBox1.Text);
print.PrintToTsc1(text,out TscStauts tscStauts);
print.LoadLabel(cb_labelname.SelectedItem.ToString());
TscConfig tscConfig = new TscConfig();
tscConfig.Offset = ConfigHelper.Config.Get("Tsc_Offset", -17D);
tscConfig.Speed = ConfigHelper.Config.Get("Tsc_Speed", 9);
tscConfig.Density = ConfigHelper.Config.Get("Tsc_Density", 12);
print.PrintToTsc1(text, tscConfig, out TscStauts tscStauts);
return;
}
void loadlabelname() {
cb_labelname.Items.Clear();
cb_labelname.Items.AddRange(print.GetLabelName());
if (cb_labelname.Items.Count>0)
cb_labelname.SelectedIndex = 0;
}
}
}
支持 Markdown 格式
你添加了 0 到此讨论。请谨慎行事。
Finish editing this message first!