Form1.cs 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. using System;
  2. using System.Runtime.InteropServices;
  3. using System.Windows.Forms;
  4. using UAS_MES_NEW.PublicMethod;
  5. namespace UAS_MES_NEW
  6. {
  7. public partial class Form1 : Form
  8. {
  9. public Form1()
  10. {
  11. InitializeComponent();
  12. }
  13. private void Form1_Load(object sender, EventArgs e)
  14. {
  15. //Com.PortName = "COM4";
  16. //Com.ReadTimeout = 5000;
  17. //Com.WriteTimeout = 5000;
  18. //Com.BaudRate = 9600;
  19. //Com.StopBits = StopBits.One;
  20. //Com.Parity = Parity.None;
  21. }
  22. [DllImport("WinIo64.dll")]
  23. public static extern bool InitializeWinIo();
  24. [DllImport("WinIo64.dll")]
  25. public static extern void ShutdownWinIo();
  26. [DllImport("WinIo64.dll")]
  27. public static extern bool GetPortVal(IntPtr wPortAddr, out int pdwPortVal, byte bSize);
  28. [DllImport("WinIo64.dll")]
  29. public static extern bool SetPortVal(IntPtr wPortAddr, int dwPortVal, byte bSize);
  30. //以下是与并口无关
  31. [DllImport("WinIo64.dll")]
  32. public static extern byte MapPhysToLin(byte pbPhysAddr, uint dwPhysSize, IntPtr PhysicalMemoryHandle);
  33. [DllImport("WinIo64.dll")]
  34. public static extern bool UnmapPhysicalMemory(IntPtr PhysicalMemoryHandle, byte pbLinAddr);
  35. [DllImport("WinIo64.dll")]
  36. public static extern bool GetPhysLong(IntPtr pbPhysAddr, byte pdwPhysVal);
  37. [DllImport("WinIo64.dll")]
  38. public static extern bool SetPhysLong(IntPtr pbPhysAddr, byte dwPhysVal);
  39. [DllImport("user32.dll")]
  40. public static extern int MapVirtualKey(uint Ucode, uint uMapType);
  41. public bool online = false; //WinIo打开标志
  42. //数据端口共8位,控制端口共4位,可以组成1~12位的任意数字输出端口;
  43. //状态端口共5位,控制端口共4位,可以组成1~9位的任意数字输入端口
  44. private static IntPtr data_port = (IntPtr)0x378; //数据端口地址 D0-D7 8个端口
  45. private static IntPtr state_port = (IntPtr)0x379; //状态端口地址 S3-S7 只能读取5位
  46. private static IntPtr control_port = (IntPtr)0x37A; //控制端口地址 C0-C3 只能控制或输出4位
  47. ModeBusTCPServer md;
  48. private void button3_Click_1(object sender, EventArgs e)
  49. {
  50. md = new ModeBusTCPServer();
  51. md.Open();
  52. txtMsg.AppendText("SUCCESS");
  53. }
  54. private void button4_Click(object sender, EventArgs e)
  55. {
  56. md.SendOrder(enterTextBox2.Text);
  57. }
  58. }
  59. }