Beispiel #1
0
        private void CheckTag(byte startAdd, byte bank, byte length)
        {
            startCheck = true;
            new Task(() =>
            {
                DataTable source = dataGridView1.DataSource as DataTable;
                byte Length      = (byte)(source.Rows[0][0].ToString().Length / 4);
                byte[] byteArray;
                string str;
                bool isCheckRight;
                int checkIndex = 0;
                while (startCheck)
                {
                    isCheckRight = false;
                    byteArray    = new byte[64];
                    str          = "";
                    if (1 == Dis.ReadTagData(deviceNo, bank, startAdd, length, byteArray))
                    {
                        for (int i = 3; i < 2 * Length + 3; i++) // 前面3个字节为输入的参数
                        {
                            str += string.Format("{0:X2}", byteArray[i]);
                        }

                        for (int index = 0; index < source.Rows.Count; index++)
                        {
                            if (str.IndexOf(source.Rows[index][0].ToString(), StringComparison.OrdinalIgnoreCase) >= 0)
                            //   if (source.Rows[index][0].ToString() == str)
                            {
                                isCheckRight = true;
                                source.Rows[index][checkResultStr] = Convert.ToString((char)8730);
                                m_SyncContext.Post(UpdataDataGrid, source);
                                m_SyncContext.Post(UpdataOkImage, Properties.Resources.ResourceManager.GetObject("yuandian_1"));
                                checkIndex = index;
                                break;
                            }
                        }
                        if (!isCheckRight)
                        {
                            MessageBoxTimeoutA((IntPtr)0, unWriteStr, checkResultStr, 0, 0, 1000);
                        }
                    }
                    Thread.Sleep(1000);
                    m_SyncContext.Post(UpdataOkImage, Properties.Resources.ResourceManager.GetObject("yuandian"));
                }
            }).Start();
        }
Beispiel #2
0
        /// <summary>
        /// 单个区域标签读写
        /// </summary>
        /// <param name="startadd"></param>
        /// <param name="bank"></param>
        /// <param name="Length"></param>
        private void AutoWriteCardFilter(Dictionary <string, MultiArea> writeData)
        {
            autoWrite = true;
            Task autoWriteTask = new Task(() =>
            {
                byte[] byteArray;
                string writeStr;
                string strTID = "";
                int page      = 0;
                int index     = 0;
                int length    = 0;
                bool writeFinish;
                byte reWriteTimes   = 0;
                string successTimes = "";
                while (currentRow < tableCollection.Rows.Count && autoWrite)
                {
                    byteArray     = new byte[64];
                    strTID        = "";
                    bool isExit   = false;
                    bool isEnable = true;
                    if (1 == Dis.ReadTagData(deviceNo, 0x02, 0x00, 6, byteArray))
                    {
                        for (int i = 3; i < 2 * 6 + 3; i++)     // 前面3个字节为输入的参数
                        {
                            strTID += string.Format("{0:X2}", byteArray[i]);
                        }
                        for (int start = 0; start < tableCollection.Rows.Count; start++)
                        {
                            if (tableCollection.Rows[start][stateStr].ToString() == WriteSuccess)
                            {
                                if (strTID == tableCollection.Rows[start][TIDStr].ToString())
                                {
                                    isExit     = true;
                                    currentRow = start;
                                    page       = currentRow / csize;
                                    index      = currentRow % csize;
                                    if (tableCollection.Rows[currentRow][checkResultStr].ToString() != "")
                                    {
                                        successTimes = (int.Parse(tableCollection.Rows[currentRow][checkResultStr].ToString()) + 1).ToString();
                                        tableCollection.Rows[currentRow][checkResultStr] = successTimes;
                                        tables[page].Rows[index][checkResultStr]         = successTimes;
                                    }
                                    m_SyncContext.Post(UpdataDataGrid, tables[page]);
                                    // MessageBoxTimeoutA((IntPtr)0,"重复写入", tipStr, 0, 0, 1000);
                                    break;
                                }
                                else
                                {
                                    continue;
                                }
                            }
                            else
                            {
                                if (strTID == tableCollection.Rows[start][TIDStr].ToString() || tableCollection.Rows[start][TIDStr].ToString() == "")
                                {
                                    currentRow = start;
                                    break;
                                }
                                else
                                {
                                    continue;
                                }
                            }
                        }
                        m_SyncContext.Post(UpdataOkImage, Properties.Resources.ResourceManager.GetObject("yuandian_1"));
                        if (!isExit)
                        {
                            page        = currentRow / csize;
                            index       = currentRow % csize;
                            writeFinish = false;
                            tableCollection.Rows[currentRow][TIDStr] = strTID;
                            tables[page].Rows[index][TIDStr]         = strTID;
                            reWriteTimes = 0;
                            foreach (string key in writeData.Keys)
                            {
                                writeData[key].writeSuccess = false;
                            }
                            while (!writeFinish && reWriteTimes < 3)          //连续三次写不成功则跳过
                            {
                                writeFinish = true;
                                reWriteTimes++;
                                foreach (string key in writeData.Keys)
                                {
                                    if (!writeData[key].writeSuccess)                //还未写入
                                    {
                                        writeStr = tableCollection.Rows[currentRow][key].ToString();
                                        if (writeStr != "")
                                        {
                                            length = (byte)(writeStr.Length / 2);
                                            for (int i = 0; i < 64; ++i)
                                            {
                                                if (i < length)
                                                {
                                                    byteArray[i] = Convert.ToByte(writeStr.Substring(2 * i, 2), 16);
                                                }
                                                else
                                                {
                                                    byteArray[i] = 0;
                                                }
                                                {
                                                }
                                            }
                                            length = (byte)(length / 2);
                                            if (1 == Dis.WriteTagMultiWord(deviceNo, writeData[key].bank, writeData[key].startAdd, (byte)length, byteArray))
                                            {
                                                writeData[key].writeSuccess = true;
                                            }
                                            else
                                            {
                                                writeFinish = false;
                                                tableCollection.Rows[currentRow][stateStr] = WriteFailed;
                                                tables[page].Rows[index][stateStr]         = WriteFailed;
                                            }
                                        }
                                        else
                                        {
                                            writeData[key].writeSuccess = true;
                                        }
                                    }
                                }
                            }
                            if (reWriteTimes >= 3)
                            {
                                writeFinish = false;
                            }
                            if (writeFinish)                     //连续三次没写成功
                            {
                                // MessageBoxEx((IntPtr)0, "标签可能存在问题,请更换标签继续写入", tipStr, 0, 2);
                                // autoWrite = false;
                                tableCollection.Rows[currentRow][stateStr]       = WriteSuccess;
                                tables[page].Rows[index][stateStr]               = WriteSuccess;
                                tableCollection.Rows[currentRow][checkResultStr] = "0";
                                tables[page].Rows[index][checkResultStr]         = "0";
                            }

                            m_SyncContext.Post(UpdataDataGrid, tables[page]);
                        }
                    }
                    Thread.Sleep(500);
                    m_SyncContext.Post(UpdataOkImage, Properties.Resources.ResourceManager.GetObject("yuandian"));
                }
                if (autoWrite)
                {
                    MessageBox.Show(finishWriteStr);
                }
            });

            autoWriteTask.Start();
        }
Beispiel #3
0
        private void AutoWriteCard(byte startMode, byte startadd, byte bank, byte Length)
        {
            autoWrite = true;
            if (startMode == 0x00)
            {
                currentRow = 0x00;
            }
            Task autoWriteTask = new Task(() =>
            {
                byte[] byteArray;
                string str;
                while (currentRow < dataGridView1.Rows.Count - 1 && autoWrite)
                {
                    DataTable source = dataGridView1.DataSource as DataTable;
                    Length           = (byte)(source.Rows[currentRow][0].ToString().Length / 4);
                    if (startMode == 0x02)
                    {
                        bool isExit = false;
                        for (int start = 0; start < source.Rows.Count; start++)
                        {
                            if (source.Rows[start][3].ToString() == "")
                            {
                                currentRow = start;
                                isExit     = true;
                                break;
                            }
                        }
                        if (!isExit)
                        {
                            break;
                        }
                    }
                    byteArray = new byte[64];
                    str       = "";
                    if (1 == Dis.ReadTagData(deviceNo, bank, startadd, (byte)Length, byteArray))
                    {
                        for (int i = 3; i < 2 * Length + 3; i++) // 前面3个字节为输入的参数
                        {
                            str += string.Format("{0:X2}", byteArray[i]);
                        }
                        if (currentRow < source.Rows.Count)
                        {
                            source.Rows[currentRow][1] = str;
                            m_SyncContext.Post(UpdataDataGrid, source);
                        }
                        else
                        {
                            break;
                        }
                        if (str != backStr)
                        {
                            str    = source.Rows[currentRow][0].ToString();
                            Length = (byte)(str.Length / 2);
                            for (int i = 0; i < 64; ++i)
                            {
                                if (i < Length)
                                {
                                    byteArray[i] = Convert.ToByte(str.Substring(2 * i, 2), 16);
                                }
                                else
                                {
                                    byteArray[i] = 0;
                                }
                            }
                            Length = (byte)(Length / 2);
                            if (1 == Dis.WriteTagData(deviceNo, bank, startadd, (byte)Length, byteArray))
                            {
                                source.Rows[currentRow][2] = WriteSuccess;
                                backStr = str;
                                if (startMode == 0x00 || startMode == 0x01)
                                {
                                    currentRow++;
                                }
                            }
                            else
                            {
                                source.Rows[currentRow][2] = WriteFailed;
                            }
                            m_SyncContext.Post(UpdataDataGrid, source);
                        }
                        else
                        {
                            source.Rows[currentRow][2] = WriteSuccess;
                        }
                    }
                    Thread.Sleep(1000);
                }
                if (autoWrite)
                {
                    MessageBox.Show(finishWriteStr);
                }
            });

            autoWriteTask.Start();
        }