private void ScanNet() { lock (_hyperTerminal) { _flagScanI = (int)EFlagState.Yes; Modules.Clear(); for (byte address10 = _beginAddress; address10 <= _endAddress; address10++) { if (_actionUpdateView != null) { _actionUpdateView(address10.ToString()); } string address = NewModuleAbstract.ByteToHex(address10); string stIn = _dlgSendCommand("$" + address + "2"); if ((stIn.Length == 9) && (stIn.StartsWith("!" + address))) { stIn = _dlgSendCommand("$" + address + "M"); if ((stIn.Length > 3) && (stIn.StartsWith("!" + address))) { string mod = stIn.Substring(3); NewModuleAbstract newModule = null; switch (mod) { case "4019P": newModule = new NewModuleAdam4019Plus(Modules, address); break; } if (newModule != null) { newModule.ReadModuleSettings(); Modules.AddModule(address, newModule); if (EventNewModuleFind != null) { EventNewModuleFind(address); } } } } //if ((_flagScan == EFlagState.Stop) || (address10 == 255)) break; if ((_flagScanI == (int)EFlagState.Stop) || (address10 == 255)) { break; } } if (_actionUpdateView != null) { _actionUpdateView(null); } //_flagScan = EFlagState.No; _flagScanI = (int)EFlagState.No; } }
public bool ContainsAddress(string address) { byte?address10 = NewModuleAbstract.HexToByte(address); if (address10 != null) { return(ContainsAddress((byte)address10)); } return(false); }
public bool DeleteModule(string address) { byte?address10 = NewModuleAbstract.HexToByte(address); if (address10 != null) { return(DeleteModule((byte)address10)); } return(false); }
public bool AddModule(string address, NewModuleAbstract module) { byte?address10 = NewModuleAbstract.HexToByte(address); if (address10 != null) { return(AddModule((byte)address10, module)); } return(false); }
public bool AddModule(byte address10, NewModuleAbstract module) { if (!ContainsAddress(address10)) { _modules.Add(module); module.Address10 = address10; return(true); } return(false); }
private string GetFf() { //Возвращает подстроку FF в команде $AA2 //--var b = (byte) ((ClassAbstractAdamModule.HexToByte(_dataFormat) ?? 0) + //-- (_checkSumStatus ? Math.Pow(2, 6) : 0) + (_integrationTime ? Math.Pow(2, 7) : 0)); //--return ClassAbstractAdamModule.ByteToHex(b); var b = (byte)((NewModuleAbstract.HexToByte(_dataFormat) ?? 0) + (_checkSumStatus ? Math.Pow(2, 6) : 0) + (_integrationTime ? Math.Pow(2, 7) : 0)); return(NewModuleAbstract.ByteToHex(b)); }
private void ScanVirtualNet() { for (byte i = 0; i <= 255; i++) { //--string addr = ClassAbstractAdamModule.ByteToHex(i); string addr = NewModuleAbstract.ByteToHex(i); string stIn = Program.Net.VirtSendCommand("$" + addr + "M"); GroupBox groupBox; if ((i >= 0) && (i <= 31)) { groupBox = gb001F; } else if ((i >= 32) && (i <= 63)) { groupBox = gb203F; } else if ((i >= 64) && (i <= 95)) { groupBox = gb405F; } else if ((i >= 96) && (i <= 127)) { groupBox = gb607F; } else if ((i >= 128) && (i <= 159)) { groupBox = gb809F; } else if ((i >= 160) && (i <= 191)) { groupBox = gbA0BF; } else if ((i >= 182) && (i <= 223)) { groupBox = gbC0DF; } else { groupBox = gbE0FF; } ((ComboBox)groupBox.Controls["cb" + addr]).SelectedIndex = (stIn == "!" + addr + "4019P") ? 1 : 0; if (i == 255) { break; } } }
private void tbAddress10_Validating(object sender, CancelEventArgs e) { byte address10; if (byte.TryParse(tbAddress10.Text, NumberStyles.Integer, CultureInfo.InvariantCulture, out address10)) { //tbAddress.Text = ClassAbstractAdamModule.ByteToHex(address10); tbAddress.Text = NewModuleAbstract.ByteToHex(address10); tbCommand.Text = GetCommandString(); } else { MessageBox.Show(@"Адрес должен быть целым числом от 0 до 255"); e.Cancel = true; tbAddress10.SelectionStart = 0; tbAddress10.SelectionLength = tbAddress10.Text.Length; } }
public ClassVirtualNet(string modules) { if (modules != null) { var mods = modules.Split(new[] { "/" }, StringSplitOptions.None); for (int i = 0; i <= mods.GetUpperBound(0); i++) { switch (mods[i]) { case "4019+": //--string address = ClassAbstractAdamModule.ByteToHex((byte) i); string address = NewModuleAbstract.ByteToHex((byte)i); _virtualNet.Add(address, new ClassVirtualAdamModule4019Plus(address)); break; } } } }
public void AddModuleToTreeView(string moduleAddress) { if (tvModuleTree.InvokeRequired == false) { NewModuleAbstract module = Program.Net.Modules[moduleAddress]; if (module.Address != null) { string nodeKey = "M" + module.Address; string nodeText = "Module " + module.Address; if (!tvModuleTree.Nodes.ContainsKey(nodeKey)) { tvModuleTree.Nodes.Add(nodeKey, nodeText); foreach (NewChannelAbstract channel in module.Channels) { string nodeChieldKey = nodeKey + "_C" + channel.Channel; nodeText = (!channel.IsCjc) ? "Channel " + channel.Channel : "CJC"; if (!tvModuleTree.Nodes[nodeKey].Nodes.ContainsKey(nodeChieldKey)) { tvModuleTree.Nodes[nodeKey].Nodes.Add(nodeChieldKey, nodeText); } else { ClassLog.AddLog(ELogType.Event, "ClassViews.AddModuleToTreeView", "Дерево модуля уже содержит подузел " + nodeChieldKey + " в узле " + nodeKey, DateTime.Now); } } } else { ClassLog.AddLog(ELogType.Event, "ClassViews.AddModuleToTreeView", "Дерево модулей уже содержит узел " + nodeKey, DateTime.Now); } } } else { var dlg = new Action <string>(AddModuleToTreeView); tvModuleTree.BeginInvoke(dlg, new object[] { moduleAddress }); } }
private void tbAddress_Validating(object sender, CancelEventArgs e) { //byte? address10 = ClassAbstractAdamModule.HexToByte(tbAddress.Text); byte?address10 = NewModuleAbstract.HexToByte(tbAddress.Text); if (address10 != null) { tbAddress.Text = (tbAddress.Text.Length == 1) ? '0' + tbAddress.Text.ToUpper() : tbAddress.Text.ToUpper(); tbAddress10.Text = address10.ToString(); tbCommand.Text = GetCommandString(); } else { MessageBox.Show(@"Адрес должен быть 16-ричным числом от 00 до FF"); tbAddress.SelectionStart = 0; tbAddress.SelectionLength = tbAddress.Text.Length; e.Cancel = true; } }
private void butProgramModules_Click(object sender, EventArgs e) { for (byte i = 0; i <= 255; i++) { //--string addr = ClassAbstractAdamModule.ByteToHex(i); string addr = NewModuleAbstract.ByteToHex(i); if (Program.Net.Modules[addr] != null) { var fmModule = new FormModule4019P(addr); fmModule.ShowDialog(); break; } if (i == 255) { MessageBox.Show(@"Модули не найдены" + "\n" + @"Выполните сканирование сети и повторите попытку"); break; } } }
private void butOK_Click(object sender, EventArgs e) { string virtModules = ""; for (byte i = 0; i <= 255; i++) { //--string addr = ClassAbstractAdamModule.ByteToHex(i); string addr = NewModuleAbstract.ByteToHex(i); GroupBox groupBox; if ((i >= 0) && (i <= 31)) { groupBox = gb001F; } else if ((i >= 32) && (i <= 63)) { groupBox = gb203F; } else if ((i >= 64) && (i <= 95)) { groupBox = gb405F; } else if ((i >= 96) && (i <= 127)) { groupBox = gb607F; } else if ((i >= 128) && (i <= 159)) { groupBox = gb809F; } else if ((i >= 160) && (i <= 191)) { groupBox = gbA0BF; } else if ((i >= 182) && (i <= 223)) { groupBox = gbC0DF; } else { groupBox = gbE0FF; } if (((groupBox).Controls["cb" + addr]).Text == @"Adam 4019+") { virtModules += "4019+/"; } else { virtModules += "/"; } if (i == 255) { break; } } Program.Net.InitVirtNet(virtModules); MessageBox.Show(@"Виртуальная сеть обновлена"); //Close(); }
public void AddModuleToListView(string moduleAddress) { if (lvSignalList.InvokeRequired == false) { NewModuleAbstract module = Program.Net.Modules[moduleAddress]; if (module != null) { foreach (NewChannelAbstract channel in module.Channels) { string itemKey = "M" + channel.Module.Address + "C" + channel.Channel; string itemText = (lvSignalList.Items.Count + 1).ToString(); if (!lvSignalList.Items.ContainsKey(itemKey)) { ListViewItem curListItem = lvSignalList.Items.Add(itemKey, itemText, null); curListItem.Checked = channel.Selected; curListItem.SubItems.Add(channel.Code); curListItem.SubItems.Add(channel.Name); curListItem.SubItems.Add(channel.Signal); curListItem.SubItems.Add(channel.Value.ToString()); curListItem.SubItems.Add(channel.Time.ToString()); //curListItem.SubItems.Add(((int)channel.Status).ToString()); curListItem.SubItems.Add((channel.Status != null) ? ((int)channel.Status).ToString() : null); curListItem.SubItems.Add(channel.Module.Address10.ToString()); curListItem.SubItems.Add((!channel.IsCjc) ? channel.Channel.ToString() : "CJC"); curListItem.SubItems.Add(channel.Aperture.ToString()); curListItem.SubItems.Add(channel.Min.ToString()); curListItem.SubItems.Add(channel.Max.ToString()); switch (channel.ChannelType) { case "Adam4019+": curListItem.SubItems.Add(((NewChannelAdamAbstract)channel).DataFormat); curListItem.SubItems.Add(((NewChannelAdamAbstract)channel).ChannelRange); break; default: curListItem.SubItems.Add(""); curListItem.SubItems.Add(""); break; } curListItem.SubItems.Add(channel.InLevel); curListItem.SubItems.Add(channel.Conversion); curListItem.SubItems.Add(channel.Units); curListItem.UseItemStyleForSubItems = false; } else { ClassLog.AddLog(ELogType.Event, "ClassViews.AddModuleToListView", "Элемент " + itemKey + " уже существует в списке каналов", DateTime.Now); break; } } } } else { var dlg = new Action <string>(AddModuleToListView); lvSignalList.BeginInvoke(dlg, new object[] { moduleAddress }); } }
private string GetChannelValue(byte channel) { //Генерирует случайное значение канала в зависимости от свойст устройства и канала //if ((channel == 7) && ((DateTime.Now.Second % 2) == 1)) return "+888888"; /*(((DateTime.Now.Millisecond % 256) == ClassAbstractAdamModule.HexToByte(_address)) && */ if ((DateTime.Now.Millisecond % 10) == channel) { return("+888888"); } //--byte? a = ClassAbstractAdamModule.HexToByte(_address); byte? a = NewModuleAbstract.HexToByte(_address); double value = GetValue(3, 20 * (a != null ? (byte)a : 0) + 1, 2.5 * channel); switch (_dataFormat) { case "0": // Engineering units switch (_channels[channel].InputRange) { case "02": // +-100 mV value = 200 * value - 100; break; case "03": // +-500 m value = 1000 * value - 500; break; case "04": // +-1 V value = 2 * value - 1; break; case "05": // +-2.5 mV value = 5 * value - 2.5; break; case "07": // +4 ~ 20 mA value = 16 * value + 4; break; case "08": // +-10 V value = 20 * value - 10; break; case "09": // +-5 V value = 10 * value - 5; break; case "0D": // +-20 mA value = 40 * value - 20; break; case "0E": // Type J Thermocouple 0 ~ 760 C value = 760 * value; break; case "0F": // Type K Thermocouple 0 ~1370 C value = 1370 * value; break; case "10": // Type T Thermocouple -100 ~ 400 C value = 500 * value - 100; break; case "11": // Type E Thermocouple 0 ~ 1000 C value = 1000 * value; break; case "12": // Type R Thermocouple 500 ~ 1750 C value = 1250 * value + 500; break; case "13": // Type S Thermocouple 500 ~ 1750 C value = 1250 * value + 500; break; case "14": // Type B Thermocouple 500 ~ 1800 C value = 1300 * value + 500; break; } break; case "1": // % of FSR case "2": // two's complement of hexadecimal switch (_channels[channel].InputRange) { case "02": // +-100 mV case "03": // +-500 m case "04": // +-1 V case "05": // +-2.5 mV case "08": // +-10 V case "09": // +-5 V case "0D": // +-20 mA value = 200 * value - 100; break; case "07": // +4 ~ 20 mA case "0E": // Type J Thermocouple 0 ~ 760 C case "0F": // Type K Thermocouple 0 ~1370 C case "10": // Type T Thermocouple -100 ~ 400 C case "11": // Type E Thermocouple 0 ~ 1000 C case "12": // Type R Thermocouple 500 ~ 1750 C case "13": // Type S Thermocouple 500 ~ 1750 C case "14": // Type B Thermocouple 500 ~ 1800 C value = 100 * value; break; } break; } string stVal = ""; switch (_dataFormat) { case "0": // Engineering units stVal = (value >= 0) ? "+" + value : value.ToString(); stVal = stVal.Substring(0, 7).Replace(",", "."); if (stVal.IndexOf(".") == -1) { stVal = stVal + "."; } while (stVal.Length < 7) { stVal = stVal + "0"; } break; case "1": // % of FSR value = Math.Round(value, 2); stVal = (value >= 0) ? "+" + value : value.ToString(); stVal = stVal.Replace(",", "."); int i = stVal.IndexOf("."); if (i == -1) { stVal = stVal + "."; i = stVal.Length; } for (; i <= 5; i++) { stVal = stVal.Substring(0, 1) + "0" + stVal.Substring(1); } while (stVal.Length <= 7) { stVal = stVal + "0"; } break; case "2": // two's complement of hexadecimal var val = (int)Math.Round(327.67 * value); if (val < 0) { val = (int)Math.Pow(16, 4) - val; } stVal = Convert.ToString(val, 16); break; } return(stVal); }