Ejemplo n.º 1
0
        public byte[] GetData()
        {
            List<byte> result = new List<byte>();
            byte[] byteLabel = Encoding.ASCII.GetBytes(Label);
            Writer.AddBytes(result, byteLabel);

            foreach (Frame frame in Frames)
            {
                result.AddRange(frame.GetData());
            }

            return result.ToArray();
        }
Ejemplo n.º 2
0
        /// <summary>兄弟ノードを取得する。
        /// </summary>
        /// <param name="node"></param>
        /// <returns></returns>
        public static TreeNode[] GetBrotherNodes(this TreeNode node)
        {
            var broNodes = new List<TreeNode>();

            for (var iNode = node.PrevNode; iNode != null; iNode = iNode.PrevNode)
            {
                broNodes.Add(iNode);
            }

            broNodes.Reverse();

            for (var iNode = node.NextNode; iNode != null; iNode = iNode.NextNode)
            {
                broNodes.Add(iNode);
            }

            return broNodes.ToArray();
        }
        private List<int> AddFiles()
        {
            List<string> filenames = new List<string>();
            List<string> filedescs = new List<string>();
            for (int i = 0; i < dataGridView1.Rows.Count; i++)
            {
                filenames.Add(dataGridView1.Rows[i].Cells[0].Value.ToString());
                filedescs.Add(dataGridView1.Rows[i].Cells[1].Value.ToString());
            }
            AddMultiFilesMessage amfm = new AddMultiFilesMessage();
            amfm.filenames = filenames.ToArray<string>();
            amfm.filedescs = filedescs.ToArray<string>();
            amfm.project = Project;
            AddMultiFilesReturn idlist = client.AddMultiFiles(amfm);

            btnUpload.Enabled = false;
            lblError.Text = "Upload done";
            return idlist.ids.ToList();
        }
Ejemplo n.º 4
0
        public BufferManager(long maxBufferPoolSize, int maxBufferSize)
        {
            //_bufferManager = System.ServiceModel.Channels.BufferManager.CreateBufferManager(maxBufferPoolSize, maxBufferSize);

            if (maxBufferPoolSize < maxBufferSize) throw new ArgumentOutOfRangeException();
            if (maxBufferPoolSize == 0) throw new ArgumentOutOfRangeException();

            _maxBufferPoolSize = maxBufferPoolSize;
            _maxBufferSize = maxBufferSize;

            var sizes = new List<int>();
            var buffers = new List<LinkedList<WeakReference>>();

            for (int i = 256; i < _maxBufferSize; i *= 2)
            {
                sizes.Add(i);
                buffers.Add(new LinkedList<WeakReference>());
            }

            _sizes = sizes.ToArray();
            _buffers = buffers.ToArray();

            _watchTimer = new System.Threading.Timer(this.WatchTimer, null, new TimeSpan(0, 0, 30), new TimeSpan(0, 0, 30));
        }
Ejemplo n.º 5
0
        // Data Received Delegate Trigger
        void comPort_DataReceived(object sender, SerialDataReceivedEventArgs e)
        {
            try
            {
                //Thread.Sleep(2000);
                //byte[] ReadSerialData = new byte[comPort.BytesToRead];

                //string TotalSerialData = "";
                //string stringData = "";

                List<byte> ListByte = new List<byte>();
                byte[] ReadSerialData;

                do
                {
                    int numOfBytes = comPort.BytesToRead;
                    ReadSerialData = new byte[numOfBytes];
                    comPort.Read(ReadSerialData, 0, numOfBytes);
                    ListByte.AddRange(ReadSerialData);
                    //stringData = Encoding.UTF8.GetString(ReadSerialData, 0, numOfBytes);
                    //TotalSerialData = TotalSerialData + stringData;
                    PauseForMilliSeconds(40);

                } while (comPort.BytesToRead > 0);

                //do
                //{
                //    Byte ReadSerialData1;
                //    ReadSerialData1 = (byte)comPort.ReadByte();
                //    ListByte.Add(ReadSerialData1);
                //} while (comPort.BytesToRead > 0);

                if (ListByte[ListByte.Count - 2] == 0x0d)
                {
                    if (ListByte[ListByte.Count - 1] == 0x0a)
                    {
                        Console.WriteLine("True");
                        WriteEOT();

                    }
                }

                ReadSerialData = new byte[ListByte.Count];

                ReadSerialData = ListByte.ToArray();
                //do
                //{
                    //int numOfBytes = comPort.BytesToRead;
                    //ReadSerialData = new byte[numOfBytes];
                    //stringData = comPort.ReadTo("\r\n");
                    ////stringData = Encoding.UTF8.GetString(ReadSerialData, 0, numOfBytes);
                    //TotalSerialData = TotalSerialData + stringData;
                    //PauseForMilliSeconds(200);

                //} while (comPort.BytesToRead > 0);

                //byte[] ReadSerialData = new byte[comPort.BytesToRead];
                //comPort.Read(ReadSerialData, 0, ReadSerialData.Length);

                if (SerialDataReceived != null)
                {
                    SerialDataReceived((ReadSerialData));
                }
            }
            catch //(Exception ex)
            {
                throw;
            }
        }
Ejemplo n.º 6
0
        public void WriteEOT()
        {
            try
            {
                if (comPort.IsOpen == true)
                {
                    comPort.DiscardInBuffer();
                    comPort.DiscardOutBuffer();
                    //byte returnbyte = 4;
                    List<byte> list = new List<byte>();
                    //EOT
                    list.Add(4);

                    //Dash
                    list.Add(226);

                    //Hashtag
                    //list.Add(35);

                    //ACK
                    list.Add(6);

                    // !A
                    //list.Add(33);
                    //list.Add(65);
                    byte[] bytearr = new byte[list.Count];
                    bytearr = list.ToArray();
                    //byte[] bytearr = new byte[1];
                    //bytearr = Encoding.UTF8.GetBytes("!A");
                    //bytearr = BitConverter.GetBytes(returnbyte);
                    comPort.Write(bytearr, 0, bytearr.Length);
                }
            }
            catch //(Exception ex)
            {
                throw;
            }
        }
Ejemplo n.º 7
0
        public void WriteCLREEPROM()
        {
            try
            {
                comPort.DataReceived -= new SerialDataReceivedEventHandler(comPort_DataReceived);

                if (comPort.IsOpen == true)
                {
                    comPort.DiscardInBuffer();
                    comPort.DiscardOutBuffer();
                    //byte returnbyte = 4;
                    List<byte> list = new List<byte>();

                    // !A
                    list.Add(33);
                    list.Add(65);
                    byte[] bytearr = new byte[list.Count];
                    bytearr = list.ToArray();
                    //byte[] bytearr = new byte[1];
                    //bytearr = Encoding.UTF8.GetBytes("!A");
                    //bytearr = BitConverter.GetBytes(returnbyte);
                    comPort.Write(bytearr, 0, bytearr.Length);
                }
            }
            catch
            {
                throw;
            }
        }
Ejemplo n.º 8
0
        //自定义附加消息显示 周立山 2014.1.3
        private string[] TransAddMsgTxt(string addMsgTxt)
        {
            List<string> results = new List<string>();

            try
            {
                //addMsgTxt = "10/M100000/20/ME8A8";

                string[] addmsgtxts = addMsgTxt.Split('/');

                foreach (string s in addmsgtxts)
                {
                    if (!s.StartsWith("ME8"))
                        continue;

                    byte byt = Convert.ToByte(s.Substring(3), 16);

                    if ((byt & 128) != 0)
                        results.Add("制动/开");
                    else
                        results.Add("制动/关");
                    if ((byt & 64) != 0)
                        results.Add("左转向灯/开");
                    else
                        results.Add("左转向灯/关");
                    if ((byt & 32) != 0)
                        results.Add("右转向灯/开");
                    else
                        results.Add("右转向灯/关");
                    if ((byt & 16) != 0)
                        results.Add("远光灯/开");
                    else
                        results.Add("远光灯/关");
                    if ((byt & 8) != 0)
                        results.Add("近光灯/开");
                    else
                        results.Add("近光灯/关");
                }
            }
            catch
            {
                //Record.execFileRecord("自定义附加消息时失败!");
            }
            return results.ToArray();
        }
Ejemplo n.º 9
0
 /// <summary>子孫ノードを取得する。
 /// </summary>
 /// <param name="nodes">ツリーノードのコレクション。</param>
 /// <returns>子孫ノードの配列。</returns>
 public static TreeNode[] GetDescendants(this TreeNodeCollection nodes)
 {
     var list = new List<TreeNode>();
     TreeViewUtility.GetDescendants(nodes, list);
     return list.ToArray();
 }
Ejemplo n.º 10
0
 /// <summary>子孫ノードを取得する。
 /// </summary>
 /// <param name="node">ツリーノードオブジェクト。</param>
 /// <returns>子孫ノードの配列。</returns>
 public static TreeNode[] GetDescendants(this TreeNode node)
 {
     var list = new List<TreeNode>(TreeViewUtility.GetDescendants(node.Nodes));
     list.Insert(0, node);
     return list.ToArray();
 }
Ejemplo n.º 11
0
        private static bool TestFilters()
        {
            List<byte> values = new List<byte>() { 1, 2, 3, 5 };
            List<byte> original = new List<byte>(values);
            ColorBitPlaneChunk.Filter(values);
             Console.Write("Have filtered values");
            foreach (byte b in values)
            {
                Console.Write(" " + b);
            }

            Console.WriteLine(string.Empty);

            byte[] array = values.ToArray();
            ColorBitPlaneChunk.UnFilter(array);
            int index = 0;
            foreach (byte b in original)
            {
                if (array[index] != b)
                {
                    Console.WriteLine("Failed match in index " + index + " have original " + b + " and got instead " + array[index]);
                    return false;
                }

                index++;
            }

            return true;
        }
Ejemplo n.º 12
0
        /// <summary>
        /// There's probably a better way to do this
        /// </summary>
        /// <param name="bytes"></param>
        /// <param name="size"></param>
        /// <returns></returns>
        public static bool[] ConvertBytesToBools(byte[] bytes, int size)
        {
            List<bool> result = new List<bool>();

            int index = 0;
            for (int i = 0; i < bytes.Length; i++)
            {
                //read a bytes worth of bits at a time
                for (int j = 0; j < Writer.Masks.Length; j++)
                {
                    byte b = bytes[i];
                    bool boolean = (b & Writer.Masks[j]) != 0;
                    result.Add(boolean);
                    index++;
                    if (index >= size)
                    {
                        return result.ToArray();
                    }
                }
            }

            //oops
            throw new Exception("Failed to convert Bytes to Bools");
        }
Ejemplo n.º 13
0
        public byte[] Write(Frame frame)
        {
            List<byte> result = new List<byte>();
            foreach (Chunk chunk in frame.Chunks)
            {
            }

            return result.ToArray();
        }
Ejemplo n.º 14
0
        public byte[] GetData()
        {
            List<byte> result = new List<byte>();
            byte[] byteLabel = Encoding.ASCII.GetBytes(Label);
            Writer.AddBytes(result, byteLabel);

            foreach (Chunk chunk in Chunks)
            {
                result.AddRange(chunk.GetData());
            }

            //don't forget the size
            Writer.WriteSizeInt(result);

            return result.ToArray();
        }