コード例 #1
0
ファイル: Form1.cs プロジェクト: 287396159/A
        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));
                }
            }
        }
コード例 #2
0
ファイル: Form1.cs プロジェクト: 287396159/A
        private void receivedData00(object data)
        {
            if (clickEventNum == CLICKEVENTNUM.SEARCH || clickEventNum == CLICKEVENTNUM.SETCARDID || clickEventNum == CLICKEVENTNUM.SETWARNID)
            {
                listView1.Items.Clear();
                listView2.Items.Clear();
                if (data is List <Differentiable> )
                {
                    devices = data as List <Differentiable>;

                    foreach (Differentiable device in devices)
                    {
                        byte[]       id           = device.getId();
                        ListViewItem listViewItem = new ListViewItem();
                        listViewItem.Text      = getID(id);
                        listViewItem.BackColor = Color.DeepSkyBlue;
                        if (device is CardDevice)
                        {
                            listView1.Items.Add(listViewItem);
                        }
                        else if (device is WarningDevice)
                        {
                            listView2.Items.Add(listViewItem);
                        }
                    }
                }
                clickEventNum = CLICKEVENTNUM.NONE;
            }
        }
コード例 #3
0
ファイル: Form1.cs プロジェクト: 287396159/A
 private void receivedData16(object data)
 {
     if (clickEventNum == CLICKEVENTNUM.SETACCRANGE || clickEventNum == CLICKEVENTNUM.GETACCRANGE || clickEventNum == CLICKEVENTNUM.LISTVIEWITEMCARDCLICK || clickEventNum == CLICKEVENTNUM.SEARCHCARDID)
     {
         byte[] accRangeBytes = data as byte[];
         textBox4.Text = "" + accRangeBytes[0];
         showResult();
         clickEventNum = CLICKEVENTNUM.NONE;
     }
 }
コード例 #4
0
ファイル: Form1.cs プロジェクト: 287396159/A
 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();
     }
 }
コード例 #5
0
ファイル: Form1.cs プロジェクト: 287396159/A
 private void Button3_Click(object sender, EventArgs e)
 {
     if (serialPort.IsOpen)
     {
         clickEventNum = CLICKEVENTNUM.SEARCH;
         deviceCom.sendSearchDeviceNumCom();
     }
     else
     {
         MessageBox.Show("请打开端口");
     }
 }
コード例 #6
0
ファイル: Form1.cs プロジェクト: 287396159/A
 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 });
         }
     }
 }
コード例 #7
0
ファイル: Form1.cs プロジェクト: 287396159/A
        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!");
            }
        }
コード例 #8
0
ファイル: Form1.cs プロジェクト: 287396159/A
        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!");
            }
        }
コード例 #9
0
ファイル: Form1.cs プロジェクト: 287396159/A
        private void receivedData49(object data)
        {
            if (clickEventNum == CLICKEVENTNUM.SETWARNCARD || clickEventNum == CLICKEVENTNUM.ADDWARNCARD || clickEventNum == CLICKEVENTNUM.REMOVEWARNCARD)
            {
                if (data is byte[])
                {
                    byte[] revflagBytes = data as byte[];
                    if (revflagBytes.Length == 1)
                    {
                        if (revflagBytes[0] == 0)
                        {
                            showResult();
                        }
                        else
                        {
                            switch (clickEventNum)
                            {
                            case CLICKEVENTNUM.GETWARNCARD:
                                label12.Text = "Read card failed";
                                break;

                            case CLICKEVENTNUM.SETWARNCARD:
                                label12.Text = "Set card failed";
                                break;

                            case CLICKEVENTNUM.ADDWARNCARD:
                                label12.Text = "Add card failed";
                                break;

                            case CLICKEVENTNUM.REMOVEWARNCARD:
                                label12.Text = "Remove card failed";
                                break;

                            default:
                                break;
                            }
                        }
                    }
                }
                clickEventNum = CLICKEVENTNUM.NONE;
            }
        }
コード例 #10
0
ファイル: Form1.cs プロジェクト: 287396159/A
 private void TabControl1_SelectedIndexChanged(object sender, EventArgs e)
 {
     listView1.Items.Clear();
     listView2.Items.Clear();
     if (serialPort.IsOpen)
     {
         clickEventNum = CLICKEVENTNUM.SEARCH;
         deviceCom.sendSearchDeviceNumCom();
     }
     if ("Tag".Equals(tabControl1.SelectedTab.Text))
     {
         device = new CardDevice();
         showDevice(device);
     }
     else if ("Warn".Equals(tabControl1.SelectedTab.Text))
     {
         device = new WarningDevice();
         showDevice(device);
     }
     setDeviceCom();
 }
コード例 #11
0
ファイル: Form1.cs プロジェクト: 287396159/A
 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();
         }
     }
 }
コード例 #12
0
ファイル: Form1.cs プロジェクト: 287396159/A
 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();
         }
     }
 }
コード例 #13
0
ファイル: Form1.cs プロジェクト: 287396159/A
 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();
         }
     }
 }
コード例 #14
0
ファイル: Form1.cs プロジェクト: 287396159/A
        private void Button5_Click(object sender, EventArgs e)
        {
            //search id
            string textStr = textBox1.Text;
            string idStr   = textStr.Replace(" ", "");

            byte[] id = getID(idStr, 3);
            if (id != null)
            {
                string endId = idStr.PadLeft(6, '0').Substring(2, 4);
                if ("0000" != endId && !"FFFF".Equals(endId.ToUpper()))
                {
                    //device.setId(id);
                    if (device is CardDevice)
                    {
                        clickEventNum = CLICKEVENTNUM.SEARCHCARDID;
                    }
                    else if (device is WarningDevice)
                    {
                        clickEventNum = CLICKEVENTNUM.SEARCHWARNID;
                    }
                    searchDeviceAllInfo();
                }
                else
                {
                    MessageBox.Show("Incorrect format!");
                }
            }
            else
            {
                MessageBox.Show("Incorrect format!");
            }
            //if (idStr.Length >= 6)
            //{
            //    device.setId(new byte[] {Convert.ToByte(idStr.Substring(0,2),16), Convert.ToByte(idStr.Substring(2, 2), 16), Convert.ToByte(idStr.Substring(4, 2), 16) });
            //}
        }
コード例 #15
0
ファイル: Form1.cs プロジェクト: 287396159/A
 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!");
             }
         }
     }
 }
コード例 #16
0
ファイル: Form1.cs プロジェクト: 287396159/A
 private void ListView1_Click(object sender, EventArgs e)
 {
     clickEventNum = CLICKEVENTNUM.LISTVIEWITEMCARDCLICK;
     listClick(listView1);
 }
コード例 #17
0
ファイル: Form1.cs プロジェクト: 287396159/A
 private void ListView2_Click(object sender, EventArgs e)
 {
     clickEventNum = CLICKEVENTNUM.LISTVIEWITEMWARNCLICK;
     listClick(listView2);
     textBox1.Text = "" + getID(device.getId());
 }
コード例 #18
0
ファイル: Form1.cs プロジェクト: 287396159/A
 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();
         }
     }
 }
コード例 #19
0
ファイル: Form1.cs プロジェクト: 287396159/A
        private void showResult()
        {
            string idStr = getID(device.getId());

            switch (clickEventNum)
            {
            case CLICKEVENTNUM.LISTVIEWITEMCARDCLICK:
                //label12.Text = "Search " + idStr + " success";
                break;

            case CLICKEVENTNUM.SETCARDID:
                label12.Text = "Set card id(" + idStr + ") success";
                break;

            case CLICKEVENTNUM.SEARCHCARDID:
                label12.Text = "Search " + idStr + " success";
                break;

            case CLICKEVENTNUM.SETRANGETIME:
                label12.Text = "Set range time(" + idStr + ") success";
                break;

            case CLICKEVENTNUM.GETRANGETIME:
                label12.Text = "Read range time(" + idStr + ") success";
                break;

            case CLICKEVENTNUM.SETCARDSTILLTIME:
                label12.Text = "Set card still time(" + idStr + ") success";
                break;

            case CLICKEVENTNUM.GETCARDSTILLTIME:
                label12.Text = "Read card still time(" + idStr + ") success";
                break;

            case CLICKEVENTNUM.SETACCRANGE:
                label12.Text = "Set acc range(" + idStr + ") success";
                break;

            case CLICKEVENTNUM.GETACCRANGE:
                label12.Text = "Read acc range(" + idStr + ") success";
                break;

            case CLICKEVENTNUM.LISTVIEWITEMWARNCLICK:
                break;

            case CLICKEVENTNUM.SETWARNID:
                label12.Text = "Set id(" + idStr + ") success";
                break;

            case CLICKEVENTNUM.SEARCHWARNID:
                label12.Text = "Search " + idStr + " success";;
                break;

            case CLICKEVENTNUM.SETLINKTIME:
                label12.Text = "Set line time(" + idStr + ") success";
                break;

            case CLICKEVENTNUM.GETLINKTIME:
                label12.Text = "Read line time(" + idStr + ") success";
                break;

            case CLICKEVENTNUM.SETSAFEDISTANCE:
                label12.Text = "Set safa distance(" + idStr + ") success";
                break;

            case CLICKEVENTNUM.GETSAFEDISTANCE:
                label12.Text = "Read safa distance(" + idStr + ") success";
                break;

            case CLICKEVENTNUM.SETVOLUME:
                label12.Text = "Set volume(" + idStr + ") success";
                break;

            case CLICKEVENTNUM.GETVOLUME:
                label12.Text = "Read volume(" + idStr + ") success";
                break;

            case CLICKEVENTNUM.GETWARNCARD:
                label12.Text = "Read card success";
                break;

            case CLICKEVENTNUM.SETWARNCARD:
                label12.Text = "Set card success";
                break;

            case CLICKEVENTNUM.ADDWARNCARD:
                label12.Text = "Add card success";
                break;

            case CLICKEVENTNUM.REMOVEWARNCARD:
                label12.Text = "Remove card success";
                break;

            default:
                break;
            }
            if (clickEventNum != CLICKEVENTNUM.SETCARDID && clickEventNum != CLICKEVENTNUM.SETWARNID && clickEventNum != CLICKEVENTNUM.LISTVIEWITEMCARDCLICK && clickEventNum != CLICKEVENTNUM.SEARCHCARDID && clickEventNum != CLICKEVENTNUM.LISTVIEWITEMWARNCLICK && clickEventNum != CLICKEVENTNUM.SEARCHWARNID)
            {
                clickEventNum = CLICKEVENTNUM.NONE;
            }
        }