コード例 #1
0
ファイル: FormTerminal.cs プロジェクト: mnisl/OD
		/// <summary></summary>
		public FormTerminal()
		{
			//
			// Required for Windows Form Designer support
			//
			InitializeComponent();
			moRS232 = new Rs232();
			moRS232.Port=1;
			moRS232.BaudRate=9600;
			moRS232.DataBit=8;
			moRS232.StopBit=Rs232.DataStopBit.StopBit_1;
			moRS232.Parity=Rs232.DataParity.Parity_None;
			moRS232.Timeout=1500;
			moRS232.CommEvent+=new Rs232.CommEventHandler(moRS232_CommEvent);
		}
コード例 #2
0
ファイル: FormTerminal.cs プロジェクト: nampn/ODental
 ///<summary>Events raised when a communication event occurs.</summary>
 private void moRS232_CommEvent(Rs232 source, Rs232.EventMasks Mask)
 {
     if ((Mask & Rs232.EventMasks.RxChar) > 0)
     {
         StringBuilder strBuilder = new StringBuilder();
         //loop through each new char and handle it.
         for (int i = 0; i < source.InputStream.Length; i++)
         {
             RxBuff.Append((char)source.InputStream[i]);
             if (IsSpecialCode((char)source.InputStream[i]))
             {
                 strBuilder.Append(DisplaySpecialCode((char)source.InputStream[i]));
             }
             else
             {
                 strBuilder.Append((char)source.InputStream[i]);
             }
         }
         textRx.Text += strBuilder.ToString();
     }
 }
コード例 #3
0
ファイル: FormTerminal.cs プロジェクト: mnisl/OD
		///<summary>Events raised when a communication event occurs.</summary>
		private void moRS232_CommEvent(Rs232 source,Rs232.EventMasks Mask){
			if((Mask & Rs232.EventMasks.RxChar) > 0){
				StringBuilder strBuilder=new StringBuilder();
				//loop through each new char and handle it.
				for(int i=0;i<source.InputStream.Length;i++){
					RxBuff.Append((char)source.InputStream[i]);
					if(IsSpecialCode((char)source.InputStream[i])){
						strBuilder.Append(DisplaySpecialCode((char)source.InputStream[i]));
					}
					else{
						strBuilder.Append((char)source.InputStream[i]);
					}
				}
				textRx.Text+=strBuilder.ToString();
			}
    }
コード例 #4
0
ファイル: ScannerCOMUseEvent.cs プロジェクト: lzhice/test
        private void _RS232_DataReceived(Rs232 Source, byte[] DataBuffer)
        {
            mScannerTimeout.Stop();
            //接受到了数据
            //校验数据
            if (DataBuffer.Length != 5)
            {
                Source.ClearInputBuffer();
                StartNextCheckInformationRequest();
                return;
            }
            byte[] ReceiveData = DataBuffer;

            //Special CheckSum校验
            int CheckSumFlag = 0;

            for (int i = 1; i <= ReceiveData.Length - 2; i++)
            {
                CheckSumFlag += ReceiveData[i];
            }

            if ((byte)(CheckSumFlag % 256) != ReceiveData[ReceiveData.Length - 1])
            {
                StartNextCheckInformationRequest(); return;
            }
            ;
            if ((256 - (mCurrentRoom.Number + mCurrentRoom.MyFloor.Number) % 256) != ReceiveData[0])
            {
                StartNextCheckInformationRequest(); return;
            }
            ;

            if (mCurrentReceiveDataCheckRepeatTimes == 0)
            {
                mReceiveCheckData = ReceiveData;
            }
            else
            {
                //判断是不是与前几次相同
                if (!Utility.ArrayDataEquals(mReceiveCheckData, ReceiveData))
                {
                    StartNextCheckInformationRequest(); return;
                }
                ;
            }

            //下一步
            mCurrentReceiveDataCheckRepeatTimes++;
            if (mCurrentReceiveDataCheckRepeatTimes >= mReceiveDataCheckRepeatTimes)
            {
                //数据都正确
                ApplyData();
                //判断是否断网
                if (mDisconnectList[mCurrentRoom.ToString()] != null)
                {
                    mDisconnectList.Remove(mCurrentRoom.ToString());
                }
                mCurrentRoom.MyATM.Connect();

                //延时一段时间再查询下一个房间
                mScanNextRoomDelay.Start();
            }
            else
            {
                //下一次校验查询
                mScannerTimeout.Start();
                SendRequestRoomInformationData();
            }
        }