Beispiel #1
0
 private static extern Boolean DeviceIoControl
 (
     int hfile,
     UInt32 IOctlcode,
     ref SERIAL_STATUS inbuf,              // fixme ... should not be specific
     UInt32 inbufsize,
     ref SERIAL_STATUS outbuf,             // fixme .... this should not be specific
     UInt32 outbufsize,
     ref UInt32 return_count,
     IntPtr overlap
 );
Beispiel #2
0
//		private void whackTimeouts()
//		{
//			// SET THE COMM TIMEOUTS.
//			COMMTIMEOUTS ctoCommPort = new COMMTIMEOUTS();
//			// GetCommTimeouts(hComm,ref ctoCommPort);
//
//			//		  ctoCommPort.ReadTotalTimeoutConstant = ReadTimeout;
//			//		  ctoCommPort.ReadTotalTimeoutMultiplier = 0;
//
//			ctoCommPort.ReadIntervalTimeout = UInt32.MaxValue;
//			ctoCommPort.ReadTotalTimeoutMultiplier = 0;
//			ctoCommPort.ReadTotalTimeoutConstant = 0;
//			ctoCommPort.WriteTotalTimeoutMultiplier = 0;
//			ctoCommPort.WriteTotalTimeoutConstant = 0;
//			bool temp = SetCommTimeouts(hComm,ref ctoCommPort);
//			Console.WriteLine("SetCommTimeOuts: " + temp);
//			COMMTIMEOUTS cto =  new COMMTIMEOUTS();
//			temp = GetCommTimeouts(hComm, ref cto);
//			Console.WriteLine("GetCommTimeOuts: " + temp);
//			Console.WriteLine("cto: Interval: " + cto.ReadIntervalTimeout + " Mult: " +
//					           cto.ReadTotalTimeoutMultiplier + " Const: " + cto.ReadTotalTimeoutConstant);
//		}


//		public byte[] Read(int NumBytes) {
//			byte[] BufBytes;
//			byte[] OutBytes;
//			BufBytes = new byte[NumBytes];
//			if (hComm!=INVALID_HANDLE_VALUE) {
//				OVERLAPPED ovlCommPort = new OVERLAPPED();
//				int BytesRead=0;
//				ReadFile(hComm,BufBytes,NumBytes,ref BytesRead,ref ovlCommPort);
//				OutBytes = new byte[BytesRead];
//				Array.Copy(BufBytes,OutBytes,BytesRead);
//			}
//			else {
//				throw(new ApplicationException("Comm Port Not Open"));
//			}
//			return OutBytes;
//		}


        // returns count of chars available to be read ... sort of a hack as this is using an ioctl
        // that is not in the documentation but does appear in the dd source
        // this is needed when using the MixW CommEmulDrv virt serial ports  becuse it does not respect
        // the SetCommTimeout values, so a read with no data avail will block forever
        //
        private uint checkIfCharsAvail()
        {
            UInt32 returned_count = SIZE_SERIAL_STATUS;

            if (!Opened)
            {
                return(0);
            }
            SERIAL_STATUS ss = new SERIAL_STATUS();
            // Console.WriteLine("Calling ioctl....");
            // Thread.Sleep(1000);
            Boolean result = DeviceIoControl(hComm, IOCTL_SERIAL_GET_COMMSTATUS,
                                             ref ss, SIZE_SERIAL_STATUS, ref ss, SIZE_SERIAL_STATUS, ref returned_count, (IntPtr)0);

            // Console.WriteLine("....ioctl returned");
            // Thread.Sleep(1000);
            if (result == false)
            {
                Console.WriteLine("JustinIO: IOControl failed!");
                return(0);
            }
            return(ss.AmountInInQueue);
        }
//		private void whackTimeouts() 
//		{
//			// SET THE COMM TIMEOUTS.
//			COMMTIMEOUTS ctoCommPort = new COMMTIMEOUTS(); 		
//			// GetCommTimeouts(hComm,ref ctoCommPort);
//
//			//		  ctoCommPort.ReadTotalTimeoutConstant = ReadTimeout;
//			//		  ctoCommPort.ReadTotalTimeoutMultiplier = 0;
//
//			ctoCommPort.ReadIntervalTimeout = UInt32.MaxValue;
//			ctoCommPort.ReadTotalTimeoutMultiplier = 0; 
//			ctoCommPort.ReadTotalTimeoutConstant = 0;
//			ctoCommPort.WriteTotalTimeoutMultiplier = 0;
//			ctoCommPort.WriteTotalTimeoutConstant = 0;  
//			bool temp = SetCommTimeouts(hComm,ref ctoCommPort);
//			Console.WriteLine("SetCommTimeOuts: " + temp); 
//			COMMTIMEOUTS cto =  new COMMTIMEOUTS(); 
//			temp = GetCommTimeouts(hComm, ref cto); 
//			Console.WriteLine("GetCommTimeOuts: " + temp); 
//			Console.WriteLine("cto: Interval: " + cto.ReadIntervalTimeout + " Mult: " + 
//					           cto.ReadTotalTimeoutMultiplier + " Const: " + cto.ReadTotalTimeoutConstant); 
//		}


//		public byte[] Read(int NumBytes) {
//			byte[] BufBytes;
//			byte[] OutBytes;
//			BufBytes = new byte[NumBytes];
//			if (hComm!=INVALID_HANDLE_VALUE) {
//				OVERLAPPED ovlCommPort = new OVERLAPPED();
//				int BytesRead=0;
//				ReadFile(hComm,BufBytes,NumBytes,ref BytesRead,ref ovlCommPort);
//				OutBytes = new byte[BytesRead];
//				Array.Copy(BufBytes,OutBytes,BytesRead);
//			} 
//			else {
//				throw(new ApplicationException("Comm Port Not Open"));
//			}
//			return OutBytes;
//		}


		// returns count of chars available to be read ... sort of a hack as this is using an ioctl
		// that is not in the documentation but does appear in the dd source 
		// this is needed when using the MixW CommEmulDrv virt serial ports  becuse it does not respect 
		// the SetCommTimeout values, so a read with no data avail will block forever 
		// 
		private uint checkIfCharsAvail() 
		{
			UInt32 returned_count = SIZE_SERIAL_STATUS; 
			if ( !Opened ) return 0; 
			SERIAL_STATUS ss = new SERIAL_STATUS(); 		
			// Console.WriteLine("Calling ioctl...."); 
			// Thread.Sleep(1000); 
			Boolean result = DeviceIoControl(hComm, IOCTL_SERIAL_GET_COMMSTATUS, 
				ref ss, SIZE_SERIAL_STATUS, ref ss, SIZE_SERIAL_STATUS, ref returned_count, (IntPtr)0); 
			// Console.WriteLine("....ioctl returned"); 
			// Thread.Sleep(1000); 
			if ( result == false ) 
			{
				Console.WriteLine("JustinIO: IOControl failed!"); 
				return 0;													  
			}
			return ss.AmountInInQueue; 
		}
		private static extern Boolean DeviceIoControl
			(
			int hfile, 
			UInt32 IOctlcode, 
			ref SERIAL_STATUS inbuf,          // fixme ... should not be specific 
			UInt32 inbufsize, 
			ref SERIAL_STATUS outbuf, // fixme .... this should not be specific 
			UInt32 outbufsize,
			ref UInt32 return_count, 
			IntPtr overlap
		    );