要循环读取16站,如果我有些时候有几站没用,怎么判断呢?非常感谢!
E_maiL:[email protected]

解决方案 »

  1.   

    我也正在想用,能给我一份吗,非常感激,
    我的邮箱
    [email protected]
      

  2.   

    我可要一份不?
    [email protected]
      

  3.   

    还有我也想要一份
    [email protected]
    Thank you!
      

  4.   

    顶,我也想要一份,谢谢[email protected]
      

  5.   

    我也想要一份,谢谢[email protected]
      

  6.   

    [email protected]
    我也想要一份,谢谢
      

  7.   

    有吗
    [email protected]
    谢谢楼上呀
      

  8.   

    我也想要,我的email是[email protected],谢谢
      

  9.   

    我也想要一份啊
    [email protected],谢谢pc_csharp(帮助别人,帮助自己)!
      

  10.   

    请给我一份 [email protected]
    谢谢
      

  11.   

    [email protected] 很想了解一下,谢谢。
      

  12.   

    [email protected]非常感谢!!谢谢!
      

  13.   

    [email protected]刚好要找对串口编程的例子!
    谢谢了!
      

  14.   

    我直接引用VB6的mscomm32.ocx搞定了
      

  15.   

    学习,给我也发一份吧 [email protected]
      

  16.   

    收到的兄弟给我也发一份吧
    [email protected]
      

  17.   

    也给我来一份吧
    [email protected]
      

  18.   

    我也想要啊!不知哪位大哥可以发我一份啊?
    [email protected]
    谢谢!~~~~
      

  19.   

    大哥还有吗?给一份[email protected]
      

  20.   

    pc_csharp(帮助别人,帮助自己)---这位兄弟,你能给我发一份吗?
    谢谢!不胜感激!大家一起顶啊!!
      

  21.   

    如果有可能的话也麻烦大哥发给我一份[email protected]
      

  22.   

    看这里,三种方法
    http://www.microsoft.com/china/MSDN/library/enterprisedevelopment/softwaredev/code4fun12102003.mspx
      

  23.   

    来晚了,给我也来一份阿
    [email protected]
      

  24.   

    there is chinese class
    you can translate it into english
      

  25.   

    终于有救了!!那位大哥给我发一份
    [email protected]
    我正为这个发愁呢
      

  26.   

    using System;
    using System.Runtime.InteropServices;
    using System.Windows.Forms;namespace printuseapi
    {
    public class writeLpt1
    {
    #region 申明要引用的和並口要調用的API
    //win32 api constants 
    private const uint GENERIC_READ = 0x80000000; 
    private const uint GENERIC_WRITE = 0x40000000; 
    private const int OPEN_EXISTING = 3;       
    private const int INVALID_HANDLE_VALUE = -1; 
    private const uint FILE_FLAG_OVERLAPPED = 0x40000000;   //異步通訊
    private const int MAXBLOCK = 4096; private const uint PURGE_TXABORT = 0x0001;  // Kill the pending/current writes to the comm port.
    private const uint PURGE_RXABORT = 0x0002;  // Kill the pending/current reads to the comm port.
    private const uint PURGE_TXCLEAR = 0x0004;  // Kill the transmit queue if there.
    private const uint PURGE_RXCLEAR = 0x0008;  // Kill the typeahead buffer if there.

    private const int EV_RXCHAR = 0x0001; //private const uint EV_RXCHAR = 
           
    [StructLayout(LayoutKind.Sequential)] 
    private struct DCB  

    //taken from c struct in platform sdk  
    public int DCBlength;          
    public int BaudRate;            
    public int fBinary;
    public int fParity;
    public int fOutxCtsFlow;
    public int fOutxDsrFlow;
    public int fDtrControl;
    public int fDsrSensitivity;   
    public int fTXContinueOnXoff;
    public int fOutX;
    public int fInX;
    public int fErrorChar;
    public int fNull;
    public int fRtsControl;

    public int fAbortOnError;
    public int fDummy2;
    public ushort wReserved;         public ushort XonLim;           
    public ushort XoffLim;          
    public byte ByteSize;           
    public byte Parity;             
    public byte StopBits;           
    public char XonChar;            
    public char XoffChar;           
    public char ErrorChar;          


    public char EofChar;            
    public char EvtChar;            
    public ushort wReserved1;       
    }  [StructLayout(LayoutKind.Sequential)] 
    private struct COMMTIMEOUTS  
    {   
    public int ReadIntervalTimeout;  
    public int ReadTotalTimeoutMultiplier;  
    public int ReadTotalTimeoutConstant;  
    public int WriteTotalTimeoutMultiplier;  
    public int WriteTotalTimeoutConstant;  
    }      [StructLayout(LayoutKind.Sequential)]    
    private struct OVERLAPPED  
    {  
    public int  Internal;  
    public int  InternalHigh;  
    public int  Offset;  
    public int  OffsetHigh;  
    public int hEvent;  
    }
      

  27.   

    [StructLayout(LayoutKind.Sequential)]
    private struct COMSTAT
    {
    /*public int fCtsHold;
    public int fDsrHold;
    public int fRlsdHold;
    public int fXoffHold;
    public int fXoffSent;
    public int fEof;
    public int fTxim;
    public int fReserved;
    public int cbInQue;
    public int cbOutQue;*/
    // Should have a reverse, i don't know why!!!!!
    public int cbOutQue;
    public int cbInQue;
    public int fReserved;
    public int fTxim;
    public int fEof;
    public int fXoffSent;
    public int fXoffHold;
    public int fRlsdHold;
    public int fDsrHold;
    public int fCtsHold;  
    }
    #if FULLFRAMEWORK
      [DllImport("kernel32")] 
      private static extern int CreateFile( 
       string lpFileName,                         // file name 
       uint dwDesiredAccess,                      // access mode 
       int dwShareMode,                          // share mode 
       int lpSecurityAttributes, // SD 
       int dwCreationDisposition,                // how to create 
       int dwFlagsAndAttributes,                 // file attributes 
       int hTemplateFile                        // handle to template file 
       );
    #else
    [DllImport("kernel32")]
    private static extern int CreateFile( 
    string lpFileName,                         // file name 
    uint dwDesiredAccess,                      // access mode 
    int dwShareMode,                          // share mode 
    int lpSecurityAttributes, // SD 
    int dwCreationDisposition,                // how to create 
    uint dwFlagsAndAttributes,                 // file attributes 
    int hTemplateFile                        // handle to template file 
    );
    #endif
    #if FULLFRAMEWORK
      [DllImport("kernel32")] 
      private static extern bool GetCommState( 
       int hFile,  // handle to communications device 
       ref DCB lpDCB    // device-control block 
       );   
    #else
    //取得並口狀態
    [DllImport("kernel32")] 
    private static extern bool GetCommState( 
    int hFile,  // handle to communications device 
    ref DCB lpDCB    // device-control block 
    );
    #endif
    #if FULLFRAMEWORK
      [DllImport("kernel32")] 
      private static extern bool BuildCommDCB( 
       string lpDef,  // device-control string 
       ref DCB lpDCB     // device-control block 
       ); 
    #else
    [DllImport("kernel32")] 
    private static extern bool BuildCommDCB( 
    string lpDef,  // device-control string 
    ref DCB lpDCB     // device-control block 
    );
    #endif
    #if FULLFRAMEWORK
      [DllImport("kernel32")] 
      private static extern bool SetCommState( 
       int hFile,  // handle to communications device 
       ref DCB lpDCB    // device-control block 
       );
    #else
    [DllImport("kernel32")] 
    private static extern bool SetCommState( 
    int hFile,  // handle to communications device 
    ref DCB lpDCB    // device-control block 
    );
    #endif
    #if FULLFRAMEWORK
      [DllImport("kernel32")] 
      private static extern bool GetCommTimeouts( 
       int hFile,                  // handle to comm device 
       ref COMMTIMEOUTS lpCommTimeouts  // time-out values 
       );
    #else
    [DllImport("kernel32")] 
    private static extern bool GetCommTimeouts( 
    int hFile,                  // handle to comm device 
    ref COMMTIMEOUTS lpCommTimeouts  // time-out values 
    );
    #endif
    #if FULLFRAMEWORK
      [DllImport("kernel32")]    
      private static extern bool SetCommTimeouts( 
       int hFile,                  // handle to comm device 
       ref COMMTIMEOUTS lpCommTimeouts  // time-out values 
       );
    #else
    [DllImport("kernel32")]    
    private static extern bool SetCommTimeouts( 
    int hFile,                  // handle to comm device 
    ref COMMTIMEOUTS lpCommTimeouts  // time-out values 
    );
    #endif
    #if FULLFRAMEWORK
      [DllImport("kernel32")] 
      private static extern bool ReadFile( 
       int hFile,                // handle to file 
       byte[] lpBuffer,             // data buffer 
       int nNumberOfBytesToRead,  // number of bytes to read 
       ref int lpNumberOfBytesRead, // number of bytes read 
       ref OVERLAPPED lpOverlapped    // overlapped buffer 
       );
    #else
    [DllImport("kernel32")] 
    private static extern bool ReadFile( 
    int hFile,                // handle to file 
    byte[] lpBuffer,             // data buffer 
    int nNumberOfBytesToRead,  // number of bytes to read 
    ref int lpNumberOfBytesRead, // number of bytes read 
    ref OVERLAPPED lpOverlapped    // overlapped buffer 
    );
    #endif
    #if FULLFRAMEWORK
      [DllImport("kernel32")] 
      private static extern bool WriteFile( 
       int hFile,                    // handle to file 
       byte[] lpBuffer,                // data buffer 
       int nNumberOfBytesToWrite,     // number of bytes to write 
       ref int lpNumberOfBytesWritten,  // number of bytes written 
       ref OVERLAPPED lpOverlapped        // overlapped buffer 
       ); 
    #else
    [DllImport("kernel32")] 
    private static extern bool WriteFile( 
    int hFile,                    // handle to file 
    byte[] lpBuffer,                // data buffer 
    int nNumberOfBytesToWrite,     // number of bytes to write 
    ref int lpNumberOfBytesWritten,  // number of bytes written 
    ref OVERLAPPED lpOverlapped        // overlapped buffer 
    );
    #endif
    #if FULLFRAMEWORK
      [DllImport("kernel32")] 
      private static extern bool CloseHandle( 
       int hObject   // handle to object 
       );
    #else
    [DllImport("kernel32")] 
    private static extern bool CloseHandle( 
    int hObject   // handle to object 
    );
    #endif
    #if FULLFRAMEWORK
      [DllImport("kernel32")]
      private static extern bool ClearCommError(
       int hFile,     // handle to file
       ref int lpErrors,
       ref COMSTAT lpStat
      );
    #else
    [DllImport("kernel32")]
    private static extern bool ClearCommError(
    int hFile,     // handle to file
    ref int lpErrors,
    ref COMSTAT lpStat
    );
    #endif
      

  28.   

    #if FULLFRAMEWORK
      [DllImport("kernel32")]
      private static extern bool PurgeComm(
       int hFile,     // handle to file
       uint dwFlags
       );
    #else
    [DllImport("kernel32")]
    private static extern bool PurgeComm(
    int hFile,     // handle to file
    uint dwFlags
    );
    #endif
    #if FULLFRAMEWORK
      [DllImport("kernel32")]
      private static extern bool SetupComm(
       int hFile,
       int dwInQueue,
       int dwOutQueue
      );
    #else
    [DllImport("kernel32")]
    private static extern bool SetupComm(
    int hFile,
    int dwInQueue,
    int dwOutQueue
    );
    #endif#if FULLFRAMEWORK
      [DllImport("kernel32")] 
      private static extern bool SetCommMask( 
    int hFile,
    int dwEvtMask //梓隴岈璃腔栚鎢
       );
    #else
    [DllImport("kernel32")]
    private static extern bool SetCommMask( 
    int hFile,
    int dwEvtMask //表明事件的掩碼
    );
    #endif#if FULLFRAMEWORK
      [DllImport("kernel32")] 
      private static extern bool WaitCommEvent( 
    int hFile,
    ref int lpEvtMask,
    ref OVERLAPPED lpOverlapped
       
    );
    #else
    [DllImport("kernel32")]
    private static extern bool WaitCommEvent( 
    int hFile,
    int dwEvtMask,
    ref OVERLAPPED lpOverlapped
    );
    #endif#if FULLFRAMEWORK
      [DllImport("kernel32")] 
      private static extern int CreateEvent( 
    int lpSecurityAttributes,
    bool bManualReset,
    bool bInitialState,
    string lpName
    );
    #else
    [DllImport("kernel32")]
    private static extern int CreateEvent( 

    int lpSecurityAttributes,
    bool bManualReset,
    bool bInitialState,
    string lpName
    );
    #endif
    //private static extern int
    #endregion // SerialPort成員
    private int hComm = INVALID_HANDLE_VALUE;
    private bool bOpened = false; //標志並口初始化成功與否的標志 public bool Opened //用屬性返回標志變量
    {
    get
    {
    return bOpened;
    }
    }