private void Button15_Click(object sender, EventArgs e) { //remove card //MessageBox.Show("Button15_Click"); int selectCount = 0; foreach (ListViewItem item in listView3.SelectedItems) { selectCount++; listView3.Items.Remove(item); } if (selectCount == 0) { MessageBox.Show("Select the object to remove"); } else { if (device is WarningDevice && deviceCom is WarningDeviceCom) { WarningDeviceCom warningDeviceCom = deviceCom as WarningDeviceCom; clickEventNum = CLICKEVENTNUM.REMOVEWARNCARD; warningDeviceCom.sendSetWarningCardsCom(getListViewItemsToCardID(listView3)); } } }
private void searchDeviceAllInfo() { if (device is CardDevice) { if (deviceCom is CardDeviceCom) { CardDeviceCom cardDeviceCom = deviceCom as CardDeviceCom; cardDeviceCom.sendShowCardDeviceCom(); Thread.Sleep(120); cardDeviceCom.sendSearchRangeTime(); Thread.Sleep(120); cardDeviceCom.sendSearchStillTime(); Thread.Sleep(120); cardDeviceCom.sendSearchAccRange(); } } else if (device is WarningDevice) { if (deviceCom is WarningDeviceCom) { WarningDeviceCom warningDeviceCom = deviceCom as WarningDeviceCom; warningDeviceCom.sendSerachWarningLinkTimeCom(); Thread.Sleep(120); warningDeviceCom.sendSerachWarningSafeDistanceCom(); Thread.Sleep(120); warningDeviceCom.sendSerachWarningVolumeCom(); Thread.Sleep(120); warningDeviceCom.sendSerachWarningCardsCom(); } } }
private void Button13_Click(object sender, EventArgs e) { //MessageBox.Show("Button13_Click"); //read card if (device is WarningDevice && deviceCom is WarningDeviceCom) { WarningDeviceCom warningDeviceCom = deviceCom as WarningDeviceCom; clickEventNum = CLICKEVENTNUM.GETWARNCARD; warningDeviceCom.sendSerachWarningCardsCom(); } }
private void Button10_Click(object sender, EventArgs e) { //MessageBox.Show("Button10_Click"); //set volume if (device is CardDevice) { if (deviceCom is CardDeviceCom) { CardDeviceCom cardDeviceCom = deviceCom as CardDeviceCom; clickEventNum = CLICKEVENTNUM.SETACCRANGE; //cardDeviceCom.sendSetAccRange(); //string accRangeText = textBox4.Text; try { byte accRange = Convert.ToByte(textBox4.Text); if (accRange >= 10 && accRange <= 86) { cardDeviceCom.sendSetAccRange(new byte[] { accRange }); } else { MessageBox.Show("Incorrect format!"); } } catch (FormatException) { MessageBox.Show("Incorrect format!"); } catch (OverflowException) { MessageBox.Show("Incorrect format!"); } //cardDeviceCom.sendSearchAccRange(); } } else if (device is WarningDevice) { if (deviceCom is WarningDeviceCom) { WarningDeviceCom warningDeviceCom = deviceCom as WarningDeviceCom; clickEventNum = CLICKEVENTNUM.SETVOLUME; //byte volume = trackBar1.Value; warningDeviceCom.sendSetWarningVolumeCom(new byte[] { (byte)trackBar1.Value }); } } }
private void Button14_Click(object sender, EventArgs e) { //MessageBox.Show("Button14_Click"); //Add card string idStr = textBox5.Text; byte[] id = getID(idStr, 3); if (id != null) { string endId = idStr.PadLeft(6, '0').Substring(2, 4); if ("0000" != endId && !"FFFF".Equals(endId.ToUpper())) { if (device is WarningDevice && deviceCom is WarningDeviceCom) { WarningDeviceCom warningDeviceCom = deviceCom as WarningDeviceCom; clickEventNum = CLICKEVENTNUM.ADDWARNCARD; warningDeviceCom.sendSerachWarningCardsCom(); //byte[] setCardBytes = new byte[300]; //ListViewItem listViewItem = new ListViewItem(); //listViewItem.Text = getID(id); //listViewItem.BackColor = Color.DeepSkyBlue; //listView3.Items.Add(listViewItem); //for (int i = 0; i < listView3.Items.Count; i++) //{ // string cardIDStr = listView3.Items[i].Text; // byte[] cardIDBytes = getID(cardIDStr, 3); // setCardBytes[i * 3] = cardIDBytes[0]; // setCardBytes[i * 3 + 1] = cardIDBytes[1]; // setCardBytes[i * 3 + 2] = cardIDBytes[2]; //} //warningDeviceCom.sendSetWarningCardsCom(setCardBytes); } } else { MessageBox.Show("Incorrect format!"); } } else { MessageBox.Show("Incorrect format!"); } }
private void Button4_Click(object sender, EventArgs e) { //MessageBox.Show("Button4_Click"); //set id string idStr = textBox1.Text; byte[] id = getID(idStr, 3); if (id != null) { string endId = idStr.PadLeft(6, '0').Substring(2, 4); if ("0000" != endId && !"FFFF".Equals(endId.ToUpper())) { if (device is CardDevice) { if (deviceCom is CardDeviceCom) { CardDeviceCom cardDeviceCom = deviceCom as CardDeviceCom; clickEventNum = CLICKEVENTNUM.SETCARDID; cardDeviceCom.sendSetCardIdCom(id); //cardDeviceCom.sendSearchRangeTime(); } } else if (device is WarningDevice) { if (deviceCom is WarningDeviceCom) { WarningDeviceCom warningDeviceCom = deviceCom as WarningDeviceCom; clickEventNum = CLICKEVENTNUM.SETWARNID; warningDeviceCom.sendSetWarningIdCom(id); } } } else { MessageBox.Show("Incorrect format!"); } } else { MessageBox.Show("Incorrect format!"); } }
private void Button11_Click(object sender, EventArgs e) { //read volume if (device is CardDevice) { if (deviceCom is CardDeviceCom) { CardDeviceCom cardDeviceCom = deviceCom as CardDeviceCom; clickEventNum = CLICKEVENTNUM.GETACCRANGE; cardDeviceCom.sendSearchAccRange(); } } else if (device is WarningDevice) { if (deviceCom is WarningDeviceCom) { WarningDeviceCom warningDeviceCom = deviceCom as WarningDeviceCom; clickEventNum = CLICKEVENTNUM.GETVOLUME; warningDeviceCom.sendSerachWarningVolumeCom(); } } }
private void Button9_Click(object sender, EventArgs e) { //read safe Distance if (device is CardDevice) { if (deviceCom is CardDeviceCom) { CardDeviceCom cardDeviceCom = deviceCom as CardDeviceCom; clickEventNum = CLICKEVENTNUM.GETCARDSTILLTIME; cardDeviceCom.sendSearchStillTime(); } } else if (device is WarningDevice) { if (deviceCom is WarningDeviceCom) { WarningDeviceCom warningDeviceCom = deviceCom as WarningDeviceCom; clickEventNum = CLICKEVENTNUM.GETSAFEDISTANCE; warningDeviceCom.sendSerachWarningSafeDistanceCom(); } } }
private void Button7_Click(object sender, EventArgs e) { ////MessageBox.Show("Button7_Click"); //read Link time if (device is CardDevice) { if (deviceCom is CardDeviceCom) { CardDeviceCom cardDeviceCom = deviceCom as CardDeviceCom; clickEventNum = CLICKEVENTNUM.GETRANGETIME; cardDeviceCom.sendSearchRangeTime(); } } else if (device is WarningDevice) { if (deviceCom is WarningDeviceCom) { WarningDeviceCom warningDeviceCom = deviceCom as WarningDeviceCom; clickEventNum = CLICKEVENTNUM.GETLINKTIME; warningDeviceCom.sendSerachWarningLinkTimeCom(); } } }
private void Button8_Click(object sender, EventArgs e) { //MessageBox.Show("Button8_Click"); //set safe Distance if (device is CardDevice) { if (deviceCom is CardDeviceCom) { CardDeviceCom cardDeviceCom = deviceCom as CardDeviceCom; clickEventNum = CLICKEVENTNUM.SETCARDSTILLTIME; //string stillTimeText = textBox3.Text; try { byte[] stillTimeBytes = new byte[2]; int stillTime = Convert.ToInt32(textBox3.Text); if (stillTime >= 0 && stillTime <= 65535) { stillTimeBytes[0] = (byte)(stillTime / 256); stillTimeBytes[1] = (byte)(stillTime % 256); cardDeviceCom.sendSetStillTime(stillTimeBytes); } else { MessageBox.Show("Incorrect format!"); } } catch (FormatException) { MessageBox.Show("Incorrect format!"); } catch (OverflowException) { MessageBox.Show("Incorrect format!"); } //cardDeviceCom.sendSearchRangeTime(); } } else if (device is WarningDevice) { if (deviceCom is WarningDeviceCom) { WarningDeviceCom warningDeviceCom = deviceCom as WarningDeviceCom; clickEventNum = CLICKEVENTNUM.SETSAFEDISTANCE; try { byte[] safeDistanceBytes = new byte[2]; int safeDistance = Convert.ToInt32(textBox3.Text); if (safeDistance >= 0 && safeDistance <= 65535) { safeDistanceBytes[0] = (byte)(safeDistance / 256); safeDistanceBytes[1] = (byte)(safeDistance % 256); warningDeviceCom.sendSetWarningSafeDistanceCom(safeDistanceBytes); } else { MessageBox.Show("Incorrect format!"); } } catch (FormatException) { MessageBox.Show("Incorrect format!"); } catch (OverflowException) { MessageBox.Show("Incorrect format!"); } //warningDeviceCom.sendSetWarningSafeDistanceCom(); } } }
private void Button6_Click(object sender, EventArgs e) { //MessageBox.Show("Button6_Click"); //set Link Time if (device is CardDevice) { if (deviceCom is CardDeviceCom) { CardDeviceCom cardDeviceCom = deviceCom as CardDeviceCom; clickEventNum = CLICKEVENTNUM.SETRANGETIME; //cardDeviceCom.sendSearchRangeTime(); //string rangeTimeText = textBox2.Text; try { byte rangeTime = Convert.ToByte(textBox2.Text); if (rangeTime > 0) { cardDeviceCom.sendSetRangeTime(new byte[] { rangeTime }); } else { MessageBox.Show("Incorrect format!"); } } catch (FormatException) { MessageBox.Show("Incorrect format!"); } catch (OverflowException) { MessageBox.Show("Incorrect format!"); } } } else if (device is WarningDevice) { if (deviceCom is WarningDeviceCom) { WarningDeviceCom warningDeviceCom = deviceCom as WarningDeviceCom; clickEventNum = CLICKEVENTNUM.SETLINKTIME; //string linkTimeText = textBox2.Text; try { byte[] linkTimeBytes = new byte[2]; int linkTime = Convert.ToInt32(textBox2.Text); if (linkTime >= 0 && linkTime <= 65535) { linkTimeBytes[0] = (byte)(linkTime / 256); linkTimeBytes[1] = (byte)(linkTime % 256); warningDeviceCom.sendSetWarningLinkTimeCom(linkTimeBytes); } else { MessageBox.Show("Incorrect format!"); } } catch (FormatException) { MessageBox.Show("Incorrect format!"); } catch (OverflowException) { MessageBox.Show("Incorrect format!"); } } } }
private void receivedData48(object data) { if (clickEventNum == CLICKEVENTNUM.GETWARNCARD || clickEventNum == CLICKEVENTNUM.ADDWARNCARD || clickEventNum == CLICKEVENTNUM.LISTVIEWITEMWARNCLICK || clickEventNum == CLICKEVENTNUM.SEARCHWARNID) { listView3.Items.Clear(); if (data is List <Differentiable> ) { List <Differentiable> warnCardDevices = data as List <Differentiable>; foreach (Differentiable warnCardDevice in warnCardDevices) { if (warnCardDevice is CardDevice) { ListViewItem listViewItem = new ListViewItem(); listViewItem.Text = getID(warnCardDevice.getId()); listViewItem.BackColor = Color.DeepSkyBlue; listView3.Items.Add(listViewItem); } } } if (clickEventNum == CLICKEVENTNUM.ADDWARNCARD) { byte[] idBytes = getID(textBox5.Text, 3); bool isExist = false; if (data is List <Differentiable> ) { List <Differentiable> warnCardDevices = data as List <Differentiable>; foreach (Differentiable warnCardDevice in warnCardDevices) { if (warnCardDevice is CardDevice) { byte[] warnCardDeviceID = warnCardDevice.getId(); bool[] isExistBytes = new bool[idBytes.Length]; bool isOk = true; for (int i = 0; i < idBytes.Length; i++) { if (idBytes[i] == warnCardDeviceID[i]) { isExistBytes[i] = true; } else { isOk = false; isExistBytes[i] = false; } } if (isOk) { isExist = true; } //foreach(bool isExistByte in isExistBytes) //{ // if (!isExistByte) // { // } //} } } } if (isExist) { } else { byte[] setCardBytes = new byte[300]; ListViewItem addListViewItem = new ListViewItem(); addListViewItem.Text = getID(getID(textBox5.Text, 3)); addListViewItem.BackColor = Color.DeepSkyBlue; listView3.Items.Add(addListViewItem); for (int i = 0; i < listView3.Items.Count; i++) { string cardIDStr = listView3.Items[i].Text; byte[] cardIDBytes = getID(cardIDStr, 3); setCardBytes[i * 3] = cardIDBytes[0]; setCardBytes[i * 3 + 1] = cardIDBytes[1]; setCardBytes[i * 3 + 2] = cardIDBytes[2]; } WarningDeviceCom warningDeviceCom = deviceCom as WarningDeviceCom; warningDeviceCom.sendSetWarningCardsCom(setCardBytes); } } else { showResult(); } } }