|
to:BEYONDMA
操作代码如下:
common.IOFile.SetInfo Setinfo = new IOtest.common.IOFile.SetInfo();
Setinfo.address = 0x200; //设置IO板基地址
Setinfo.data = new byte[4];
Setinfo.data[0] = Convert.ToByte(this.tb1.Text.ToString().Trim()); //这里得到输入的数字,下同
Setinfo.data[1] = Convert.ToByte(this.tb2.Text.ToString().Trim());
Setinfo.data[2] = Convert.ToByte(this.tb3.Text.ToString().Trim());
Setinfo.data[3] = Convert.ToByte(this.tb4.Text.ToString().Trim());
if (common.IOFile.WriteFile(HandlePtr,ref Setinfo, ref HasWriten))
{
this.lbState.Text = HasWriten + " bytes data have writen to the IOBoard !";
}
else
{
this.lbState.Text = "Some Error ocurred ,can not write to the IOBoard !";
}
SetInfo结构体如下
public struct SetInfo
{
public ulong address;
public byte[] data;
}
申明的writefile如下:
[DllImport("coredll.dll")]
private static extern bool WriteFile(
System.IntPtr h_comm, // file name
ref SetInfo text,
System.UInt32 length,
ref int length2,
int overlap
);
重载了一次:
public static bool WriteFile(System.IntPtr HandleName,ref SetInfo buffer,ref int length)
{
UInt32 TotalSize = 96;
return WriteFile(HandleName,ref buffer,TotalSize,ref length,0);
}
如果不是这与写的话,
在C#里我该怎么写呢?
谢谢! |
|