Encoding.UTF8 different between NETMF and Full Framework

Hi all,

I’ve somthing strange when using UTF8 encoding between PC and a NETMF board, in that each pair byte is not the same between the source and the target…

Is there any difference between both implementations ?

Was one of my Idea, but maybe it would change All the Byte order…Why the pair one only ?

Example :
Send : 87 | 72 | 79 | 73 | 83
Receive: 83 | 72 | 65 | 73 | 81

@ LouisCpro - Do you have a small example… I did not experience differences so far …

ahhhh. same time posting and question :wink:

@ andre.marschalek -

I’m using e STM32, and an information that I missed : I’m working with RS485, no Ethernet at all !

@ LouisCpro - Oh God !

It seems to be a problem with the RS. In fact, even when removing the encoding, my read buffer is different than the one I send…

I have to investigate with my MAX3483…Maybe something is wrong in the schematic…

I am running on PC WebService for serving time to my spider. And it works this way (I did not optimize code, because it is only for testing purpose. After testing is done I will use DCF77):
PC code:


        private void StartServer()
        {

            TcpListener server = null;
            try
            {
                // Set the TcpListener on port 13000.
                Int32 port = 13000;
                IPAddress localAddr = IPAddress.Parse("192.168.1.2");

                // TcpListener server = new TcpListener(port);
                server = new TcpListener(localAddr, port);

                // Start listening for client requests.
                server.Start();

                // Buffer for reading data
                Byte[] bytes = new Byte[256];

                // Enter the listening loop.
                while (true)
                {

                    // Perform a blocking call to accept requests.
                    // You could also user server.AcceptSocket() here.
                    TcpClient client = server.AcceptTcpClient();


                    // Get a stream object for reading and writing
                    NetworkStream stream = client.GetStream();

                    int i;

                    byte[] msg = System.Text.Encoding.ASCII.GetBytes(DateTime.Now.ToString("M.d.yyyy HH:mm:ss").Replace(".", "/"));       //06/01/2011 10:50:33

                        // Send back a response.
                        stream.Write(msg, 0, msg.Length);

                    client.Close();
                }
            }
            catch (SocketException)
            {
            }
            finally
            {
                // Stop listening for new clients.
                server.Stop();
            }
        }

My client (Spider) code is:


        private bool GetTime()
        {
            try
            {
                using (Socket socket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp))
                {
                    IPEndPoint endPoint = new IPEndPoint(new IPAddress(new byte[] { 192, 168, 1, 2 }), 13000);
                    socket.ReceiveTimeout = 5000;
                    socket.SendTimeout = 5000;
                    socket.Connect(endPoint);
                    byte[] data = new byte[17];
                    int read = socket.Receive(data, 17, SocketFlags.None);
                    if (read < 17)
                        return false;
                    DateTime now = DateTimeUtils.Parse(data.ToStr(true));
                    Utility.SetLocalTime(now);
                    return true;
                }
            }
            catch (Exception)
            {
                return false;
            }
        }

        public static DateTime Parse(string datetime)
        {
            string[] dt = datetime.Split(' ');
            string[] date = dt[0].Split('/');
            string[] time = dt[1].Split(':');
            return new DateTime(date[2].ToInt(), date[0].ToInt(), date[1].ToInt(), time[0].ToInt(), time[1].ToInt(), time[2].ToInt());
        }

        public static string ToStr(this byte[] data, bool Encoded64 = false)
        {
            if (Encoded64)
            {
                string result = "";
                char[] s = Encoding.UTF8.GetChars(data, 0, data.Length);

                for (int i = 0; i < s.Length; i++)
                    result += s[i];
                return result;
                
            }
            else
                return Convert.ToBase64String(data);
        }

@ LouisCpro - maybe A and B input / output swapped at MAX3483

I’ve seen that in the MAX3483 datasheet, but however do not change anyhting.

What I’m looking at now is the USB/RS485 converter I bought to do the test, and which seems to have some lakes in conception : Prolific PL2303XA…(dixit forums).
I’m gonna search for real FTDI products and see…

new FTDI converter received : Now everything is OK at this part !

Just put the PROLIFIC converter into the nearest TRASH I found !

Magnifique :slight_smile: