private MCPacket CreatePacket() { var packet = new MCPacket(); var subHeader = new MCSubHeader3E(); packet.SubHeader = subHeader; var qHeader = new MCQHeaderRequest(); this.SetupQHeader(qHeader); qHeader.Watchdog = 0; packet.QHeader = qHeader; return(packet); }
private void Connection() { try { while (true) { using (var sw = new StreamWrapper(this.Stream)) { try { MCPacket request = null; MCErrorCode errorCode = MCErrorCode.None; MCFunction responseFunction = null; try { request = this.Parent.Slave.Protocol.ReadPacket(sw, null); errorCode = this.ProcessPacket(request.Function, out responseFunction); } catch (MCProtocolException e) { errorCode = e.ErrorCode; responseFunction = null; } catch (IOException) { throw; } catch (ThreadInterruptedException) { throw; } catch (Exception) { errorCode = MCErrorCode.UnkownRequest; responseFunction = null; } var response = new MCPacket(); response.SubHeader = request.SubHeader; response.QHeader = this.CreateResponseQHeader(request.QHeader, errorCode); response.Function = this.GetResponseFunction(request.QHeader, errorCode, request.Function, responseFunction); this.Parent.Slave.Protocol.WritePacket(sw, response); } finally { var mco = this.Parent.Slave; var datas = mco.MemoryMap.Get(DeviceCode.D, 500, 32); Console.Clear(); Console.WriteLine("status : " + datas[3]); var position = new BitNumber2Words(new BitShort(), new BitShort()); position.UpperWord.Raw32 = datas[4]; position.LowerWord.Raw32 = datas[5]; Console.WriteLine("Position : " + position.Value); var force = new BitNumber2Words(new BitShort(), new BitShort()); force.UpperWord.Raw32 = datas[6]; force.LowerWord.Raw32 = datas[7]; Console.WriteLine("Force : " + force.Value); for (int i = 0; i < datas.Length; i++) { //Console.WriteLine(i.ToString("D2") + " : " + datas[i].ToString("X4")); } //this.Logger.OnCommunicationLog(sw.Log); } } } } catch (Exception e) { this.Logger.OnMessageLog(e.ToString()); } this.Close(); }