Advertisement
Guest User

Untitled

a guest
Mar 5th, 2015
205
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.25 KB | None | 0 0
  1. using System;
  2. using System.IO;
  3. using System.Drawing;
  4. using System.Windows.Forms;
  5. using System.Runtime.InteropServices;
  6.  
  7. public class PortAccessAPI
  8. {
  9. /// <summary>
  10. /// This method will be used to send the data out to the parallel port.
  11. /// </summary>
  12. /// <param name="adress">Address of the port to which the data needs to be sent.</param>
  13. /// <param name="value">Data that need to send out.</param>
  14.  
  15. [DllImport("inpout32.dll", EntryPoint="Out32")]
  16. public static extern void Output(int address, int value);
  17.  
  18. /// <summary>
  19. /// This method will be used to receive any data from the parallel port.
  20. /// </summary>
  21. /// <param name="address">Address of the port from which the data should be received.</param>
  22. /// <returns>Returns Integer read from the given port.</returns>
  23. [DllImport("inpout32.dll", EntryPoint = "Inp32")]
  24. public static extern int Input(int address);
  25. }
  26.  
  27.  
  28. partial class MainForm : Form
  29. {
  30.  
  31. void Button1Click(object sender, EventArgs e)
  32. {
  33.  
  34. int address = 888;
  35. int value = 24;
  36. PortAccessAPI.Output(address, value);
  37. value = PortAccessAPI.Input(address);
  38. label1.Text = Convert.ToString(value);
  39.  
  40. }
  41.  
  42. void MainFormLoad(object sender, EventArgs e)
  43. {
  44.  
  45.  
  46.  
  47. }
  48. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement