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);     //注意,只有关闭并口后打印机才执行命令
  • 相关阅读:
    git常用指令 github版本回退 reset
    三门问题 概率论
    如何高效的学习高等数学
    数据库6 关系代数(relational algebra) 函数依赖(functional dependency)
    数据库5 索引 动态哈希(Dynamic Hashing)
    数据库4 3层结构(Three Level Architecture) DBA DML DDL DCL DQL
    梦想开始的地方
    java String字符串转对象实体类
    java 生成图片验证码
    java 对象之间相同属性进行赋值
  • 原文地址:https://www.cnblogs.com/love2wllw/p/1847007.html
Copyright © 2011-2022 走看看