Exemplo n.º 1
0
        public void TestUSInt()
        {
            byte value = 44;

            var type    = new PlcUSInt("TEST");
            var data    = new byte[type.Size.Bytes];
            var binding = new PlcObjectBinding(new PlcRawData(512), type, 0, 0);

            type.ConvertToRaw(value, binding, data);
            var result1 = (byte)type.ConvertFromRaw(binding, data);

            Assert.Equal(value, result1);
        }
Exemplo n.º 2
0
        private static PlcObject DataTypeToPlcObject(string value, StringBuilder dataType)
        {
            PlcObject plcObject = null;

            switch (dataType.ToString())
            {
            case "X":
            case "BIT":
                plcObject = new PlcBool(value);
                break;

            case "B":
            case "BYTE":
                plcObject = new PlcByte(value);
                break;

            case "C":
            case "CHAR":
                plcObject = new PlcChar(value);
                break;

            case "DATE":
                plcObject = new PlcDate(value);
                break;

            case "DT":
            case "DATETIME":
                plcObject = new PlcDateTime(value);
                break;

            case "DI":
            case "DINT":
                plcObject = new PlcDInt(value);
                break;

            case "DW":
            case "DWORD":
                plcObject = new PlcDWord(value);
                break;

            case "I":
            case "INT":
                plcObject = new PlcInt(value);
                break;

            case "LDT":
            case "LDATETIME":
                plcObject = new PlcLDateTime(value);
                break;

            case "LI":
            case "LINT":
                plcObject = new PlcLInt(value);
                break;

            case "LT":
            case "LTIME":
                plcObject = new PlcTime(value);
                break;

            case "LW":
            case "LWORD":
                plcObject = new PlcWord(value);
                break;

            case "R":
            case "REAL":
                plcObject = new PlcReal(value);
                break;

            case "TIMEBCD":
                plcObject = new PlcS5Time(value);
                break;

            case "CT":
            case "COUNT":
                plcObject = new PlcS7Counter(value);
                break;

            case "SI":
            case "SINT":
                plcObject = new PlcSInt(value);
                break;

            case "S":
            case "STRING":
                plcObject = new PlcString(value);
                break;

            case "T":
            case "TIME":
                plcObject = new PlcTime(value);
                break;

            case "TOD":
                plcObject = new PlcTimeOfDay(value);
                break;

            case "UDI":
            case "UDINT":
                plcObject = new PlcUDInt(value);
                break;

            case "UI":
            case "UINT":
                plcObject = new PlcUInt(value);
                break;

            case "ULI":
            case "ULINT":
                plcObject = new PlcULInt(value);
                break;

            case "USI":
            case "USINT":
                plcObject = new PlcUSInt(value);
                break;

            case "WC":
            case "WCHAR":
                plcObject = new PlcWChar(value);
                break;

            case "W":
            case "WORD":
                plcObject = new PlcWord(value);
                break;

            case "WS":
            case "WSTRING":
                plcObject = new PlcWString(value);
                break;
            }

            return(plcObject);
        }