Ejemplo n.º 1
0
 /// <summary>
 /// Close the driver
 /// </summary>
 protected void Close()
 {
     if (m_hPort != IntPtr.Zero)
     {
         FileEx.CloseHandle(m_hPort);
         m_hPort = IntPtr.Zero;
     }
 }
Ejemplo n.º 2
0
        /// <summary>
        /// Write data to the driver
        /// </summary>
        /// <param name="data">Data to write</param>
        /// <param name="bytesToWrite">Number of bytes from passed in buffer to write</param>
        /// <returns>Number of bytes actually written</returns>
        protected int Write(byte[] data, int bytesToWrite)
        {
            int written = 0;

            FileEx.WriteFile(m_hPort, data, bytesToWrite, ref written);

            return(written);
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Read data from the driver
        /// </summary>
        /// <param name="bytesToRead">The number of bytes requested.</param>
        /// <returns>A byte array returned by the driver</returns>
        protected byte[] Read(int bytesToRead)
        {
            byte[] buffer = new byte[bytesToRead];
            int    read   = 0;

            FileEx.ReadFile(m_hPort, buffer, bytesToRead, ref read);

            return(buffer);
        }
Ejemplo n.º 4
0
        protected void Open(OpenNETCF.IO.FileAccess access, OpenNETCF.IO.FileShare share)
        {
            m_hPort = FileEx.CreateFile(m_portName, access, share, IO.FileCreateDisposition.OpenExisting, 0);

            if ((int)m_hPort == -1)
            {
                throw new Win32.WinAPIException("Cannot open driver", Marshal.GetLastWin32Error());
            }
        }
Ejemplo n.º 5
0
        /// <summary>
        /// This function moves the file pointer of an open file
        /// <seealso cref="FileEx.MoveMethod"/>
        /// </summary>
        /// <param name="distance">Bytes to move - a positive number moves forward, a negative moves backward</param>
        /// <param name="seekFrom">Starting position from where distance is measured</param>
        /// <returns>New file position</returns>
        /// <remarks>The current file position can be queried using seekFrom(0, MoveMethod.CurrentPosition)</remarks>
        protected int Seek(int distance, FileEx.MoveMethod seekFrom)
        {
            int dist = FileEx.SetFilePointerCE(m_hPort, distance, 0, seekFrom);

            if (dist == 0)
            {
                throw new Win32.WinAPIException("Seek Failed", Marshal.GetLastWin32Error());
            }

            return(dist);
        }
Ejemplo n.º 6
0
        protected void DeviceIoControl(uint controlCode, byte[] inData, byte[] outData)
        {
            int xfer   = 0;
            int inlen  = (inData == null) ? 0 : inData.Length;
            int outlen = (outData == null) ? 0 : outData.Length;

            if (FileEx.DeviceIoControlCE(m_hPort, controlCode, inData, inlen, outData, outlen, ref xfer, IntPtr.Zero) == 0)
            {
                throw new Win32.WinAPIException("IOControl call failed", Marshal.GetLastWin32Error());
            }
        }
		/// <summary>
		/// This function moves the file pointer of an open file
		/// <seealso cref="FileEx.MoveMethod"/>
		/// </summary>
		/// <param name="distance">Bytes to move - a positive number moves forward, a negative moves backward</param>
		/// <param name="seekFrom">Starting position from where distance is measured</param>
		/// <returns>New file position</returns>
		/// <remarks>The current file position can be queried using seekFrom(0, MoveMethod.CurrentPosition)</remarks>
		protected int Seek(int distance, FileEx.MoveMethod seekFrom)
		{
			int dist = FileEx.SetFilePointerCE(m_hPort, distance, 0, seekFrom);
			
			if(dist == 0)
			{
				throw new Win32.WinAPIException("Seek Failed", Marshal.GetLastWin32Error());
			}

			return dist;
		}