Ответы пользователя по тегу Программирование
  • Как научить ребёнка программировать?

    Myrkr
    @Myrkr
    Видел книги по программированию для самых маленьких на BASIC, времен еще наверное совка (хотя скорее это был перевод), книга с картинками, играми и тому подобным, интересно сейчас такие выпускают?
    Ответ написан
    Комментировать
  • Как правильно принимать данные по LPT?

    Myrkr
    @Myrkr
    Нет ничего особо сложного в том чтобы общаться с драйвером
    Сами драйверы можно скачать Тут
    А удобный класс для работы с ними вот.

    using System;
    using System.Runtime.InteropServices;
    
    namespace PortAccess {
    	public class ParallelPort {
    		[DllImport("inpout32.dll")]
    		private static extern UInt32 IsInpOutDriverOpen();
    		[DllImport("inpout32.dll")]
    		private static extern void Out32(short portAddress, short data);
    		[DllImport("inpout32.dll")]
    		private static extern char Inp32(short portAddress);
    		[DllImport("inpout32.dll")]
    		private static extern void DlPortWritePortUshort(short portAddress, ushort data);
    		[DllImport("inpout32.dll")]
    		private static extern ushort DlPortReadPortUshort(short portAddress);
    		[DllImport("inpout32.dll")]
    		private static extern void DlPortWritePortUlong(int portAddress, uint data);
    		[DllImport("inpout32.dll")]
    		private static extern uint DlPortReadPortUlong(int portAddress);
    
    		[DllImport("inpoutx64.dll")]
    		private static extern bool GetPhysLong(ref int portAddress, ref uint data);
    		[DllImport("inpoutx64.dll")]
    		private static extern bool SetPhysLong(ref int portAddress, ref uint data);
    		[DllImport("inpoutx64.dll", EntryPoint = "IsInpOutDriverOpen")]
    		private static extern UInt32 IsInpOutDriverOpenmode();
    		[DllImport("inpoutx64.dll", EntryPoint = "Out32")]
    		private static extern void Out32mode(short portAddress, short data);
    		[DllImport("inpoutx64.dll", EntryPoint = "Inp32")]
    		private static extern char Inp32mode(short portAddress);
    		[DllImport("inpoutx64.dll", EntryPoint = "DlPortWritePortUshort")]
    		private static extern void DlPortWritePortUshortmode(short portAddress, ushort data);
    		[DllImport("inpoutx64.dll", EntryPoint = "DlPortReadPortUshort")]
    		private static extern ushort DlPortReadPortUshortmode(short portAddress);
    		[DllImport("inpoutx64.dll", EntryPoint = "DlPortWritePortUlong")]
    		private static extern void DlPortWritePortUlongmode(int portAddress, uint data);
    		[DllImport("inpoutx64.dll", EntryPoint = "DlPortReadPortUlong")]
    		private static extern uint DlPortReadPortUlongmode(int portAddress);
    		[DllImport("inpoutx64.dll", EntryPoint = "GetPhysLong")]
    		private static extern bool GetPhysLongmode(ref int portAddress, ref uint data);
    		[DllImport("inpoutx64.dll", EntryPoint = "SetPhysLong")]
    		private static extern bool SetPhysLongmode(ref int portAddress, ref uint data);
    
    		private bool mode;
    		private short portAddress;
    
    		public ParallelPort(short portAddress) {
    			mode = false;
    			this.portAddress = portAddress;
    			try {
    				uint nResult = 0;
    				try {
    					nResult = IsInpOutDriverOpen();
    				}
    				catch (BadImageFormatException) {
    					nResult = IsInpOutDriverOpenmode();
    					if (nResult != 0) {
    						mode = true;
    					}
    				}
    				if (nResult == 0 ) {
    					throw new ArgumentException("Unable to open InpOut32 driver");
    				}
    			}
    			catch (DllNotFoundException) {
    				throw new ArgumentException("Unable to find InpOut32.dll");
    			}
    		}
    
    		public void Write(short data) {
    			if (mode) {
    				Out32mode(portAddress, data);
    			}
    			else {
    				Out32(portAddress, data);
    			}
    		}
    
    		public byte Read() {
    			if (mode) {
    				return (byte)Inp32mode(portAddress);
    			}
    			else {
    				return (byte)Inp32(portAddress);
    			}
    		}
    	}
    }
    
    Ответ написан
    Комментировать