private void REQUEST_TYPE() { //запрос верификации //List<object> list = myArray.Cast<Object>().ToList(); int readCount = 14; int sleep = Convert.ToInt32(0.1 * TimeOut); dataSend = createStartMessageTEM(this.Adress); //Channelref.DiscardInBuffer(); Channelref.WritePort(dataSend, 0, dataSend.Length); Channelref.addLog(Channelref.createLogStr(ref dataSend), Channel.LogType.TX); for (int i = 0; i < 10; i++) { if (Channelref.BytesToRead == readCount) { dataRead = new byte[readCount]; Channelref.ReadPort(ref dataRead, 0, readCount); Channelref.addLog(Channelref.createLogStr(ref dataRead), Channel.LogType.RX); //List<byte> list = dataRead.Cast<byte>().ToList(); if (dataRead[0] == 0xAA && dataRead[1] == dataSend[1] && dataRead[2] == dataSend[2] && dataRead[3] == dataSend[3] && dataRead[4] == dataSend[4]) { if (!CHEK_SUMM(dataRead, readCount)) { _state = State_thread.CLOSE; Console.Write(" :ERROR CHECK SUMM "); return; } else { if (type_msg[0] == dataRead[6] && type_msg[1] == dataRead[7] && type_msg[2] == dataRead[8] && type_msg[3] == dataRead[9] && type_msg[4] == dataRead[10] && type_msg[5] == dataRead[11] && type_msg[6] == dataRead[12]) { _state = State_thread.NEXT_DATA; return; } else { _state = State_thread.CLOSE; Console.Write(" :INCORRECT TYPE TEM "); return; } } } else { _state = State_thread.CLOSE; Console.Write(" :INCORRECT ANSWER "); return; } } else { Thread.Sleep(sleep); } } _state = State_thread.NEXT_DATA; }
private void REQUEST_2K_DATA(int count, byte bH, byte bL) { //int readCount = 74; //int sleep = Convert.ToInt32(0.1 * TimeOut); //byte[] dataSend = createStartMessageTEM(this.Adress); //Channelref.DiscardInBuffer(); //Channelref.WritePort(dataSend, 0, dataSend.Length); //Channelref.addLog(Channelref.createLogStr(ref dataSend), Channel.LogType.TX); //_channel.DiscardInBuffer(); //_channel.DiscardOutBuffer(); int readCount = count + 7; int sleep = Convert.ToInt32(0.1 * TimeOut); dataSend = create2KMessageTEM(this.Adress, bH, bL, Convert.ToByte(count)); //Channelref.DiscardInBuffer(); Channelref.WritePort(dataSend, 0, dataSend.Length); Channelref.addLog(Channelref.createLogStr(ref dataSend), Channel.LogType.TX); for (int i = 0; i < 10; i++) { if (Channelref.BytesToRead == readCount) { dataRead = new byte[readCount]; Channelref.ReadPort(ref dataRead, 0, readCount); Channelref.addLog(Channelref.createLogStr(ref dataRead), Channel.LogType.RX); //List<byte> list = dataRead.Cast<byte>().ToList(); if (dataRead[0] == 0xAA && dataRead[1] == dataSend[1] && dataRead[2] == dataSend[2] && dataRead[3] == dataSend[3] && dataRead[4] == dataSend[4]) { if (!CHEK_SUMM(dataRead, readCount)) { _state = State_thread.CLOSE; Console.Write(" :ERROR CHECK SUMM "); return; } else { _state = State_thread.NEXT_DATA; Buffer.BlockCopy(dataRead, 6, memoryTimer, 64 * (numBlocks - 1), count); return; } } else { _state = State_thread.CLOSE; Console.Write(" :INCORRECT ANSWER "); return; } } else { Thread.Sleep(sleep); } } _state = State_thread.NEXT_DATA; }