Example #1
0
        // TODO: The order of data in the matrix is reverse of the channel index.
        // m[11] => channel 0, etc.
        protected override void Write(ONIContextTask ctx, Arr input)
        {
            var inputMatrix = input.GetMat();

            // Check dims
            var size = inputMatrix.Rows * inputMatrix.Cols;

            if (size % AnalogInputDataFrame.NumberOfChannels != 0)
            {
                throw new IndexOutOfRangeException("Source must contain a multiple of 12 elements.");
            }

            if (DataType == AnalogDataType.S16 && inputMatrix.Depth == Depth.S16)
            {
                var data = new Mat(inputMatrix.Size, Depth.U16, 1);
                CV.ConvertScale(inputMatrix, data, 1, 32768);
                ctx.Write((uint)DeviceAddress.Address, data.Data, 2 * size);
            }
            else if (DataType == AnalogDataType.Volts && (inputMatrix.Depth == Depth.F32 || inputMatrix.Depth == Depth.F64))
            {
                var data = new Mat(inputMatrix.Size, Depth.U16, 1);
                CV.ConvertScale(inputMatrix, data, 3276.75, 32768);
                ctx.Write((uint)DeviceAddress.Address, data.Data, 2 * size);
            }
            else
            {
                throw new Bonsai.WorkflowRuntimeException("Source element depth must Depth.S16 when " +
                                                          "DataType is S16 and either Depth.F32 or Depth.F64 when Datatype is Volts.");
            }
        }
Example #2
0
 protected override void Write(ONIContextTask ctx, ulong input)
 {
     writeArray[0] = (uint)(input & uint.MaxValue);
     writeArray[1] = (uint)(input >> 32);
     ctx.Write((uint)DeviceAddress.Address, writeArray);
 }
Example #3
0
 protected override void Write(ONIContextTask ctx, int input)
 {
     ctx.Write((uint)DeviceAddress.Address, (uint)input);
 }