コード例 #1
0
        public void Action_Multi_Jog(byte unit_id, ushort[] pos, ushort[] vel) //一次下7軸
        {
            ushort address = Convert.ToUInt16(REG_HOLDING_START + eMbData.DEF_INX_TARPOS1);

            mm.WriteMultipleRegisters(unit_id, address, pos);
            Thread.Sleep(10);

            address = Convert.ToUInt16(REG_HOLDING_START + eMbData.DEF_INX_TARVEL1);
            mm.WriteMultipleRegisters(unit_id, address, vel);
            Thread.Sleep(10);

            address = Convert.ToUInt16(REG_HOLDING_START + eMbData.DEF_INX_OPMODE);
            mm.WriteSingleRegister(unit_id, address, Convert.ToUInt16(eOPMode.JOG));
        }
コード例 #2
0
ファイル: FormModbus.cs プロジェクト: adamj537/ModbusGUI
        /// <summary>
        /// Write Holding Registers.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void ButtonHoldingRegisterWrite_Click(object sender, EventArgs e)
        {
            try
            {
                // Get the selected device address.
                byte slaveAddr = GetDeviceAddress();

                // If the register address text box is empty...
                if (string.IsNullOrWhiteSpace(textBoxHoldingRegisterAddressDecimal.Text))
                {
                    // Convert from hex.
                    TextBoxHoldingRegisterAddressHex_Leave(null, null);
                }

                // Get the selected register address.
                ushort regAddr = GetRegisterAddress(textBoxHoldingRegisterAddressDecimal.Text);

                // Get the selected data format.
                DataType dataType = GetDataFormat(comboBoxHoldingRegisterFormat);

                // Calculate the number of registers to write.
                ushort numRegs = 2;
                if (dataType == DataType.String)
                {
                    numRegs = GetNumRegisters(textBoxHoldingRegisterStringLength.Text);
                }

                // Convert the desired data into an array of register values.
                ushort[] regs = StringToRegisters(textBoxHoldingRegisterData.Text, dataType, numRegs);
                if (regs == null)
                {
                    throw new ArgumentException("Data to write does not match selected format");
                }

                // Write the register values to the device.
                _mbMaster.WriteMultipleRegisters(slaveAddr, regAddr, regs);

                // Update the status.
                toolStripStatusLabel1.Text = "Holding Register Written Successfully";
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, ex.GetType().Name.ToString());
            }
        }