示例#1
0
        //向USB发送数据,数据区不加0
        public static void SendData(int id, byte[] temp)
        {
            int TempLength = temp.Length;

            if (MyDeviceList[id] != null)
            {
                lock (MyDeviceList[id])
                {
                    Register.Byte80H = (byte)(Register.Byte80H | 0x02);
                    SendCMD(id, 0x80, Register.Byte80H);
                    Register.Byte80H = (byte)(Register.Byte80H & 0xFD);
                    SendCMD(id, 0x80, Register.Byte80H);
                    if (MyDeviceList[id].BulkOutEndPt != null)
                    {
                        bool tag = MyDeviceList[id].BulkOutEndPt.XferData(ref temp, ref TempLength);
                        if (!tag)
                        {
                            MyLog.Error("传输数据到USB板卡失败");
                        }
                        else
                        {
                            MyLog.Info("传输成功:" + TempLength.ToString());
                        }
                    }
                }
            }
            else
            {
                MyLog.Error("USB设备未连接!");
            }
        }
示例#2
0
        private void button3_Click_1(object sender, EventArgs e)
        {
            String Str_Content = textBox7.Text.Replace(" ", "");
            int    lenth       = (Str_Content.Length) / 2;

            if (lenth >= 0)
            {
                int AddToFour = lenth % 4;
                if (AddToFour != 0)
                {
                    for (int i = 0; i < (4 - AddToFour); i++)
                    {
                        Str_Content += "00";
                    }
                }

                for (int j = 0; j < 8; j++)
                {
                    byte[] temp = StrToHexByte((0x1D00 + j).ToString("x4") + lenth.ToString("x4") + Str_Content + textBox9.Text);
                    temp[4] = (byte)(0x1 + j);
                    USB.SendData(Data.OnlyId, temp);
                }
            }
            else
            {
                MyLog.Error("请至少输入4个Byte的数据");
            }
        }
示例#3
0
        public static void SendCMD(int id, byte ReqCode, byte Value)
        {
            if (MyDeviceList[id] != null)
            {
                CyControlEndPoint CtrlEndPt = null;
                CtrlEndPt = MyDeviceList[id].ControlEndPt;
                if (CtrlEndPt != null)
                {
                    lock (MyDeviceList[id])
                    {
                        CtrlEndPt.Target    = CyConst.TGT_DEVICE;
                        CtrlEndPt.ReqType   = CyConst.REQ_VENDOR;
                        CtrlEndPt.Direction = CyConst.DIR_TO_DEVICE;
                        CtrlEndPt.Index     = 0;
                        CtrlEndPt.ReqCode   = ReqCode;
                        CtrlEndPt.Value     = (ushort)Value;
                        int    len = 8;
                        byte[] buf = new byte[8];
                        CtrlEndPt.XferData(ref buf, ref len);

                        MyLog.Info("向USB机箱" + id.ToString() + "发送指令0x" + ReqCode.ToString("x2") + " 0x" + Value.ToString("x2") + "成功");
                    }
                }
            }
            else
            {
                MyLog.Error("USB设备未连接!");
            }
        }
示例#4
0
        private void button1_Click(object sender, EventArgs e)
        {
            if (this.button1.Text == "开始读取")
            {
                this.textBox1.Text = null;
                this.textBox2.Text = null;
                this.textBox3.Text = null;

                this.button1.Text = "停止读取";


                if (USB.MyDeviceList[Data.OnlyId] != null)
                {
                    CyControlEndPoint CtrlEndPt = null;
                    CtrlEndPt = USB.MyDeviceList[Data.OnlyId].ControlEndPt;

                    if (CtrlEndPt != null)
                    {
                        USB.SendCMD(Data.OnlyId, 0x80, 0x01);
                        USB.SendCMD(Data.OnlyId, 0x80, 0x00);

                        USB.MyDeviceList[Data.OnlyId].Reset();

                        Register.Byte80H = (byte)(Register.Byte80H | 0x04);
                        USB.SendCMD(Data.OnlyId, 0x80, Register.Byte80H);

                        this.btn_80_2.Text = "1:接收";
                    }

                    FileThread = new SaveFile();
                    FileThread.FileInit();
                    FileThread.FileSaveStart();

                    MyLog.Info("开始读取");
                    RecvTag = true;

                    ThisCount = 0;
                    LastCount = 0;

                    new Thread(() => { RecvAllUSB(); }).Start();
                    new Thread(() => { DealWithADFun(); }).Start();
                }
                else
                {
                    MyLog.Error("单元测试仪未连接!");
                }
            }
            else
            {
                this.button1.Text = "开始读取";
                ThisCount         = 0;
                LastCount         = 0;
                RecvTag           = false;
                Thread.Sleep(500);
                if (FileThread != null)
                {
                    FileThread.FileClose();
                }
            }
        }
示例#5
0
        public void FileCreateDat(string Path, out FileStream file)
        {
            if (!Directory.Exists(Path))
            {
                Directory.CreateDirectory(Path);
            }

            DirectoryInfo folder = new DirectoryInfo(Path);

            try
            {
                foreach (FileInfo tempfile in folder.GetFiles("*.*"))
                {
                    string name = tempfile.Name;
                    if (tempfile.Length == 0)
                    {
                        Trace.WriteLine("删除文件" + tempfile.FullName);
                        File.Delete(tempfile.FullName);
                    }
                }
            }
            catch (Exception ex)
            {
                MyLog.Error(ex.Message);
            }


            string timestr  = string.Format("{0}-{1:D2}-{2:D2} {3:D2}:{4:D2}:{5:D2}", DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day, DateTime.Now.Hour, DateTime.Now.Minute, DateTime.Now.Second);
            string filename = Path + timestr + ".dat";

            file = new FileStream(filename, FileMode.Create);
            myFileList_dat.Add(file);
        }
示例#6
0
        private void button9_Click_2(object sender, EventArgs e)
        {
            Register.Byte81H = (byte)(Register.Byte81H | (byte)(0x01 << 2));
            USB.SendCMD(Data.OnlyId, 0x81, Register.Byte81H);

            Register.Byte81H = (byte)(Register.Byte81H & (byte)(0x7f - (byte)(0x01 << 2)));
            USB.SendCMD(Data.OnlyId, 0x81, Register.Byte81H);


            String Str_Content = textBox_value_1d02.Text.Trim();
            int    lenth       = (Str_Content.Length) / 2;

            if (lenth >= 0)
            {
                int AddToFour = lenth % 4;
                if (AddToFour != 0)
                {
                    for (int i = 0; i < (4 - AddToFour); i++)
                    {
                        Str_Content += "00";
                    }
                }

                byte[] temp = StrToHexByte("1D02" + lenth.ToString("x4") + Str_Content + "C0DEC0DEC0DEC0DEC0DEC0DEC0DEC0DE");

                USB.SendData(Data.OnlyId, temp);
            }
            else
            {
                MyLog.Error("请至少输入4个Byte的数据");
            }
        }
示例#7
0
        //向USB发送数据,数据区加3个0
        public static void SendDataByInt(int id, byte[] temp)
        {
            byte[] SendBytes = new byte[1024 * 16];

            int temp_lenth      = temp.Length;
            int SendBytes_lenth = 4 * (temp_lenth - 4) + 4;

            for (int j = 0; j < 4; j++)
            {
                SendBytes[j] = temp[j];
            }
            for (int i = 4; i < SendBytes_lenth; i++)
            {
                if (i % 4 == 0)
                {
                    SendBytes[i] = temp[(i / 4) + 3];
                }
                if (i % 4 == 1)
                {
                    SendBytes[i] = 0x0;
                }
                if (i % 4 == 2)
                {
                    SendBytes[i] = 0x0;
                }
                if (i % 4 == 3)
                {
                    SendBytes[i] = 0x0;
                }
            }
            if (MyDeviceList[id] != null)
            {
                lock (MyDeviceList[id])
                {
                    Register.Byte80H = (byte)(Register.Byte80H | 0x02);
                    SendCMD(id, 0x80, Register.Byte80H);
                    Register.Byte80H = (byte)(Register.Byte80H & 0xFD);
                    SendCMD(id, 0x80, Register.Byte80H);

                    if (MyDeviceList[id].BulkOutEndPt != null)
                    {
                        bool tag = MyDeviceList[id].BulkOutEndPt.XferData(ref SendBytes, ref SendBytes_lenth);
                        if (tag)
                        {
                            MyLog.Info("传输数据到USB板卡成功");
                        }
                        else
                        {
                            MyLog.Error("传输数据到USB板卡失败");
                        }
                    }
                }
            }
            else
            {
                MyLog.Error("USB设备未连接!");
            }
        }
示例#8
0
        /*Summary
         * This is the event handler for device removal. This method resets the device count and searches for the device with VID-PID 04b4-1003
         */
        void UsbDevices_DeviceRemoved(object sender, EventArgs e)
        {
            USBEventArgs evt           = (USBEventArgs)e;
            USBDevice    RemovedDevice = evt.Device;

            string RemovedDeviceName = evt.FriendlyName;

            MyLog.Error(RemovedDeviceName + "板卡断开");

            int key = int.Parse(evt.ProductID.ToString("x4").Substring(0, 2), System.Globalization.NumberStyles.HexNumber);

            USB.MyDeviceList[key] = null;
        }
示例#9
0
        private void ComPortRecv_DataReceived(object sender, SerialDataReceivedEventArgs e)
        {
            //throw new NotImplementedException();
            Thread.Sleep(100);
            try
            {
                byte[] byteRead = new byte[ComPortRecv.BytesToRead];
                ComPortRecv.Read(byteRead, 0, byteRead.Length);
                //5a 54 01 02 03 04 05 06 07 08 00 5a fe 09 0a 0b 00 ff ff 00 0e 00 aa 5a fe
                int    N         = 53 + 11;
                byte[] SendToMac = new byte[N];
                SendToMac[0] = 0x5a;
                SendToMac[1] = 0x54;
                for (int i = 2; i < 53 + 2; i++)
                {
                    SendToMac[i] = 0x00;
                }
                SendToMac[2] = 0x81;

                SendToMac[N - 9] = 0x00;
                SendToMac[N - 8] = 0xff;
                SendToMac[N - 7] = 0xff;
                SendToMac[N - 6] = 0x00;
                SendToMac[N - 5] = 0x53;
                SendToMac[N - 4] = 0x00;
                SendToMac[N - 3] = 0xaa;
                SendToMac[N - 2] = 0x5a;
                SendToMac[N - 1] = 0xfe;

                if (byteRead.Length > 0)
                {
                    if (byteRead[0] == 0xAB)
                    {
                        if (ExecDec)
                        {
                            DisLen -= DecKM;
                        }
                        for (int j = 0; j < 30; j++)
                        {
                            this.textBox11.BeginInvoke(new Action(() => { this.textBox11.AppendText((DisLen).ToString() + "m, "); }));

                            //if (DisLen > 0)
                            //{
                            //    SendToMac[11] = (byte)(DisLen & 0xff);
                            //    SendToMac[12] = (byte)((DisLen >> 8) & 0xff);
                            //    SendToMac[13] = (byte)((DisLen >> 16) & 0xff);
                            //    SendToMac[14] = (byte)((DisLen >> 24) & 0xff);
                            //}
                            if (DisLen > 125 && DisLen <= 145)
                            {
                                SendToMac[11] = 0x1f;
                                SendToMac[12] = 0xff;
                                SendToMac[13] = 0xff;
                                SendToMac[14] = 0xff;
                            }
                            else if (DisLen > 120 && DisLen <= 125)
                            {
                                SendToMac[11] = 0x0f;
                                SendToMac[12] = 0xff;
                                SendToMac[13] = 0xff;
                                SendToMac[14] = 0xff;
                            }
                            else if (DisLen > 40 && DisLen <= 120)
                            {
                                SendToMac[11] = 0x00;
                                SendToMac[12] = 0xff;
                                SendToMac[13] = 0xff;
                                SendToMac[14] = 0xff;
                            }
                            else if (DisLen > 30 && DisLen <= 40)
                            {
                                SendToMac[11] = 0x00;
                                SendToMac[12] = 0x0f;
                                SendToMac[13] = 0xff;
                                SendToMac[14] = 0xff;
                            }
                            else if (DisLen > 15 && DisLen <= 30)
                            {
                                SendToMac[11] = 0x00;
                                SendToMac[12] = 0x00;
                                SendToMac[13] = 0xff;
                                SendToMac[14] = 0xff;
                            }
                            else if (DisLen > 8.5 && DisLen <= 15)
                            {
                                SendToMac[11] = 0x00;
                                SendToMac[12] = 0x00;
                                SendToMac[13] = 0x0f;
                                SendToMac[14] = 0xff;
                            }
                            else
                            {
                                SendToMac[11] = 0x00;
                                SendToMac[12] = 0x00;
                                SendToMac[13] = 0x00;
                                SendToMac[14] = 0xff;
                            }

                            ComPortRecv.Write(SendToMac, 0, SendToMac.Count());
                            // Thread.Sleep(1);
                        }
                    }
                    else
                    {
                        String temp = "";
                        for (int i = 0; i < byteRead.Length; i++)
                        {
                            temp += byteRead[i].ToString("x2");
                        }
                        MyLog.Error("串口收到非0xAB数据!-----" + temp);
                    }
                }
            }
            catch (Exception ex)
            {
                Trace.WriteLine(ex.Message + "--ComPortRecv_DataReceived");
            }
        }
示例#10
0
        void DealWithLongFrame(ref byte[] TempBuf, ref int TempTag)
        {
            ThisCount = TempStoreBuf[2] * 256 + TempStoreBuf[3];
            if (LastCount != 0 && ThisCount != 0 && (ThisCount - LastCount != 1))
            {
                MyLog.Error("出现漏帧情况!!");
                Trace.WriteLine("出现漏帧情况:" + LastCount.ToString("x4") + "--" + ThisCount.ToString("x4"));
            }
            LastCount = ThisCount;

            byte[] buf_LongFrame = new byte[4096];
            Array.Copy(TempStoreBuf, 0, buf_LongFrame, 0, 4096);

            Array.Copy(TempStoreBuf, 4096, TempStoreBuf, 0, TempStoreBufTag - 4096);
            TempStoreBufTag -= 4096;

            RecvdMB      += 4;
            Recv4KCounts += 1;
            if (buf_LongFrame[0] == 0xff && buf_LongFrame[1] == 0x01)
            {
                byte[] bufsav = new byte[4092];
                Array.Copy(buf_LongFrame, 4, bufsav, 0, 4092);
                SaveFile.Lock_3.EnterWriteLock();
                SaveFile.DataQueue_SC3.Enqueue(bufsav);
                SaveFile.Lock_3.ExitWriteLock();
            }
            if (buf_LongFrame[0] == 0xff && buf_LongFrame[1] == 0x02)
            {
                byte[] bufsav = new byte[4092];
                Array.Copy(buf_LongFrame, 4, bufsav, 0, 4092);
                SaveFile.Lock_4.EnterWriteLock();
                SaveFile.DataQueue_SC4.Enqueue(bufsav);
                SaveFile.Lock_4.ExitWriteLock();
            }
            if (buf_LongFrame[0] == 0xff && buf_LongFrame[1] == 0x03)
            {
                byte[] bufsav = new byte[4092];
                Array.Copy(buf_LongFrame, 4, bufsav, 0, 4092);
                SaveFile.Lock_5.EnterWriteLock();
                SaveFile.DataQueue_SC5.Enqueue(bufsav);
                SaveFile.Lock_5.ExitWriteLock();
            }
            if (buf_LongFrame[0] == 0xff && buf_LongFrame[1] == 0x04)
            {
                byte[] bufsav = new byte[4092];
                Array.Copy(buf_LongFrame, 4, bufsav, 0, 4092);
                SaveFile.Lock_6.EnterWriteLock();
                SaveFile.DataQueue_SC6.Enqueue(bufsav);
                SaveFile.Lock_6.ExitWriteLock();
            }

            if (buf_LongFrame[0] == 0xff && buf_LongFrame[1] == 0x08)
            {
                //FF08为短帧通道
                byte[] bufsav = new byte[4092];
                Array.Copy(buf_LongFrame, 4, bufsav, 0, 4092);
                SaveFile.Lock_2.EnterWriteLock();
                SaveFile.DataQueue_SC2.Enqueue(bufsav);
                SaveFile.Lock_2.ExitWriteLock();

                for (int i = 0; i < 6; i++)
                {
                    if (bufsav[i * 682 + 0] == 0x1D && bufsav[i * 682 + 1] == 0x00)
                    {
                        int    num     = bufsav[i * 682 + 2] * 256 + bufsav[i * 682 + 3];//有效位
                        byte[] buf1D0x = new byte[num];
                        Array.Copy(bufsav, i * 682 + 4, buf1D0x, 0, num);
                        SaveFile.Lock_7.EnterWriteLock();
                        SaveFile.DataQueue_SC7.Enqueue(buf1D0x);
                        SaveFile.Lock_7.ExitWriteLock();
                    }
                    else if (bufsav[i * 682 + 0] == 0x1D && bufsav[i * 682 + 1] == 0x01)
                    {
                        int    num     = bufsav[i * 682 + 2] * 256 + bufsav[i * 682 + 3];//有效位
                        byte[] buf1D0x = new byte[num];
                        Array.Copy(bufsav, i * 682 + 4, buf1D0x, 0, num);
                        SaveFile.Lock_8.EnterWriteLock();
                        SaveFile.DataQueue_SC8.Enqueue(buf1D0x);
                        SaveFile.Lock_8.ExitWriteLock();
                    }
                    else if (bufsav[i * 682 + 0] == 0x1D && bufsav[i * 682 + 1] == 0x02)
                    {
                        int    num     = bufsav[i * 682 + 2] * 256 + bufsav[i * 682 + 3];//有效位
                        byte[] buf1D0x = new byte[num];
                        Array.Copy(bufsav, i * 682 + 4, buf1D0x, 0, num);
                        SaveFile.Lock_9.EnterWriteLock();
                        SaveFile.DataQueue_SC9.Enqueue(buf1D0x);
                        SaveFile.Lock_9.ExitWriteLock();
                    }
                    else if (bufsav[i * 682 + 0] == 0x1D && bufsav[i * 682 + 1] == 0x03)
                    {
                        int    num     = bufsav[i * 682 + 2] * 256 + bufsav[i * 682 + 3];//有效位
                        byte[] buf1D0x = new byte[num];
                        Array.Copy(bufsav, i * 682 + 4, buf1D0x, 0, num);
                        SaveFile.Lock_10.EnterWriteLock();
                        SaveFile.DataQueue_SC10.Enqueue(buf1D0x);
                        SaveFile.Lock_10.ExitWriteLock();
                    }
                    else if (bufsav[i * 682 + 0] == 0x1D && bufsav[i * 682 + 1] == 0x04)
                    {
                        int    num     = bufsav[i * 682 + 2] * 256 + bufsav[i * 682 + 3];//有效位
                        byte[] buf1D0x = new byte[num];
                        Array.Copy(bufsav, i * 682 + 4, buf1D0x, 0, num);
                        SaveFile.Lock_11.EnterWriteLock();
                        SaveFile.DataQueue_SC11.Enqueue(buf1D0x);
                        SaveFile.Lock_11.ExitWriteLock();
                    }
                    else if (bufsav[i * 682 + 0] == 0x1D && bufsav[i * 682 + 1] == 0x05)
                    {
                        int    num     = bufsav[i * 682 + 2] * 256 + bufsav[i * 682 + 3];//有效位
                        byte[] buf1D0x = new byte[num];
                        Array.Copy(bufsav, i * 682 + 4, buf1D0x, 0, num);
                        SaveFile.Lock_12.EnterWriteLock();
                        SaveFile.DataQueue_SC12.Enqueue(buf1D0x);
                        SaveFile.Lock_12.ExitWriteLock();
                    }
                    else if (bufsav[i * 682 + 0] == 0x1D && bufsav[i * 682 + 1] == 0x06)
                    {
                        int    num     = bufsav[i * 682 + 2] * 256 + bufsav[i * 682 + 3];//有效位
                        byte[] buf1D0x = new byte[num];
                        Array.Copy(bufsav, i * 682 + 4, buf1D0x, 0, num);
                        SaveFile.Lock_13.EnterWriteLock();
                        SaveFile.DataQueue_SC13.Enqueue(buf1D0x);
                        SaveFile.Lock_13.ExitWriteLock();

                        lock (Data.ADList01)
                        {
                            for (int j = 0; j < num; j++)
                            {
                                Data.ADList01.Add(buf1D0x[j]);
                            }
                        }
                    }
                    else if (bufsav[i * 682 + 0] == 0x1D && bufsav[i * 682 + 1] == 0x07)
                    {
                        int    num     = bufsav[i * 682 + 2] * 256 + bufsav[i * 682 + 3];//有效位
                        byte[] buf1D0x = new byte[num];
                        Array.Copy(bufsav, i * 682 + 4, buf1D0x, 0, num);
                        SaveFile.Lock_14.EnterWriteLock();
                        SaveFile.DataQueue_SC14.Enqueue(buf1D0x);
                        SaveFile.Lock_14.ExitWriteLock();
                        lock (Data.ADList02)
                        {
                            for (int j = 0; j < num; j++)
                            {
                                Data.ADList02.Add(buf1D0x[j]);
                            }
                        }
                    }
                    else if (bufsav[i * 682 + 0] == 0x1D && bufsav[i * 682 + 1] == 0x0f)
                    {
                        //空闲帧
                    }
                    else
                    {
                        Trace.WriteLine("FF08通道出错!");
                    }
                }
            }
        }
示例#11
0
        private void RecvAllUSB()
        {
            CyUSBDevice MyDevice01 = USB.MyDeviceList[Data.OnlyId];

            startDT = DateTime.Now;
            DateTime midDT = startDT;

            RecvdMB         = 0;
            TempStoreBufTag = 0;
            while (RecvTag)
            {
                if (MyDevice01.BulkInEndPt != null)
                {
                    byte[] buf    = new byte[4096];
                    int    buflen = 4096;

                    MyDevice01.BulkInEndPt.XferData(ref buf, ref buflen);

                    if (buflen > 0)
                    {
                        Trace.WriteLine("收到数据包长度为:" + buflen.ToString());
                        Array.Copy(buf, 0, TempStoreBuf, TempStoreBufTag, buflen);
                        TempStoreBufTag += buflen;

                        byte[] Svbuf = new byte[buflen];
                        Array.Copy(buf, Svbuf, buflen);

                        SaveFile.Lock_1.EnterWriteLock();
                        SaveFile.DataQueue_SC1.Enqueue(Svbuf);
                        SaveFile.Lock_1.ExitWriteLock();

                        while (TempStoreBufTag >= 4096)
                        {
                            if (TempStoreBuf[0] == 0xff && (0x0 <= TempStoreBuf[1]) && (TempStoreBuf[1] < 0x11))
                            {
                                DealWithLongFrame(ref TempStoreBuf, ref TempStoreBufTag);
                            }
                            else
                            {
                                MyLog.Error("收到异常帧!");
                                Trace.WriteLine("收到异常帧" + TempStoreBufTag.ToString());
                                Array.Clear(TempStoreBuf, 0, TempStoreBufTag);
                                TempStoreBufTag = 0;
                            }
                        }
                    }
                    else if (buflen == 0)
                    {
                        //   Trace.WriteLine("数传422机箱 收到0包-----0000000000");
                    }
                    else
                    {
                        Trace.WriteLine("收到buflen <0");
                    }

                    endDT = DateTime.Now;
                    double tempTime = endDT.Subtract(midDT).TotalSeconds;
                    if (tempTime > 2)
                    {
                        midDT = endDT;
                        double tempMB = Recv4KCounts / 256;
                        Recv4KCounts = 0;
                        this.textBox4.BeginInvoke(new Action(() =>
                        {
                            double speed            = tempMB / tempTime;
                            textBox4.Text           = speed.ToString();
                            this.progressBar1.Value = (int)speed;
                        }));
                    }
                }
            }
            endDT = DateTime.Now;

            this.textBox1.BeginInvoke(
                new Action(() =>
            {
                double costTime = endDT.Subtract(startDT).TotalSeconds;
                double RecvdM   = RecvdMB / 1024;
                textBox1.Text   = costTime.ToString();
                textBox2.Text   = RecvdM.ToString();
                textBox3.Text   = (RecvdM / costTime).ToString();
            }));
        }
示例#12
0
        private void WriteToFileSC(int key, object file, ref Queue <byte[]> myQueue, ref ReaderWriterLockSlim myLock)
        {
            Trace.WriteLine("Start WriteToFileSC Thread:" + key.ToString());
            FileStream   myfile = (FileStream)file;
            BinaryWriter bw     = new BinaryWriter(myfile);

            //     FileInfo fileInfo;

            while (SaveOn)
            {
                if (myQueue.Count() > 0)
                {
                    try
                    {
                        myLock.EnterReadLock();
                        bw.Write(myQueue.Dequeue());
                        bw.Flush();
                        myLock.ExitReadLock();

                        #region 分割文件,防止文件过大
                        long FileSizeMB = myfile.Length / (1024 * 1024 * 1024);
                        if (FileSizeMB > 1)
                        {
                            myFileList_dat[key].Flush();

                            string Path2 = myFileList_dat[key].Name;
                            int    count = Path2.LastIndexOf("\\");
                            Path2 = Path2.Substring(0, count + 1);

                            myFileList_dat[key].Close();

                            FileStream newFile;
                            string     timestr  = string.Format("{0}-{1:D2}-{2:D2} {3:D2}:{4:D2}:{5:D2}", DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day, DateTime.Now.Hour, DateTime.Now.Minute, DateTime.Now.Second);
                            string     filename = Path2 + timestr + ".dat";
                            newFile = new FileStream(filename, FileMode.Create);

                            myFileList_dat.Remove(myFileList_dat[key]);
                            myFileList_dat.Insert(key, newFile);

                            break;
                            //break跳出循环会执行新线程
                        }
                        #endregion
                    }
                    catch (Exception e)
                    {
                        bw.Close();
                        Trace.WriteLine(myQueue.Count());
                        MyLog.Error(e.Message);
                        break;
                    }
                }
                else
                {
                    Thread.Sleep(200);
                    //                  Trace.WriteLine("Queue0 is empty!!");
                }
            }
            bw.Close();
            Trace.WriteLine("Leaving WriteToFileSC:" + key.ToString());

            if (SaveOn)
            {
                WriteToFileSC(key, myFileList_dat[key], ref myQueue, ref myLock);
            }
        }
示例#13
0
        private void button_translate68_Click(object sender, EventArgs e)
        {
            Button btn   = (Button)sender;
            string input = textBox11.Text;

            string trans_buf = null;

            //是否判断定长?
            if (input.Length == 162 * 2)
            {
                byte[] buf_before_trans = StrToHexByte(input);

                for (int i = 0; i < buf_before_trans.Length; i++)
                {
                    trans_buf += Convert.ToString(buf_before_trans[i], 2).PadLeft(8, '0');
                }

                if (trans_buf.Length == 1296)
                {
                    trans_buf.Substring(0, 1296);
                }


                byte[] buf_after_trans = new byte[217];
                string first           = trans_buf.Substring(0, 6);

                byte hexcrc = Convert.ToByte(first.PadLeft(8, '0'), 2);

                for (int i = 0; i < 216; i++)
                {
                    string temp = trans_buf.Substring(i * 6, 6);

                    buf_after_trans[i] = Convert.ToByte(temp.PadLeft(8, '0'), 2);
                    if (i == 0)
                    {
                        hexcrc = Convert.ToByte(temp.PadLeft(8, '0'), 2);
                    }
                    else
                    {
                        byte b2 = Convert.ToByte(temp.PadLeft(8, '0'), 2);
                        hexcrc ^= b2;
                    }
                }
                buf_after_trans[216] = (byte)(hexcrc & 0x3f);

                string output = null;
                for (int i = 0; i < 217; i++)
                {
                    output += buf_after_trans[i].ToString("x2");
                }

                if (btn.Name == "button_translate68_1")
                {
                    textBox_value_1d01.Text = output;
                }
                else if (btn.Name == "button_translate68_2")
                {
                    textBox_value_1d02.Text = output;
                }
                else
                {
                }
            }
            else
            {
                MyLog.Error("数据长度不正确,不是162Bytes!");
            }
        }
示例#14
0
        private void button13_Click(object sender, EventArgs e)
        {
            Button btn = (Button)sender;

            String Path = Program.GetStartupPath() + @"注入码本\";

            if (!Directory.Exists(Path))
            {
                Directory.CreateDirectory(Path);
            }
            openFileDialog1.InitialDirectory = Path;
            string tmpFilter = openFileDialog1.Filter;
            string title     = openFileDialog1.Title;

            openFileDialog1.Title  = "选择要注入的码表文件";
            openFileDialog1.Filter = "txt files (*.txt)|*.txt|All files (*.*) | *.*";

            if (openFileDialog1.ShowDialog() == DialogResult.OK) //selecting bitstream
            {
                MyLog.Info("选取" + openFileDialog1.FileName + "文件成功");

                try
                {
                    string temp = System.IO.File.ReadAllText(openFileDialog1.FileName);
                    if (btn.Name == "button13")
                    {
                        textBox_value_1d03.Text = temp;
                    }
                    else if (btn.Name == "button14")
                    {
                        textBox_value_1d04.Text = temp;
                    }
                    else if (btn.Name == "button15")
                    {
                        textBox_value_1d01.Text = temp;
                    }
                    else if (btn.Name == "button16")
                    {
                        textBox_value_1d02.Text = temp;
                    }
                    else if (btn.Name == "button17")
                    {
                        textBox_value.Text = temp;
                    }
                    else if (btn.Name == "button4")
                    {
                        textBox7.Text = temp;
                    }
                    else if (btn.Name == "button18")
                    {
                        textBox11.Text = temp;
                    }
                    else if (btn.Name == "button19")
                    {
                        textBox12.Text = temp;
                    }
                    else if (btn.Name == "button21")
                    {
                        textBox13.Text = temp;
                    }
                    else
                    {
                        ;
                    }
                }
                catch (Exception ex)
                {
                    MyLog.Error(ex.ToString());
                };
            }
        }