1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768 |
- using System;
- using System.Runtime.InteropServices;
- using System.Windows.Forms;
- using UAS_MES_NEW.PublicMethod;
- namespace UAS_MES_NEW
- {
- public partial class Form1 : Form
- {
- public Form1()
- {
- InitializeComponent();
- }
- private void Form1_Load(object sender, EventArgs e)
- {
- //Com.PortName = "COM4";
- //Com.ReadTimeout = 5000;
- //Com.WriteTimeout = 5000;
- //Com.BaudRate = 9600;
- //Com.StopBits = StopBits.One;
- //Com.Parity = Parity.None;
- }
- [DllImport("WinIo64.dll")]
- public static extern bool InitializeWinIo();
- [DllImport("WinIo64.dll")]
- public static extern void ShutdownWinIo();
- [DllImport("WinIo64.dll")]
- public static extern bool GetPortVal(IntPtr wPortAddr, out int pdwPortVal, byte bSize);
- [DllImport("WinIo64.dll")]
- public static extern bool SetPortVal(IntPtr wPortAddr, int dwPortVal, byte bSize);
- //以下是与并口无关
- [DllImport("WinIo64.dll")]
- public static extern byte MapPhysToLin(byte pbPhysAddr, uint dwPhysSize, IntPtr PhysicalMemoryHandle);
- [DllImport("WinIo64.dll")]
- public static extern bool UnmapPhysicalMemory(IntPtr PhysicalMemoryHandle, byte pbLinAddr);
- [DllImport("WinIo64.dll")]
- public static extern bool GetPhysLong(IntPtr pbPhysAddr, byte pdwPhysVal);
- [DllImport("WinIo64.dll")]
- public static extern bool SetPhysLong(IntPtr pbPhysAddr, byte dwPhysVal);
- [DllImport("user32.dll")]
- public static extern int MapVirtualKey(uint Ucode, uint uMapType);
- public bool online = false; //WinIo打开标志
- //数据端口共8位,控制端口共4位,可以组成1~12位的任意数字输出端口;
- //状态端口共5位,控制端口共4位,可以组成1~9位的任意数字输入端口
- private static IntPtr data_port = (IntPtr)0x378; //数据端口地址 D0-D7 8个端口
- private static IntPtr state_port = (IntPtr)0x379; //状态端口地址 S3-S7 只能读取5位
- private static IntPtr control_port = (IntPtr)0x37A; //控制端口地址 C0-C3 只能控制或输出4位
- ModeBusTCPServer md;
- private void button3_Click_1(object sender, EventArgs e)
- {
- md = new ModeBusTCPServer();
- md.Open();
- txtMsg.AppendText("SUCCESS");
- }
- private void button4_Click(object sender, EventArgs e)
- {
- md.SendOrder(enterTextBox2.Text);
- }
- }
- }
|