启动Visual Studio 2008
在菜单栏里:工具->连接到设备,d出“连接到设备”这个界面,在“平台”下拉列表里面选择为“Windows CE”,之后在显示出来的列表中选择“Pocket PC 2003 SE 仿真程序”,然后点击“连接”按钮。截图如下:
连接成功后,就d出了仿真模拟器的界面,界面完全就是一个掌上电脑,很不错哦!截图如下:
二、设置WinCE仿真模拟器的属性
如果想要上网,你一定要先装上Virtual PC 2007 setup.exe,然后再重新连接模拟器。Virtual PC直接装完就OK了,无需对其进行任何设置。
1、设置共享文件夹
单击模拟器界面中的菜单栏:文件->配置,在“仿真程序属性”界面中,“常规”选项卡里面,选择你的“共享文件夹”的目录。然后确定即可,最后要插入底座才生效哦。截图如下:
2、设置网络
再提一下,先要装Virtual PC 2007。(好啰嗦……呵呵)
进入“仿真程序属性”界面的“网络”选项卡,勾上“启用NE2000 PCMCIA网络适配器并绑定到”,下拉列表中选择“数据包计划程序微型端口”。确认即可,最后要插入底座才生效哦。当然,你还要在模拟器中设置网络连接的属性才能上网,一定要看完再 *** 作哦!
截图如下:
3、设置串口、耳机等
进入“仿真程序属性”界面的“外围设备”选项卡,勾上相应的选项即可。截图如下:
4、插入底座,使设置生效
在VS2008的菜单栏中,工具->设备仿真器管理,右击你目前正在用的“Pocket PC 2003 SE 仿真程序”,选择“连接”,然后再次右击,选择“插入底座”,现在你的模拟器就可以使用你的电脑上的那些网络、串口、耳机等资源了。截图如下:
5、设置WinCE模拟器中的网络连接属性
在WinCE模拟器界面中,开始->设置,选择下面的“连接”选项卡,单机“网卡”,在“我的网卡连接到”选项卡中选择“默认Internet设置”,并在其下的列表中选择“NE2000兼容Ethernet驱动程序”,然后选择“使用服务器分配的IP地址”,单击右上角的OK。最后,打开模拟器里面的IE,点击一个天线状的图标,选择网卡连接到“默认Internet设置”,然后你就可以上网了。
C#串口读写程序方法具体如下:PortDataSend.cs 发送Class
using System
using System.Collections.Generic
using System.Text
namespace IOCPTest.BaseC
...{
public class PortDataSend
...{
Declare#region Declare
private long mCount = 0
private int mDataLength = 0
private byte[] BS = null
#endregion Declare
PortDataSend#region PortDataSend
public PortDataSend()
...{
}
public PortDataSend(byte[] pBS, int pDataLength)
...{
BS = pBS
mDataLength = pDataLength
}
#endregion PortDataSend
DataSend#region DataSend
public void DataSend()
...{
try
...{
if (BS == null)
...{
return
}
if (mDataLength == 0)
...{
mDataLength = BS.Length
}
if (mDataLength == 0)
...{
return
}
mDataLength = mDataLength + 2
byte[] BST = new byte[mDataLength]
BST[BST.Length - 2] = 0x00
BST[BST.Length - 1] = 0x03
for (int i = 0i <BS.Lengthi++)
...{
BST[i] = BS[i]
BST[BST.Length - 2] = (byte)(BST[BST.Length - 2] ^ BS[i])
}
IOCPTest.BaseC.GlobeValues.SP.Write(BST, 0, BST.Length)
mCount++
mDataLength = 0
}
catch
...{
}
}
#endregion DataSend
mCount#region mCount
public long GetCount
...{
get
...{
return mCount
}
}
#endregion mCount
DataSendTest3#region DataSendTest3
public void DataSendTest3()
...{
try
...{
byte[] BSTest
string[] mBSStr = Convert.ToString("01 02 03 01 00 3A 02 03 31 31 31 31 31 31 31 31 31 31 31 31 2C 00 01 2C 00 64 3B 32 32 32 32 32 32 32 32 32 32 32 32 2C 00 01 2C 00 64 3B 33 33 33 33 33 33 33 33 33 33 33 33 2C 00 01 2C 00 64 3B").Split(' ')
BSTest = new byte[mBSStr.Length]
for (int i = 0i <BSTest.Lengthi++)
...{
BSTest[i] = (byte)Convert.ToInt32(mBSStr[i], 16)
}
BS = BSTest
DataSend()
}
catch
...{
}
}
#endregion DataSendTest3
}
}
PortDataReceived.cs 接收Class
using System
using System.Collections.Generic
using System.Text
namespace IOCPTest.BaseC
...{
class PortDataReceived
...{
Declare#region Declare
private long mCount = 0
private int mDataEnd = 0
private byte[] BR = new byte[2048]
private byte[] BRTmp = new byte[2048]
private byte mSOH = 0x01 //通讯特殊字符定义:通讯字头
private byte mSTX = 0x02 //通讯特殊字符定义:数据开始
private byte mETX = 0x03 //通讯特殊字符定义:通讯结束
#endregion Declare
PortDataReceived#region PortDataReceived
public PortDataReceived()
...{
}
#endregion PortDataReceived
Listen#region Listen
public byte[] Listen()
...{
try
...{
byte[] BR = ReceiveData()
return BR
}
catch (NullReferenceException NullEx)
...{
throw NullEx
}
catch (Exception ex)
...{
throw ex
}
}
#endregion Listen
ReceiveData#region ReceiveData
public byte[] ReceiveData()
...{
try
...{
int mStartCount = 0
int mSOHPos = 0
int mSTXPos = 0
int mETXPos = 0
int mCmdLength = 0
System.DateTime DT = System.DateTime.Now
byte[] Data = null
BRTmp = new byte[2048]
while((System.DateTime.Now.Ticks - DT.Ticks) <IOCPTest.BaseC.GlobeValues.PortTimeOut)
...{
try
...{
mStartCount = 0
//System.Threading.Thread.Sleep(IOCPTest.BaseC.GlobeValues.PortDelay)
mStartCount = IOCPTest.BaseC.GlobeValues.SP.Read(BRTmp, 0, 2048)
for (int i = 0i <mStartCounti++)
...{
BR[i + mDataEnd] = BRTmp[i]
}
mDataEnd = mDataEnd + mStartCount
}
catch
...{
}
if (mStartCount >0)
...{
DT = System.DateTime.Now
}
//寻找并且校验SOH、STX、ETX的位置
for (int i = 0i <BR.Length - 6i++)
...{
if((BR[i] == mSOH) &&(BR[i+6] == mSTX))
...{
mSOHPos = i
mSTXPos = i+6
mCmdLength = (int)BR[i+4] * 256 + (int)BR[i+5]
mETXPos = mSTXPos + mCmdLength + 2
if (BR[mETXPos] == mETX)
...{
Data = new byte[mSTXPos + mCmdLength + 1 - mSOHPos]
for (int j = 0j <mSTXPos + mCmdLength + 1 - mSOHPosj++)
...{
Data[j] = BR[mSOHPos + j]
}
for (int j = 0j <(mDataEnd - (mSTXPos + mCmdLength + 1))j++)
...{
BR[j] = BR[(mSTXPos + mCmdLength + 1) + j]
}
for (int j = (mDataEnd - (mSTXPos + mCmdLength + 1))j <2048j++)
...{
BR[j] = 0x00
}
mDataEnd = mDataEnd - (mSTXPos + mCmdLength + 1)
IOCPTest.BaseC.GlobeValues.DataBuffer.Add(Data)
mCount++
return Data
}
}
}
}
return null
}
catch (NullReferenceException NullEx)
...{
throw NullEx
}
catch (Exception ex)
...{
throw ex
}
}
#endregion ReceiveData
ReceiveDataNonReturn#region ReceiveDataNonReturn
public void ReceiveDataNonReturn()
...{
try
...{
ReceiveData()
}
catch
...{
}
}
#endregion ReceiveData
ReceiveDataThread#region ReceiveDataThread
public void ReceiveDataThread()
...{
try
...{
while (true)
...{
try
...{
ReceiveData()
}
catch
...{
}
}
}
catch
...{
}
}
#endregion ReceiveData
mCount#region mCount
public long GetCount
...{
get
...{
return mCount
}
}
#endregion mCount
}
}
DataProcessingIOCP.cs 处理Class
using System
using System.Collections.Generic
using System.Text
namespace IOCPTest.BaseC
...{
public class DataProcessingIOCP
...{
Declare#region Declare
private long mCount = 0
#endregion Declare
DataProcessingIOCP#region DataProcessingIOCP
public DataProcessingIOCP()
...{
}
#endregion DataProcessingIOCP
DataProcessing#region DataProcessing
public void DataProcessing()
...{
try
...{
int mCurrentBuffer = 0
while (true)
...{
byte[] RD = null
提取正待处理的数据#region 提取正待处理的数据
if (IOCPTest.BaseC.GlobeValues.DataBuffer != null)
...{
if (IOCPTest.BaseC.GlobeValues.DataBuffer.Count >0)
...{
if (mCurrentBuffer <0)
...{
mCurrentBuffer = 0
}
RD = (byte[])IOCPTest.BaseC.GlobeValues.DataBuffer[mCurrentBuffer]
mCurrentBuffer++
}
else
...{
continue
}
}
else
...{
continue
}
#endregion 提取正待处理的数据
数据处理#region 数据处理
switch (RD[3]) //指令处理
...{
case 0x01:
ReadData_0X01(RD)
break
case 0x02:
ReadData_0X02(RD)
break
}
#endregion 数据处理
处理结束,删除已经处理了的数据#region 处理结束,删除已经处理了的数据
if (IOCPTest.BaseC.GlobeValues.DataBuffer != null)
...{
if (IOCPTest.BaseC.GlobeValues.DataBuffer.Count >0)
...{
IOCPTest.BaseC.GlobeValues.DataBuffer.Remove(RD)
}
}
mCurrentBuffer--
if (mCurrentBuffer <0)
...{
mCurrentBuffer = 0
}
#endregion 处理结束,删除已经处理了的数据
mCount++
}
}
catch
...{
}
}
#endregion DataProcessing
mCount#region mCount
public long GetCount
...{
get
...{
return mCount
}
}
#endregion mCount
ReadData_0X01#region ReadData_0X01
private void ReadData_0X01(byte[] pRD)
...{
try
...{
try
...{
if (pRD[3] != 0x01)
...{
return
}
string[] mSampleCode = new string[pRD[7]]
int[] mTesterType = new int[pRD[7]]
int[] mLoadCapacity = new int[pRD[7]]
for (int i = 0i <pRD[7]i++)
...{
for (int j = 0j <12j++)
...{
mSampleCode[i] = mSampleCode[i] + Convert.ToString(Convert.ToChar(pRD[8 + j + i * 19]))
}
mTesterType[i] = pRD[i * 19 + 21] * 255 + pRD[i * 19 + 22]
mLoadCapacity[i] = pRD[i * 19 + 24] * 255 + pRD[i * 19 + 25]
}
return
}
catch (Exception Ex)
...{
throw Ex
}
}
catch
...{
}
}
#endregion ReadData_0X01
ReadData_0X02#region ReadData_0X02
private void ReadData_0X02(byte[] pRD)
...{
try
...{
try
...{
if (pRD[3] != 0x02)
...{
return
}
int[] mData = new int[pRD[7]]
string mSampleCode = ""
for (int i = 0i <12i++)
...{
mSampleCode = mSampleCode + Convert.ToString(Convert.ToChar(pRD[8 + i]))
}
for (int i = 0i <mData.Lengthi++)
...{
mData[i] = pRD[i * 2 + 20] * 255 + pRD[i * 2 + 21]
}
}
catch (Exception Ex)
...{
throw Ex
}
}
catch
...{
}
}
#endregion ReadData_0X02
ReadData_0X02_Request#region ReadData_0X02_Request
private void ReadData_0X02_Request(byte[] pRD)
...{
try
...{
try
...{
if (pRD[3] != 0x02)
...{
return
}
int[] mData = new int[pRD[7]]
string mSampleCode = ""
for (int i = 0i <12i++)
...{
mSampleCode = mSampleCode + Convert.ToString(Convert.ToChar(pRD[8 + i]))
}
for (int i = 0i <mData.Lengthi++)
...{
mData[i] = pRD[i * 2 + 20] * 255 + pRD[i * 2 + 21]
}
}
catch (Exception Ex)
...{
throw Ex
}
}
catch
...{
}
}
#endregion ReadData_0X02_Request
}
}
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)