这个是技术服务提供的代码,但是我们需要c#的,之前也没有做跟硬件接口类的所以不太熟悉,请教大家应该怎么写?根据我的理解,可能需要传一个string入打印机,应该怎么作?Hi all,
When printing the label by your applications, please replace those red colour data by your parameters. The size and the location of the TEXTs may need to modify to create a better view.
ofstream fout; //declare file-stream handle
fout.open("lpt1:", ios::out); //open out to lpt1:
fout<<"^XA"; // start ZPL command
fout<<"^FO11,19^A0N,17,16^FDYXX^FS"; // define the locate of the printout and the size of the font is 17 x 16
fout<<"^FO45,19^A0N,17,16^FDXXXXX^FS";
fout<<"^FO95,19^A0N,17,16^FDAA^FS";
fout<<"^FO121,19^A0N,17,16^FDB^FS";
fout<<"^FO11,40^A0N,13,12^FDMM/DD/YY^FS"; // define the locate of the printout and the size of the font is 13 x 12
fout<<"^FO81,40^A0N,13,12^FDC^FS";
fout<<"^FO103,40^A0N,13,12^FDD^FS";
fout<<"^FO11,59^A0N,13,12^FDPF^FS";
fout<<"^FO45,60^A0N,13,12^FDKF^FS";
fout<<"^FO73,60^A0N,13,12^FDDD^FS";
fout<<"^FO95,61^A0N,13,12^FDI^FS";
fout<<"^BY1,3,15^FO11,80^BCN,,Y,N^FD0705610065^FS"; // print barcode 128 with human readable
fout<<"^PQ1"; //print one label
fout<<"^XZ"; //sending end of zpl Print one
fout.close(); //close file Please contact me if any unclear.
When printing the label by your applications, please replace those red colour data by your parameters. The size and the location of the TEXTs may need to modify to create a better view.
ofstream fout; //declare file-stream handle
fout.open("lpt1:", ios::out); //open out to lpt1:
fout<<"^XA"; // start ZPL command
fout<<"^FO11,19^A0N,17,16^FDYXX^FS"; // define the locate of the printout and the size of the font is 17 x 16
fout<<"^FO45,19^A0N,17,16^FDXXXXX^FS";
fout<<"^FO95,19^A0N,17,16^FDAA^FS";
fout<<"^FO121,19^A0N,17,16^FDB^FS";
fout<<"^FO11,40^A0N,13,12^FDMM/DD/YY^FS"; // define the locate of the printout and the size of the font is 13 x 12
fout<<"^FO81,40^A0N,13,12^FDC^FS";
fout<<"^FO103,40^A0N,13,12^FDD^FS";
fout<<"^FO11,59^A0N,13,12^FDPF^FS";
fout<<"^FO45,60^A0N,13,12^FDKF^FS";
fout<<"^FO73,60^A0N,13,12^FDDD^FS";
fout<<"^FO95,61^A0N,13,12^FDI^FS";
fout<<"^BY1,3,15^FO11,80^BCN,,Y,N^FD0705610065^FS"; // print barcode 128 with human readable
fout<<"^PQ1"; //print one label
fout<<"^XZ"; //sending end of zpl Print one
fout.close(); //close file Please contact me if any unclear.
解决方案 »
- c#的项目怎么逆向工程出类图?用visio或者EA
- 简单问题,需要实例,TextBox 如何限制数据字数 5-10 位
- 如何脱离死循环
- .net下 面向连接的tcp异步socket接收传输问题寻求高手帮助!!!
- 如何将自己构建好的DataTable中的数据加入到数据库中?兄弟姐妹们,出手了!!!
- petshop中的DAL工厂主要目的是什么?
- 我是新手啊,高手进来帮个忙啊
- 请指点两个问题
- 很简单的问题 .net 属性窗口的自动隐藏的选项不可选,请问应怎么设置才有自动隐藏?
- 新手请教,关于dataset
- c#中vs2003或2005的代码格式化是什么快捷键
- C/S模式用ClickOnce部署出现的问题(在线等~~~急)
private void button1_Click(object sender, EventArgs e)
{
if (((textBox1.Text == "") || (textBox2.Text == "") || (textBox3.Text == "") || (comboBox1.Text == "")
|| (comboBox2.Text == "") || (comboBox3.Text == "") || (comboBox4.Text == "") || (comboBox5.Text == "")) == true)
{
MessageBox.Show("请填写每一项!!");
return;
} GetNo();
//zpl command line starts here
string s = "^XA^FO11,19^A0N,17,16^FDYXX^FS^FO45,19^A0N,17,16^FDXXXXX^FS^FO95,19^A0N,17,16^FDAA^FS^FO121,19^A0N,17,16^FDB^FS^FO11,40^A0N,13,12^FDMM/DD/YY^FS^FO81,40^A0N,13,12^FDC^FS^FO103,40^A0N,13,12^FDD^FS^FO11,59^A0N,13,12^FDPF^FS^FO45,60^A0N,13,12^FDKF^FS^FO73,60^A0N,13,12^FDDD^FS^FO95,61^A0N,13,12^FDI^FS^BY1,3,15^FO11,80^BCN,,Y,N^FD0705610065^FS^PQ1^XZ "; PrintDialog pd = new PrintDialog();
pd.PrinterSettings = new PrinterSettings(); if (DialogResult.OK == pd.ShowDialog(this))
{
// Send a printer-specific to the printer.
RawPrinterHelper.SendStringToPrinter(pd.PrinterSettings.PrinterName, s); }
}
其中string s的那一串就是ZPL命令
定义和这个一样的stream,按照这样的格式写进去阿
---------------------------------------------就是想请教这个,IO那块不熟悉,帮忙写个example看看先!!!!
{
[StructLayout(LayoutKind.Sequential)]
Private struct OVERLAPPED
{
int Internal;
int InternalHigh;
int Offset;
int OffSetHigh;
int hEvent;
}
[DllImport("kernel32.dll")]
private static extern int CreateFile(
string lpFileName,
uint dwDesiredAccess,
int dwShareMode,
int lpSecurityAttributes,
int dwCreationDisposition,
int dwFlagsAndAttributes,
int hTemplateFile
);
[DllImport("kernel32.dll")]
private static extern bool WriteFile(
int hFile,
byte[] lpBuffer,
int nNumberOfBytesToWrite,
ref int lpNumberOfBytesWritten,
ref OVERLAPPED lpOverlapped
);
[DllImport("kernel32.dll")]
private static extern bool CloseHandle(
int hObject
);
private int iHandle;
public bool Open()
{
iHandle=CreateFile("lpt1",0x40000000,0,0,3,0,0);
if(iHandle !=-1)
{
return true;
}
else
{
return false;
}
}
public bool Write(String Mystring)
{
if(iHandle !=-1)
{
int i;
OVERLAPPED x;
byte() mybyte=System.Text.Encoding.Default.GetBytes(Mystring);
return WriteFile(iHandle,mybyte,mybyte.Length
ref i,ref x);
}
else
{
Throw new Exception("端口未打开!");
}
}
public bool Close()
{
return CloseHandle(iHandle);
}
}
---------------------------------------------------------------/// <summary>
///在C#中调用windows API
/// </summary>
public class RawPrinterHelper { // Structure and API declarions:
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Ansi)]
public class DOCINFOA
{
[MarshalAs(UnmanagedType.LPStr)]
public string pDocName; [MarshalAs(UnmanagedType.LPStr)]
public string pOutputFile; [MarshalAs(UnmanagedType.LPStr)]
public string pDataType; } [DllImport("winspool.Drv", EntryPoint = "OpenPrinterA", SetLastError = true, CharSet = CharSet.Ansi, ExactSpelling = true, CallingConvention = CallingConvention.StdCall)]
public static extern bool OpenPrinter([MarshalAs(UnmanagedType.LPStr)] string szPrinter, out IntPtr hPrinter, long pd); [DllImport("winspool.Drv", EntryPoint = "ClosePrinter", SetLastError = true, ExactSpelling = true, CallingConvention = CallingConvention.StdCall)]
public static extern bool ClosePrinter(IntPtr hPrinter); [DllImport("winspool.Drv", EntryPoint = "StartDocPrinterA", SetLastError = true, CharSet = CharSet.Ansi, ExactSpelling = true, CallingConvention = CallingConvention.StdCall)]
public static extern bool StartDocPrinter(IntPtr hPrinter, Int32 level, [In, MarshalAs(UnmanagedType.LPStruct)] DOCINFOA di); [DllImport("winspool.Drv", EntryPoint = "EndDocPrinter", SetLastError = true, ExactSpelling = true, CallingConvention = CallingConvention.StdCall)]
public static extern bool EndDocPrinter(IntPtr hPrinter); [DllImport("winspool.Drv", EntryPoint = "StartPagePrinter", SetLastError = true, ExactSpelling = true, CallingConvention = CallingConvention.StdCall)]
public static extern bool StartPagePrinter(IntPtr hPrinter); [DllImport("winspool.Drv", EntryPoint = "EndPagePrinter", SetLastError = true, ExactSpelling = true, CallingConvention = CallingConvention.StdCall)]
public static extern bool EndPagePrinter(IntPtr hPrinter); [DllImport("winspool.Drv", EntryPoint = "WritePrinter", SetLastError = true, ExactSpelling = true, CallingConvention = CallingConvention.StdCall)]
public static extern bool WritePrinter(IntPtr hPrinter, IntPtr pBytes, Int32 dwCount, out Int32 dwWritten);
现在我们就是需要运用ZPL,当然前提是在他们提供帮助的情况下.我们告诉他们我想要达到的效果然后他们提供ZPL命令,我们要做的就是把这个命令传给打印机.怎么做?
private void Form1_Load(object sender, System.EventArgs e)
{
LabelApp=new LabelApplicationClass();
doc=(LabelView.LabelDocument)LabelApp.ActiveDocument();
doc.Open("c:\\worklog\\label.lbl",true);
}private void PrintLabel(string result)
{
try
{
LabelView.LabelField snLabel=(LabelView.LabelField)((LabelView.LabelFields)doc.LabelFields).Item("SN");
snLabel.Value=result;
doc.LabelSetup();
doc.PrintLabel(2,null,null,null,null,null,null);
}
catch(Exception err)
{
MessageBox.Show(err.ToString(),"提示",MessageBoxButtons.OK,MessageBoxIcon.Warning);
}
}
private void Form1_Closing(object sender, System.ComponentModel.CancelEventArgs e)
{
LabelApp.Quit();
LabelApp = null;
System.GC.Collect();
}
兄弟有没有联系方式可以交流以下 我的[email protected]
那边技术支持又来一个新方案,这个怎么实现?> 你好,
> 如果直接打开端口的方法不行的话,可以尝试用文本打印驱动,在打印机中添加 "Generic / Text
> Only"然后直接把文本打印到 Generic / Text Only 打印机中。
> 添加打印机,选择 制造商为"Generic" 打印机为 "Generic / Text Only "的打印机,该打印机为WINDOWS 自带的。
始终觉得调用DLL是最好的方法。
我把你给我的那个LPTControl类copy进去,优点小问题你给解决一下:
public bool Write(String Mystring)
{
private int i;
OVERLAPPED x; if(iHandle !=-1)
{ byte[] mybyte=System.Text.Encoding.Default.GetBytes(Mystring);
return WriteFile(iHandle,mybyte,mybyte.Length,ref i,ref x);
}
else
{
throw new Exception("端口未打开!");
}
}这个里面的ref i 和ref x编译通过不了,说为赋值.
我不太明白wirte函数申明中这两个参数的意思,能说明下么?
ref int lpNumberOfBytesWritten,
ref OVERLAPPED lpOverlapped
1)lpNumberOfBytesWritten这个参数返回实际的写入字节数.
2)lpOverlapped这个参数指定了当前操作的选项:如是否写完再运行程序...2.另外这边需要改成:
[DllImport("kernel32.dll")]
private static extern bool WriteFile(
int hFile,
byte[] lpBuffer,
int nNumberOfBytesToWrite,
out int lpNumberOfBytesWritten,
out OVERLAPPED lpOverlapped
);public bool Write(String Mystring)
{
if(_iHandle !=-1)
{
int i;
OVERLAPPED x;
byte[] mybyte=System.Text.Encoding.Default.GetBytes(Mystring); return WriteFile(_iHandle,mybyte,mybyte.Length,out i,out x);
}
else
{
throw new Exception("端口未打开!");
}
}
今天斑马机的技术支持过来了,根据我们要打印的标签要求设置好了ZPL
现在剩下的任务就是把lpt1口打开
利用你上面给我的调用api的方法是其中一条路,另外一个可以设置一个文本打印机然后将zpl命令作为一个文本文件打印输出,第二种方法我还不是很理解,能解释一下么?怎么样实现呢?kssys兄最好有msn或者qq或者email,我好实时请教您问题,再次感谢