最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

  • <strong id="0fq0n"><code id="0fq0n"><dd id="0fq0n"></dd></code></strong>
      1. <ruby id="0fq0n"></ruby>

          <table id="0fq0n"><th id="0fq0n"><strike id="0fq0n"></strike></th></table>
            
                
                

            C#編程實現(xiàn)向并口設(shè)備發(fā)送指令、獲取并口設(shè)備的狀態(tài)

             更新時間:2015年06月16日 11:31:35   投稿:junjie  
            這篇文章主要介紹了C#編程實現(xiàn)向并口設(shè)備發(fā)送指令、獲取并口設(shè)備的狀態(tài),本文直接給出實例代碼,需要的朋友可以參考下
            using System;
            using System.Diagnostics;
            using System.Runtime.InteropServices;
            using System.Text;
            using System.Windows.Forms;
            
             
            namespace ParallelPort
            {
              public partial class Form1 : Form
              {
                const uint GENERIC_READ = 0x80000000;
                const uint GENERIC_WRITE = 0x40000000;
                const uint FILE_ATTRIBUTE_NORMAL = 0x80;
             
                #region win32 API
                [DllImport("kernel32.dll ")]
                private static extern int CreateFile(
                  string lpFileName,
                  uint dwDesiredAccess,
                  int dwShareMode,
                  int lpSecurityAttributes,
                  int dwCreationDisposition,
                  uint dwFlagsAndAttributes,
                  int hTemplateFile
                  );
             
                [DllImport("kernel32.dll ")]
                private static extern bool WriteFile(
                  int hFile,
                  byte[] lpBuffer,
                  int nNumberOfBytesToWrite,
                  ref int lpNumberOfBytesWritten,
                  int lpOverlapped
                  );
             
                [DllImport("kernel32.dll ")]
                private static extern bool DefineDosDevice(
                int dwFlags,
                string lpDeviceName,
                string lpTargetPath);
             
                [DllImport("kernel32.dll ")]
                private static extern bool CloseHandle(
                  int hObject
                  );
                [DllImport("kernel32.dll ")]
                private static extern bool ReadFile(
                  int hFile,
                  byte[] lpBuffer,
                  int nNumberOfBytesToRead,
                  ref int lpNumberOfBytesRead,
                  int lpOverlapped
                  );
                #endregion
            
             
                public Form1()
                {
                  InitializeComponent();
                }
             
            
                private void button1_Click(object sender, EventArgs e)
                {
                  int iHandle = -1;
                  try
                  {
                    int i = 0;
                    //創(chuàng)建實例
                    DefineDosDevice(0x00000001, "LptPortName",@"\Device\Parallel0");
                    iHandle = CreateFile(@"\\.\LptPortName",GENERIC_READ | GENERIC_WRITE, 0, 0, 3, FILE_ATTRIBUTE_NORMAL, 0);
                    if (iHandle !=-1)
                    {
                      byte[] mybyte = new byte[3]{ 0x12, 0x14, 0x14 };//要發(fā)送的命令(16進制)
                      WriteFile(iHandle, mybyte, mybyte.Length, ref i, 0);
                      byte[] mybyte1 = new byte[3];
                      string content = String.Empty;
                      int j = 0;
                      ReadFile(iHandle, mybyte1, 3, ref j, 0);
                      if (mybyte1 != null)
                      {
                        foreach(var tempByte in mybyte1)
                        {
                          content += tempByte.ToString();
                        }
                      }                
                      MessageBox.Show(content);//獲取的狀態(tài)值
                    }
                    else
                    {
                      MessageBox.Show("創(chuàng)建文件失敗!");
                    }
                  }
                  catch(Exception ex)
                  {
                    MessageBox.Show(ex.Message);
                  }
                  finally
                  {
                    if (iHandle > 0)
                    {
                      CloseHandle(iHandle);
                    }
                  }
                }
              }
            }
            
             
            

            相關(guān)文章

            最新評論

            瑞安市| 青海省| 阜南县| 汽车| 巧家县| 剑河县| 大余县| 宜兴市| 普兰县| 新密市| 景宁| 安阳市| 宜兰市| 郯城县| 延安市| 丽水市| 鄄城县| 开江县| 额敏县| 深州市| 秦安县| 晋州市| 铁力市| 新泰市| 田林县| 科技| 民和| 新乐市| 百色市| 双流县| 浠水县| 鹿邑县| 遂川县| 寿阳县| 顺义区| 区。| 洪泽县| 呼玛县| 玉门市| 冕宁县| 海宁市|