private void CreateOneRow(SensactApplicationContainer sac, MethodInfo mi, TableLayoutPanel functionTable, int functionTableRow) { Button btn = CreateCommandButton(sac, mi); functionTable.Controls.Add(btn, 0, functionTableRow); functionTable.RowStyles.Add(new RowStyle(SizeType.Absolute, 40)); Config.CommandType ct = Config.CommandType.NOP; if (!Enum.TryParse <Config.CommandType>(SensactApplication.ExtractCmdName(mi), out ct)) { throw new Exception("Method name " + mi.Name + " that ist marked as SensactCommand cannot be parsed into a CommandType"); } CommandSpecification cmdSpec = new CommandSpecification { applicationIdAsUshort = (ushort)sac.Index, CommandIdAsInt = (byte)ct, }; FlowLayoutPanel flowLayoutPanel = new FlowLayoutPanel { FlowDirection = FlowDirection.LeftToRight }; foreach (ParameterInfo p in mi.GetParameters()) { flowLayoutPanel.Controls.Add(CreateParamNameLabel(p.Name)); Control inp = null; if (IsDecimalType(p.ParameterType)) { inp = CreateDecimalParamInput(p); } else { throw new NotSupportedException("Only decimal parameter types are supported"); } flowLayoutPanel.Controls.Add(inp); cmdSpec.C2Ps.Add(new Control2Parameter { TheControl = inp, TheParameter = p }); } name2cmdSpec[btn.Name] = cmdSpec; functionTable.Controls.Add(flowLayoutPanel, 1, functionTableRow); }
private void cmdButton_Click(object sender, EventArgs e) { CommandSpecification cmdSpec = name2cmdSpec[(sender as Control).Name]; byte[] buffer = new byte[100]; buffer[0] = 0x01; //0x01==START_OF_HEADING buffer[1] = 0x00; // Length EndianBitConverter.Little.CopyBytes((ushort)0x00, buffer, 2); //WRITE_CAN EndianBitConverter.Little.CopyBytes(cmdSpec.applicationIdAsUshort, buffer, 4); byte pos = 6; buffer[pos] = cmdSpec.CommandIdAsInt; pos += 1; foreach (var cmd in cmdSpec.C2Ps) { AddParam(buffer, cmd, ref pos); } buffer[1] = pos; commPort.Write(buffer, 0, pos); return; }