条码打印机维修常见问题及解决方法之一:C#.net语言写的调用条码打印机的程序,仅供参考。
using System;
using System.Collections.Generic;
using System.Text;
using System.Runtime.InteropServices;
namespace Barcode_Print
{
class LPTControl
{
[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,
out int lpNumberOfBytesWritten,
out 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, out i, out x);
}
else
{
throw new Exception("端口未打开!");
}
}
public bool Close()
{
return CloseHandle(iHandle);
}
}
说明:环境是110Xiii,600点的机器,你需要通过lpt1口跟打印机通讯;需要答应的时候调用其中的open()方法。如需要了解更多条码打印机的常见问题请留意本站!
如有其它条码机问题可以咨询我们的条码机维修技术员!他们将为你解答!
发布日期:2010-6-18 【返回】
|
有任何问题请联系我们在线客服 |
版权所有 |
zebra Sato Tec Datamax Intermec Godex Argox |
|
电话:020-22103158、13725124335 |
粤ICP备案编号 |
© 2001~2009 All rights reserved。 |
|
工作时间:周一-周五 09:00-19:00 |
本商店logo和图片都已经申请保护,不经授权不得使用。 |