예제 #1
0
        protected bool IsVoltageAdd(int seat, out bool enable, out string msg)
        {
            var status = new byte[0x100];

            enable = false;
            if (!IsSeatValid(seat, out msg))
            {
                return(false);
            }

            var chipAddr    = DriverAddr.GetChipAddr();
            var subChipAddr = DriverAddr.GetSubChipAddr(seat);
            var ctrlAddr    = DriverAddr.GetCtrlAddr(seat);
            var volAddr     = DriverAddr.GetAddVolAddr();
            var ctrlByte    = DriverAddr.GetCtrlByte(seat);

            //Select Chip
            if (1 != eDriver_IO.Cls_edriverdll.i2c_write(chipAddr, 0x01, 1, 0, new[] { subChipAddr }, status))
            {
                msg = Encoding.ASCII.GetString(status);
                return(false);
            }
            //Set Control Bit
            var data = new byte[1];

            if (1 == eDriver_IO.Cls_edriverdll.i2c_read(volAddr, ctrlAddr, 1, 0, data, status))
            {
                enable = (0 != (byte)((~data[0]) & ctrlByte));
                return(true);
            }
            msg = Encoding.ASCII.GetString(status);
            return(false);
        }
예제 #2
0
        public void TestGetCtrlByte()
        {
            Assert.AreEqual(_vbmsDriverAddr.GetCtrlByte(0), 0);
            for (var i = 1; i <= 8; i++)
            {
                var val = 0x01 << (i - 1);
                Assert.AreEqual(_vbmsDriverAddr.GetCtrlByte(i), val);
            }

            for (var i = 9; i <= 16; i++)
            {
                var val = 0x01 << (i - 9);
                Assert.AreEqual(_vbmsDriverAddr.GetCtrlByte(i), val);
            }

            for (var i = 17; i <= 24; i++)
            {
                var val = 0x01 << (i - 17);
                Assert.AreEqual(_vbmsDriverAddr.GetCtrlByte(i), val);
            }
        }