@@ -37,7 +37,7 @@ public class BreakoutAnalogOutput : Sink<Mat>
3737 /// </summary>
3838 /// <param name="source"> A sequence of 12xN sample matrices containing the analog data to write to channels 0 to 11.</param>
3939 /// <returns> A sequence of 12xN sample matrices containing the analog data that were written to channels 0 to 11.</returns>
40- public override IObservable < Mat > Process ( IObservable < Mat > source )
40+ public override unsafe IObservable < Mat > Process ( IObservable < Mat > source )
4141 {
4242 var dataType = DataType ;
4343 return DeviceManager . GetDevice ( DeviceName ) . SelectMany ( deviceInfo =>
@@ -87,6 +87,10 @@ public override IObservable<Mat> Process(IObservable<Mat> source)
8787 }
8888
8989 var dataSize = outputBuffer . Step * outputBuffer . Rows ;
90+
91+ // twos-complement to offset binary
92+ const short Mask = - 32768 ;
93+ CV . XorS ( outputBuffer , new Scalar ( Mask , 0 , 0 ) , outputBuffer ) ;
9094 device . Write ( outputBuffer . Data , dataSize ) ;
9195 } ) ;
9296 } ) ;
@@ -108,6 +112,12 @@ public IObservable<short[]> Process(IObservable<short[]> source)
108112 return source . Do ( data =>
109113 {
110114 AssertChannelCount ( data . Length ) ;
115+ var samples = new ushort [ data . Length ] ;
116+ for ( int i = 0 ; i < samples . Length ; i ++ )
117+ {
118+ const short Mask = - 32768 ;
119+ data [ i ] ^= Mask ; // twos-complement to offset binary
120+ }
111121 device . Write ( data ) ;
112122 } ) ;
113123 } ) ;
@@ -130,10 +140,10 @@ public IObservable<float[]> Process(IObservable<float[]> source)
130140 return source . Do ( data =>
131141 {
132142 AssertChannelCount ( data . Length ) ;
133- var samples = new short [ data . Length ] ;
143+ var samples = new ushort [ data . Length ] ;
134144 for ( int i = 0 ; i < samples . Length ; i ++ )
135145 {
136- samples [ i ] = ( short ) ( data [ i ] * divisionsPerVolt ) ;
146+ samples [ i ] = ( ushort ) ( data [ i ] * divisionsPerVolt + BreakoutAnalogIO . DacMidScale ) ;
137147 }
138148
139149 device . Write ( samples ) ;
0 commit comments