此方式适用于市场上大多数的小票机 佳博、POS58 等,不适用于有些标签打印机 比如斑马打印机等

直接贴代码:

 private FileStream fs = null;
[DllImport("kernel32.dll", CharSet = CharSet.Auto)]//调用系统API打印函数
public static extern IntPtr CreateFile
(
string FileName, // file name
uint DesiredAccess, // access mode
uint ShareMode, // share mode
uint SecurityAttributes, // Security Attributes
uint CreationDisposition, // how to create
uint FlagsAndAttributes, // file attributes
string hTemplateFile // handle to template file
); /// <summary>
/// 打印小票
/// </summary>
/// <param name="msg"></param>
/// <returns></returns>
public string PrintMsg(string PosPort, string msg, bool isOpenMoneyBox)
{
try
{
IntPtr iHandle = CreateFile(PosPort, 0x40000000, , , , , null);
if (iHandle.ToInt32() == -)
{
return "票机连接失败.或者端口号错误.请测试打印机是否正常!";
}
else
{
try
{
fs = new FileStream(iHandle, FileAccess.ReadWrite);
StreamWriter sw = new StreamWriter(fs, System.Text.Encoding.Default); //写数据
sw.WriteLine(msg);
//开启钱箱
if (isOpenMoneyBox)
{
sw.Write(((char)).ToString() + "p" + ((char)).ToString() + ((char)).ToString() + ((char)).ToString());
}
sw.Flush();
sw.Close();
fs.Close();
return "";
}
catch (Exception ex)
{
return ex.InnerException == null ? ex.Message : ex.InnerException.Message;
}
}
}
catch (Exception exp)
{
return "TPL或者COM口连接失败!";
}
}

C# 使用C/S模式操作小票机打印的更多相关文章

  1. C#后台调用LPT1端口实现小票机打印方法。

    public class POSPrinter { const int OPEN_EXISTING = 3; string prnPort = "LPT1"; [DllImport ...

  2. PDA手持移动POS销售开单软件(网络版)、PDA手持设备小票机

    背景描述: 一家大中型批发及门店销售企业,经销多种冻食品,业务范围覆盖周边众多区域和城市.成立以来,随着业务量的扩大,产品销售分两大渠道:多门店销售和仓库批发,各门店每天都有大量的零散客户和老客户进行 ...

  3. python-类对象以字典模式操作

    #类对象以字典模式操作 class Person: def __init__(self): self.cache={} def __setitem__(self, key, value): #增加或修 ...

  4. python-类对象以列表切片模式操作

    #类对象以列表切片模式操作 class Person: def __init__(self): self.cache=[] def __setitem__(self, key, value): #修改 ...

  5. Django实现WebSSH操作物理机或虚拟机

    我想用它替换掉xshell.crt之类的工具 WebSSH操作物理机或虚拟机 Django实现WebSSH操作Kubernetes Pod文章发布后,有小伙伴说咖啡哥,我们现在还没有用上Kuberne ...

  6. 关于appium操作真机打开app之后无法定位页面元素的问题的解决办法

    appium操作真机打开app后无法定位页面元素:例如微信或者支付宝支付时,手机的安全控件会对支付环境进行保护,会断掉当前appium与真机的链接,导致连接失败,无法定位到页面元素,在做ui自动化之前 ...

  7. C#并口热敏小票打印机打印位图包括芯片的写入

    下面是打印所需要调用的代码: class LptControl { private string LptStr = "lpt1"; public LptControl(string ...

  8. 转:C#并口热敏小票打印机打印位图

    最近一直在研究并口小票打印机打印图片问题,这也是第一次和硬件打交道,不过还好,最终成功了. 这是DEMO的窗体: 下面是打印所需要调用的代码: class LptControl { private s ...

  9. C# 热敏打印机 小票打印机 打印图片

    最近一直在研究并口小票打印机打印图片问题,这也是第一次和硬件打交道,不过还好,最终成功了. 这是DEMO的窗体: 下面是打印所需要调用的代码: 因为我们这里主要是打印条形码和二维码,所以以条形码和二维 ...

随机推荐

  1. jstl删除session,choose,动态获取request当前工程路径

    1.jstl标签c:remove删除session request.getSession().setAttribute("ssmsg", "修改成功"); &l ...

  2. WinForm 资源文件的使用

    1. 创建资源文件: 2.双击资源文件,打开如下图:添加一个字符串: 名称为cnnstr 值为-- 3.添加文本文件和图像 4. 调用代码 MessageBox.Show(Resource1.cnns ...

  3. linux源码阅读笔记 fork函数

    在阅读源码的过程中,发现找不到fork函数的定义.后来在linux/init/main.c中找到了这样一条语句 static inline _syscall0(int,fork) 原来这里就是fork ...

  4. Pycharm

    1.下载pycharm-community-3.0.2.exe 2.setting: keymap scheme:快捷键方案,可选择自带的:default:或者选择eclipse的快捷方案. ide ...

  5. CSS 的命名和书写

    CSS书写顺序 1.位置属性(position, top, right, z-index, display, float等) 2.大小(width, height, padding, margin) ...

  6. JS操作Radio与Select

    //radio的chang事件,以及获取选中的radio的值 $("input[name=radioName]").on("change", function( ...

  7. leetcode 5 :Longest Palindromic Substring 找出最长回文子串

    题目: Given a string S, find the longest palindromic substring in S. You may assume that the maximum l ...

  8. 【mongoDB中级篇②】索引与expain

    索引的操作 数据库百分之八十的工作基本上都是查询,而索引能帮我们更快的查询到想要的数据.但是其降低了数据的写入速度,所以要权衡常用的查询字段,不必在太多字段上建立索引. 在mongoDB中默认是用bt ...

  9. 10 harsh truths that will help you grow

    10 harsh truths that will help you grow帮你成长的10个残酷事实In the game of life, if it often seems like you’r ...

  10. 客户端一个http连接包含两个方向,一个是这个http连接的输入,另一个是这个http连接的输出。

    1.客户端一个http连接包含两个方向,一个是这个http连接的输入,另一个是这个http连接的输出. 利用httpclient进行ip地址和端口号连接后,http的输出端作为http请求参数设置.h ...