bitm0de / XSigUtilityLibrary

Intersystem Communications (ISC) library for SIMPL#.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

XSigUtilityLibrary

Intersystem Communications (ISC) library for SIMPL#.

modules issues license

Example 1: Reading tokens from a byte array

var buffer = new byte[] {
    0x80, 0x0A,                                                  // \x80\x0A (Digital = 1, Index = 11)
    0xC0, 0x00, 0x09, 0x52,                                      // \xC0\x00\x09R (Analog = 1234, Index = 1)
    0xC8, 0x05, (byte)'1', (byte)'2', (byte)'3', (byte)'4', 0xFF // \xC8\x051234\xFF (Serial = "1234", Index = 6)
};
using (var tokenReader = new XSigTokenStreamReader(new MemoryStream(buffer))) {
    XSigToken token;
    while ((token = tokenReader.ReadXSigToken()) != null)
        CrestronConsole.PrintLine(token.GetType().Name + ": " + token.Index + " = " + token);
}

CrestronConsole.PrintLine(string.Concat(XSigHelpers.GetBytes(15, true).Select(b => "\\x" + b.ToString("X2")).ToArray()));

Example 2: Writing tokens to a byte array (and string)

using (var memoryStream = new MemoryStream())
{
    using (var tokenWriter = new XSigTokenStreamWriter(memoryStream, true))
        tokenWriter.WriteXSigData(new XSigToken[] {
        new XSigAnalogToken(1, 0x1234),         // aout1
        new XSigSerialToken(2, "Hello world!"), // aout2
        new XSigDigitalToken(3, true),          // dig_out1
    });
    byte[] bytes = memoryStream.ToArray();
    CrestronConsole.PrintLine(string.Concat(bytes.Select(b => "\\x" + b.ToString("X2")).ToArray());
}

Note: The indexes are 1-based, and are set based on the output signal index. For instance, if nothing has been expanded on an XSIG symbol in SIMPL Windows where you have aout1 and dig_out1, aout1 is index 1 and dig_out1 is index 2. If there are no signals defined in the aout## spots, then dig_out1 seems to take index 1.

Important: Always ensure that your signal alignment matches your code to mitigate error log spam. If your datatypes and data don't match the symbol defined in your SIMPL Windows program, your logfile will be full of "Signal Mismatch in receive of Intersystem Communications" messages.

About

Intersystem Communications (ISC) library for SIMPL#.

License:MIT License


Languages

Language:C# 100.0%