コード例 #1
0
        /// <summary>
        /// ポートの入出力方向を設定する(全ピン出力に固定)
        /// </summary>
        /// <param name="directionCollection"></param>
        public void WriteDirection(Dictionary<PortType, List<bool>> directionCollection)
        {
            // Wire.beginTransmission(0x20);	                // アドレスを7バイト
            //this.write(new byte[] { 0x00, 0x06, 0x06, 0x01, 0x00, this.deviceAddress, 0xAA, 0xAA });
            Query_x06 query = new Query_x06()
            {
                DeviceAddress = 0x00,
                FunctionCode = 0x06,
                RegisterAddress = ModbusData.bytes2int(0x06, 0x01),
                PresetData = ModbusData.bytes2int(0x00, this.deviceAddress),
            };
            this.Write(query);

            // Wire.write(0x06);				// I/O direction(ic0)
            //this.write(new byte[] { 0x00, 0x06, 0x06, 0x02, 0x00, 0x06, 0xAA, 0xAA });
            query = new Query_x06()
            {
                DeviceAddress = 0x00,
                FunctionCode = 0x06,
                RegisterAddress = ModbusData.bytes2int(0x06, 0x02),
                PresetData = ModbusData.bytes2int(0x00, 0x06),
            };
            this.Write(query);

            // Wire.write(0x00);				// ic0 directon
            //this.write(new byte[] { 0x00, 0x06, 0x06, 0x02, 0x00, 0x00, 0xAA, 0xAA });
            query = new Query_x06()
            {
                DeviceAddress = 0x00,
                FunctionCode = 0x06,
                RegisterAddress = ModbusData.bytes2int(0x06, 0x02),
                PresetData = ModbusData.bytes2int(0x00, 0x00),
            };
            this.Write(query);

            // Wire.write(0x00);				// ic1 directionを続けて送信しても可
            //this.write(new byte[] { 0x00, 0x06, 0x06, 0x02, 0x00, 0x00, 0xAA, 0xAA });
            query = new Query_x06()
            {
                DeviceAddress = 0x00,
                FunctionCode = 0x06,
                RegisterAddress = ModbusData.bytes2int(0x06, 0x02),
                PresetData = ModbusData.bytes2int(0x00, 0x00),
            };
            this.Write(query);

            // Wire.endTransmission();		// 送信
            //this.write(new byte[] { 0x00, 0x06, 0x06, 0x03, 0x00, 0x00, 0xAA, 0xAA });
            query = new Query_x06()
            {
                DeviceAddress = 0x00,
                FunctionCode = 0x06,
                RegisterAddress = ModbusData.bytes2int(0x06, 0x03),
                PresetData = ModbusData.bytes2int(0x00, 0x00),
            };
            this.Write(query);
        }
コード例 #2
0
 public void Init()
 {
     // Wire.begin(); // I2Cバスに接続
     //this.write(new byte[] { 0x00, 0x06, 0x06, 0x00, 0x00, 0x00, 0xAA, 0xAA });
     Query_x06 query = new Query_x06()
     {
         DeviceAddress = 0x00,
         FunctionCode = 0x06,
         RegisterAddress = ModbusData.bytes2int(0x06, 0x00),
         PresetData = ModbusData.bytes2int(0x00, 0x00),
     };
     this.Write(query);
 }
コード例 #3
0
        public void Init()
        {
            //pinMode(slaveSelectPin, OUTPUT);
            //this.write(new byte[] { 0x00, 0x06, 0x00, (byte)this.latchPin, 0x01, 0x00, 0xAA, 0xAA});
            Query_x06 query = new Query_x06()
            {
                DeviceAddress = 0x00,
                FunctionCode = 0x06,
                RegisterAddress = ModbusData.bytes2int(0x00, (byte)this.latchPin),
                PresetData = ModbusData.bytes2int(0x01, 0x00),
            };
            this.Write(query);

            //// initialize SPI:
            //SPI.begin();
            //this.write(new byte[] { 0x00, 0x06, 0x05, 0x00, 0x00, 0x00, 0xAA, 0xAA });
            query = new Query_x06()
            {
                DeviceAddress = 0x00,
                FunctionCode = 0x06,
                RegisterAddress = ModbusData.bytes2int(0x05, 0x00),
                PresetData = ModbusData.bytes2int(0x00, 0x00),
            };
            this.Write(query);

            //SPI.setDataMode(SPI_MODE0);
            //SPI.setClockDivider(SPI_CLOCK_DIV32);
            //this.write(new byte[] { 0x00, 0x06, 0x05, 0x01, 0x00, 0x06, 0xAA, 0xAA });
            query = new Query_x06()
            {
                DeviceAddress = 0x00,
                FunctionCode = 0x06,
                RegisterAddress = ModbusData.bytes2int(0x05, 0x01),
                PresetData = ModbusData.bytes2int(0x00, 0x06),
            };
            this.Write(query);
        }
コード例 #4
0
        /// <summary>
        /// 抵抗値をセットする
        /// </summary>
        /// <param name="pinType">ピン</param>
        /// <param name="outputValue">出力値(0~255)</param>
        public void SetResistor(PinType pinType, byte outputValue)
        {
            //digitalWrite(slaveSelectPin, LOW);
            //this.write(new byte[] { 0x00, 0x06, 0x01, (byte)this.latchPin, 0x00, 0x00, 0xAA, 0xAA });
            Query_x06 query = new Query_x06()
            {
                DeviceAddress = 0x00,
                FunctionCode = 0x06,
                RegisterAddress = ModbusData.bytes2int(0x01, (byte)this.latchPin),
                PresetData = ModbusData.bytes2int(0x00, 0x00),
            };
            this.Write(query);

            ////  send in the address and value via SPI:
            //SPI.transfer(address);
            //this.write(new byte[] { 0x00, 0x06, 0x05, 0x02, 0x00, (byte)pinType, 0xAA, 0xAA });
            query = new Query_x06()
            {
                DeviceAddress = 0x00,
                FunctionCode = 0x06,
                RegisterAddress = ModbusData.bytes2int(0x05, 0x02),
                PresetData = ModbusData.bytes2int(0x00, (byte)pinType),
            };
            this.Write(query);

            //SPI.transfer(value);
            //this.write(new byte[] { 0x00, 0x06, 0x05, 0x02, 0x00, outputValue, 0xAA, 0xAA });
            query = new Query_x06()
            {
                DeviceAddress = 0x00,
                FunctionCode = 0x06,
                RegisterAddress = ModbusData.bytes2int(0x05, 0x02),
                PresetData = ModbusData.bytes2int(0x00, outputValue),
            };
            this.Write(query);

            //// take the SS pin high to de-select the chip:
            //digitalWrite(slaveSelectPin, HIGH);
            //this.write(new byte[] { 0x00, 0x06, 0x01, (byte)this.latchPin, 0x00, 0x01, 0xAA, 0xAA });
            query = new Query_x06()
            {
                DeviceAddress = 0x00,
                FunctionCode = 0x06,
                RegisterAddress = ModbusData.bytes2int(0x01, (byte)this.latchPin),
                PresetData = ModbusData.bytes2int(0x00, 0x01),
            };
            this.Write(query);
        }
コード例 #5
0
 private void Write(Query_x06 query)
 {
     byte[] buffer = query.GetBytes();
     Console.Write("送信:");
     for (int i = 0; i < buffer.Length; i++)
     {
         Console.Write(buffer[i] + ",");
     }
     Console.WriteLine();
     Arduino.ModbusSerial.Write(query);
 }
コード例 #6
0
        /// <summary>
        /// ポートの出力値を設定する
        /// </summary>
        /// <param name="levelCollection"></param>
        public void WriteLevel(Dictionary<PortType, List<bool>> levelCollection)
        {
            // Wire.beginTransmission(0x20);	                // アドレスを7バイト
            //this.write(new byte[] { 0x00, 0x06, 0x06, 0x01, 0x00, this.deviceAddress, 0xAA, 0xAA });
            Query_x06 query = new Query_x06()
            {
                DeviceAddress = 0x00,
                FunctionCode = 0x06,
                RegisterAddress = ModbusData.bytes2int(0x06, 0x01),
                PresetData = ModbusData.bytes2int(0x00, this.deviceAddress),
            };
            this.Write(query);

            // Wire.write(0x02);				// コマンド
            //this.write(new byte[] { 0x00, 0x06, 0x06, 0x02, 0x00, 0x02, 0xAA, 0xAA });
            query = new Query_x06()
            {
                DeviceAddress = 0x00,
                FunctionCode = 0x06,
                RegisterAddress = ModbusData.bytes2int(0x06, 0x02),
                PresetData = ModbusData.bytes2int(0x00, 0x02),
            };
            this.Write(query);

            // Wire.write(0x**);				// ic0 data
            //this.write(new byte[] { 0x00, 0x06, 0x06, 0x02, 0x00, this.Bool2Byte(levelCollection[PortType.port0]), 0xAA, 0xAA });
            query = new Query_x06()
            {
                DeviceAddress = 0x00,
                FunctionCode = 0x06,
                RegisterAddress = ModbusData.bytes2int(0x06, 0x02),
                PresetData = ModbusData.bytes2int(0x00, this.Bool2Byte(levelCollection[PortType.port0])),
            };
            this.Write(query);

            // Wire.write(0x**);				// ic1 data
            //this.write(new byte[] { 0x00, 0x06, 0x06, 0x02, 0x00, this.Bool2Byte(levelCollection[PortType.port1]), 0xAA, 0xAA });
            query = new Query_x06()
            {
                DeviceAddress = 0x00,
                FunctionCode = 0x06,
                RegisterAddress = ModbusData.bytes2int(0x06, 0x02),
                PresetData = ModbusData.bytes2int(0x00, this.Bool2Byte(levelCollection[PortType.port1])),
            };
            this.Write(query);

            // Wire.endTransmission();		// 送信
            //this.write(new byte[] { 0x00, 0x06, 0x06, 0x03, 0x00, 0x00, 0xAA, 0xAA });
            query = new Query_x06()
            {
                DeviceAddress = 0x00,
                FunctionCode = 0x06,
                RegisterAddress = ModbusData.bytes2int(0x06, 0x03),
                PresetData = ModbusData.bytes2int(0x00, 0x00),
            };
            this.Write(query);
        }