danikf / tik4net

Manage mikrotik routers with .NET C# code via ADO.NET like API or enjoy O/R mapper like highlevel api.
Apache License 2.0
178 stars 93 forks source link

Encoding Error #8

Closed se7en3 closed 8 years ago

se7en3 commented 8 years ago

when i want to add a ip pool, use Chinese word like name=“北京” ,but it's result is "??" on the mikrotik ROS var com = connection.CreateCommand("/ip/pool/add"); com.AddParameter("name", "北京"); com.AddParameter("ranges", "10.1.135.3");

se7en3 commented 8 years ago

on the ApiConnection.cs WriteCommand function,i have modified bytes Encoding,and it's resolved.

Original:byte[] bytes = Encoding.ASCII.GetBytes(row.ToCharArray()); modified :byte[] bytes = Encoding.GetEncoding("GB2312").GetBytes(row.ToCharArray());

danikf commented 8 years ago

Support for read/write encoding added. See ITikConenction.Encoding.

Deantwo commented 8 years ago

I guess I should have looked here sooner. But it is fixed now so whatever.

Just wondering why you are using ASCII by default, but since you were nice enough to make it a property like boen_robot suggested it doesn't matter.

See: http://forum.mikrotik.com/viewtopic.php?f=9&t=106053

danikf commented 8 years ago

ASCII is default for mikrotik console :-) I have added comment to forum to help other people to use thei custom encodings ...

D

se7en3 commented 8 years ago

on the ApiConnection.cs ReadWord function,i can't get chinese. and i fixed it use this byte[] byteArray=new byte[wordLength]; for (int i = 0; i < wordLength; i++) { byte readByte = (byte)_tcpConnectionStream.ReadByte(); byteArray[i] = readByte; } result = Encoding.GetString(byteArray);