
wince6.0下怎么查看串口号
如果仅检测wince设备的串口是否正常,可以把串口的TX和RX短接,打开串口助手选择对应的串口号,波特率随意,随便发送什么数据如果收到的数据和发送的一样说明串口正常;如果是检测外部串口模块的好坏,需要知道模块的透明指令集,如果发送成功有对应数据帧返回就说明模块正常,每个外挂模块的指令集不一定相同
用C# 实现 wince 串口操作的方法
初始化代码: sp = new SerialPort(); sp.PortName = config.COMPort; sp.BaudRate = 9600; sp.DataBits = 8; sp.StopBits = StopBits.One; sp.Parity = Parity.None; sp.DataReceived += sp_dataReceive; sp.ReadTimeout = 500; try { sp.Open(); } catch (Exception e1) { if (MessageBox.Show(打开串口时失败, 工作站将不能正常读码, 是否继续?, 警告, MessageBoxButtons.YesNo) != DialogResult.Yes) { Close(); } }数据接收事件:public void sp_dataReceive(object sender, SerialDataReceivedEventArgs e) { int i = 0; byte[] data = new byte[20]; try { while (i < 20) data[i++] = (byte)sp.ReadByte(); } catch (Exception e1) { } if (tbBSM.Enabled) { strBsm = Encoding.ASCII.GetString(data, 0, i); if (strBsm.Length >= 10) { strBsm = strBsm.Substring(0, 10); } MethodInvoker mi = new MethodInvoker(updateBSM); this.BeginInvoke(mi); this.Invalidate(); } }
如何把wince Sate210 的调试串口改成普通串口
wince的调试串口作为普通串口使用 creator 目前wince的串口0是作为调试串口用的,但是因为我的案子需要3个串口,所以要把它改为普通串口,但是开机时候
wince系统串口接收数据不完整怎么办
C#串口读写程序方法具体如下:PortDataSend.cs 发送Classusing 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 = 0; i < BS.Length; i++) ...{ 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 mCountDataSendTest3#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 = 0; i < BSTest.Length; i++) ...{ BSTest[i] = (byte)Convert.ToInt32(mBSStr[i], 16); } BS = BSTest; DataSend(); } catch ...{ } } #endregion DataSendTest3}}PortDataReceived.cs 接收Classusing 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 = 0; i < mStartCount; i++) ...{ BR[i + mDataEnd] = BRTmp[i]; } mDataEnd = mDataEnd + mStartCount; } catch ...{ } if (mStartCount > 0) ...{ DT = System.DateTime.Now; } \\\/\\\/寻找并且校验SOH、STX、ETX的位置 for (int i = 0; i < BR.Length - 6; i++) ...{ 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 = 0; j < mSTXPos + mCmdLength + 1 - mSOHPos; j++) ...{ Data[j] = BR[mSOHPos + j]; } for (int j = 0; j < (mDataEnd - (mSTXPos + mCmdLength + 1)); j++) ...{ BR[j] = BR[(mSTXPos + mCmdLength + 1) + j]; } for (int j = (mDataEnd - (mSTXPos + mCmdLength + 1)); j < 2048; j++) ...{ 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 处理Classusing 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 = 0; i < pRD[7]; i++) ...{ for (int j = 0; j < 12; j++) ...{ 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 = 0; i < 12; i++) ...{ mSampleCode = mSampleCode + Convert.ToString(Convert.ToChar(pRD[8 + i])); } for (int i = 0; i < mData.Length; i++) ...{ 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 = 0; i < 12; i++) ...{ mSampleCode = mSampleCode + Convert.ToString(Convert.ToChar(pRD[8 + i])); } for (int i = 0; i < mData.Length; i++) ...{ mData[i] = pRD[i * 2 + 20] * 255 + pRD[i * 2 + 21]; } } catch (Exception Ex) ...{ throw Ex; } } catch ...{ } } #endregion ReadData_0X02_Request }}



