/// <summary> /// отправка телеграммы с формы /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void buttonSendCommand_Click(object sender, EventArgs e) { try { byte[] bytesComm = new byte[3]; Byte.TryParse(textBoxCmd_T.Text, NumberStyles.AllowHexSpecifier, null, out bytesComm[0]); Byte.TryParse(textBoxIdent.Text, NumberStyles.AllowHexSpecifier, null, out bytesComm[1]); Byte.TryParse(textBoxValue.Text, NumberStyles.AllowHexSpecifier, null, out bytesComm[2]); uint data; byte[] bytesData; if (UInt32.TryParse(textBoxData.Text, NumberStyles.AllowHexSpecifier, null, out data)) { bytesData = BitConverter.GetBytes(data); } else { bytesData = new byte[0]; } // - send Telegram Telegram send = new Telegram(bytesComm[0], bytesComm[1], bytesComm[2], (ushort)bytesData.Length); Array.Copy(bytesData, send.Data, bytesData.Length); //<- data keyGPack.SendPack(send); } catch (Exception exp) { snif.Text = exp.Message.ToString(); } }
/// <summary> /// Добавление нового владельца карты /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void addCardButton_Click(object sender, EventArgs e) { // - запишем тексты string textStr; textStr = surnameTextBox.Text + ' ' + nameTextBox.Text + ' ' + patronymTextBox.Text; Text newText = new Text(1); // <- bag должна быть сквозная адресация на тексты //new Text(keyGPack.Texts.Last().Addr + 1); byte[] text = Encoding.ASCII.GetBytes(textStr); if (text.Length <= 31) { Array.Copy(text, 0, newText.TextBytes, 0, text.Length); } else { Array.Copy(text, 0, newText.TextBytes, 0, 31); } keyGPack.Texts.Add(newText); keyGPack.SendPack(new Telegram(0x91, 0x12, 0xE1, newText.GetBytesText())); // - отправим устр-ву // - запишем карту byte[] fisnumCard = new byte[10]; for (int i = cardmaskedTextBox.Text.Length - 2; i >= 0; i -= 2) { //fisnumCard[(cardmaskedTextBox.Text.Length - 2 - i) / 2] = Convert.ToByte(cardmaskedTextBox.Text.Substring(i, 2)); byte.TryParse(cardmaskedTextBox.Text.Substring(i, 2), NumberStyles.AllowHexSpecifier, null, out fisnumCard[(cardmaskedTextBox.Text.Length - 2 - i) / 2]); } //int key = (int)lKeysBox.SelectedItem; ushort uLKey = 0; // - уровень доступа к ключам из combobox if (ushort.TryParse(lKeysBox.SelectedItem.ToString(), out uLKey)) { keyGPack.Cards.Add(new Card(1, 0x03000003, 0x1E1CB60A, 0x461CB60A, uLKey, (ushort)newText.Addr, fisnumCard)); keyGPack.SendPack(new Telegram(0x91, 0x04, 0xE1, keyGPack.Cards.Last().GetBytesCard())); // - отправим устр-ву } }
/// <summary> /// Сохранение данных с формы на устр-ве /// </summary> public void SaveDateZoneToDB() { // - сначала проверим форму saveDateZone(); // - затем, есть ли временная зона для добавления в устр-во? if (typeMass.Length > 0 || startMass.Length > 0 || endMass.Length > 0) { keyGPack.DateZones.Add(new DateZone(1, typeMass, startMass, endMass)); keyGPack.SendPack(new Telegram(0x91, 0x06, 0xE1, keyGPack.DateZones.Last().GetBytesDateZone())); //<- отправим устр-ву } }