public MainViewModel()
        {
            if (srv == null)
            {
                // init serial device
                srv = new ModbusServer("UART0");
            }

            _lookup32 = createLookup32();
            address = 100;
            function = 3;
            register = 1;
            length = 1;
            frequency = 100;
            writingTimeout = 100;
            readingTimeout = 100;
            results = new ObservableCollection<string>();
        }
        public async Task Handle(string type)
        {
            string msgTemp = "TxD:{0} || RxD: \"{1}\"";
            string msgTempDebug = "TxD:{0} Elapsed time:{1}ms\r\nRxD: \"{2}\" Elapsed time:{3}ms";

            string txdMsg = string.Format(" data=\"{0}\", crc=\"{1}\" ", Modbus, CRC);
            string rxdMsg = "";

            //modbus request
            string command = Modbus + CRC;
            byte[] cache = convertHexToBytes(command);

            var buffer = cache.AsBuffer();
            byte[] result;

            switch (type)
            {
                case "Sending":
                    try
                    {
                        await srv.Open(WritingTimeout, ReadingTimeout);
                        await srv.Send(buffer);
                        var received = await srv.Receive();
                        srv.Clear();

                        //modbus response
                        result = received.ToArray();

                        /*
                        //byte convert to string sample
                        Collection<string> resultStringCollection = new Collection<string>();
                        foreach (var b in result)
                        {
                            resultStringCollection.Add(b.ToString("X2"));
                        }
                        */
                        rxdMsg = byteArrayToHexViaLookup32(result);
                    }
                    catch (Exception ex)
                    {
                        rxdMsg = ex.Message.Replace("\r\n", "\\r\\n");
                    }

                    Results.Insert(0, string.Format(msgTemp, txdMsg, rxdMsg));
                    break;
                case "Continuous sending":
                    try
                    {
                        Results.Insert(0, "Start sending");
                        await srv.Open(WritingTimeout, ReadingTimeout);

                        for (int i = 0; i < Frequency; i++)
                        {
                            var begin = DateTime.Now;
                            await srv.Send(buffer);
                            var writeSpan = DateTime.Now;

                            var received = await srv.Receive();
                            var readSpan = DateTime.Now;

                            srv.Clear();

                            //modbus response
                            result = received.ToArray();
                            rxdMsg = byteArrayToHexViaLookup32(result);

                            Results.Insert(0, string.Format(msgTempDebug, txdMsg, (writeSpan - begin).TotalMilliseconds, rxdMsg, (readSpan - writeSpan).TotalMilliseconds));
                        }
                    }
                    catch (Exception ex)
                    {
                        rxdMsg = ex.Message.Replace("\r\n", "\\r\\n");
                        Results.Insert(0, string.Format(msgTemp, txdMsg, rxdMsg));
                    }
                    Results.Insert(0, "End sending");
                    break;
                case "Reconnect":
                    if (srv.Status == ModbusServer.ModbusServerStatus.Opened)
                    {
                        srv.Cancel();
                        srv.Close();
                        srv = null;
                        srv = new ModbusServer("UART0");
                        await srv.Open();
                    }
                    break;
                default:
                    break;
            }
        }