zoukankan      html  css  js  c++  java
  • C#直接操作并口

    C#只提供了直接操作串口的类,如果直接操作并口的话需要调用API函数:
     
      using   System.Runtime.InteropServices;
      
      string   sendData   =   "^xa^fo50,80^adn,36,20^fdTRW   EOL2^fs^xz ";   //Zebra   打印机命令格式
            [DllImport( "kernel32.dll ")]  
                  private       static       extern       int       CreateFile(  
                  string       lpFileName,     //       要打开的串口/并口名称
                  int       dwDesiredAccess,   //       指定口的访问方式,一般设置为可读可写方式  
                  int       dwShareMode,             //       指定口的共享模式,不能共享,所以设置为0  
                  int       lpSecurityAttributes,     //       设置口的安全属性,WIN9X下不支持,应设为NULL
                  int       dwCreationDisposition   ,   //   对于串口通信,创建方式只能为   OPEN_EXISTING  
                  int       dwFlagsAndAttributes,   //   指定串口属性与标志
                  int   hTemplateFile);                             //       对于串口通信必须设置为NULL
            [DllImport( "kernel32.dll "   )]
    public   static   extern   void   WriteFile(int   ComHandle,string   SendData,int   StrLen,ref   int   aLen,int   zero);
            [DllImport( "kernel32.dll "   )]
                  public   static   extern   void   CloseHandle(int   handle);  
                  int   handle   =   CreateFile( "lpt1 ",   0x40000000,   0,   0,   3   /**//*OPEN_EXISTING*/,   0,   0);
                  if   (handle   !=   0)   {
                        WriteFile(handle,   sendData,   strLen,   ref   aLen,   0);
                        CloseHandle(handle);     //注意,只有关闭并口后打印机才执行命令
  • 相关阅读:
    归并排序
    二分查找
    分治 递归 引用 求一个数组中的最大和最小元素
    插入排序
    Poj 2503
    SELinux 基础命令
    Zend Framework中的MVC架构
    phpfpm详解
    CentOS 6 minimal 安装
    php 5.3.3 中的phpfpm配置
  • 原文地址:https://www.cnblogs.com/love2wllw/p/1847007.html
Copyright © 2011-2022 走看看