Export to DB – String variables

Forum Home Forums Uncategorized Issues Export to DB – String variables

Tagged: 

This topic contains 1 reply, has 2 voices, and was last updated by Mikhail Mikhail 2 months, 2 weeks ago.

Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • #5514
    Avatar
    JD
    Participant

    I am using the Export to DB module, attached to a MySQL database.
    I have a tag which is a string (ASCII Text on SCADA-Administrator) that is displayed correctly on the web station.

    On the MySQL database it is shown as float and thus has no sense. How can I log it to string type or at least how can I decode the stored float value to the expected string? CONVERT and CAST functions of MySQL do not work.

    #5519
    Mikhail
    Mikhail
    Moderator

    The idea of conversion:
    Convert the value of double type to 8 bytes. Each byte is a character.

    public static string DecodeAscii(double val)
    {
        byte[] buf = BitConverter.GetBytes(val);
        return Encoding.ASCII.GetString(buf).TrimEnd((char)0);
    }

    You should create a function in your database that performs this conversion.

Viewing 2 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic.