Exemple #1
0
 public BitStatus()
 {
     InitializeComponent();
     this.BorderStyle              = BorderStyle.FixedSingle;
     PeriodicRefreshTimer.Elapsed += PeriodicRefreshTimer_Elapsed;
     ModbusRTU.VoteToConfirmTransmitRegs('+', (byte)_ReadFunctionCode, _ReadAddress, _ReadDataLengthInBit);//控件初始化时,票决器根据地址值自动加1,并判断票选结果
 }
Exemple #2
0
        private void Button1_MouseClick(object sender, MouseEventArgs e)
        {
            this.PeriodicRefreshTimer.Enabled = false;
            ModbusRTU.SuspendRead((byte)_ReadFunctionCode, _ReadAddress, _ReadDataLengthInBit);//鼠标单击本控件后,进入写寄存器状态,暂停寄存器的读操作

            switch (_ButtonClickAction)
            {
            case ModbusButtonClickActionEnum.Set:
                ModbusRTU.MasterDataRepos.Coils[_WriteAddress] = true;
                break;

            case ModbusButtonClickActionEnum.Reset:
                ModbusRTU.MasterDataRepos.Coils[_WriteAddress] = false;
                break;

            case ModbusButtonClickActionEnum.Toggle:
                ModbusRTU.MasterDataRepos.Coils[_WriteAddress] = !ModbusRTU.MasterDataRepos.Coils[_WriteAddress];
                break;

            default:
                break;
            }
            ModbusRTU.VoteToConfirmTransmitRegs('+', (byte)_WriteFunctionCode, _WriteAddress, _WriteDataLengthInBit);
            ModbusRTU.AssembleRequestADU(1, ModbusRTU.LoadUnmannedBuses((byte)_WriteFunctionCode, 0));
            ModbusRTU.ResumeRead((byte)_ReadFunctionCode, _ReadAddress, _ReadDataLengthInBit);//鼠标单击本控件后,进入写寄存器状态,暂停寄存器的读操作
            PeriodicRefreshTimer.Enabled = true;
        }
Exemple #3
0
        public TextBoxModbus()
        {
            PeriodicRefreshTimer.Elapsed += PeriodicRefreshTimer_Elapsed;
            this.MouseClick += ModbusView_MouseClick1;
            this.KeyPress   += ModbusView_KeyPress;

            ModbusRTU.VoteToConfirmTransmitRegs('+', (byte)_ReadFunctionCode, _ReadAddress, _ReadDataLengthInWord);//控件初始化时,票决器根据地址值自动加1,并判断票选结果
        }
Exemple #4
0
 public ButtonModbus()
 {
     InitializeComponent();
     PeriodicRefreshTimer.Elapsed += PeriodicRefreshTimer_Elapsed;
     PeriodicRefreshTimer.Enabled  = true;
     this.button1.MouseClick      += Button1_MouseClick;
     ModbusRTU.VoteToConfirmTransmitRegs('+', (byte)_ReadFunctionCode, _ReadAddress, _ReadDataLengthInBit);//控件初始化时,票决器根据地址值自动加1,并判断票选结果
 }
Exemple #5
0
 private void PeriodicRequestTimer_Elapsed(object sender, System.Timers.ElapsedEventArgs e)
 {
     ModbusRTU.AssembleRequestADU(_MyModbusIndex, false, _StationID, (byte)ReadFuncCode, ReadAddress, 1, null);
     if (ModbusRTU.GetDataStorageFlag(_MyModbusIndex) == false)
     {
         this.Invoke(new EventHandler(delegate
         {
             this.Text = _CommDataType.ToString();
         }));
     }
 }
        public MainForm()
        {
            InitializeComponent();
            WorkSpcaeSystemInfoForm.MdiParent = this;
            WorkSpcaeFaultInfoForm.MdiParent  = this;
            WorkSpcaeWaveformForm.MdiParent   = this;
            WorkSpaceWorkModeForm.MdiParent   = this;

            treeView1.ExpandAll();

            ModbusRTU.IsMaster = true;
            ModbusRTU.AssembleRequestADU(1, ModbusRTU.LoadUnmannedBuses((byte)ModbusRTU.ModbusFuncCode.ReadStorageRegs, 8));
            ModbusRTU.AssembleRequestADU(1, ModbusRTU.LoadUnmannedBuses((byte)ModbusRTU.ModbusFuncCode.ReadInputRegs, 8));
            ModbusRTU.AssembleRequestADU(1, ModbusRTU.LoadUnmannedBuses((byte)ModbusRTU.ModbusFuncCode.ReadCoils, 8));
        }
Exemple #7
0
        private void ModbusView_KeyPress(object sender, KeyPressEventArgs e)
        {
            if (e.KeyChar == (char)Keys.Enter)                                                                     //如果按下了Enter键,则进入发数据状态
            {
                if (UInt16.TryParse(this.Text, out ModbusRTU.MasterDataRepos.StorageRegs[_WriteAddress]) == false) //TryParse 函数如果判断出所转换的字符串与所对应的数据格式不对应,会以0值out出来
                {
                    this.Text = "Wrong Input";
                    return;
                }
                ; // 需要改进,增加容错能力  考虑使用uint16.tryparse()

                ModbusRTU.VoteToConfirmTransmitRegs('+', (byte)_WriteFunctionCode, _WriteAddress, _WriteDataLengthInWord);
                ModbusRTU.AssembleRequestADU(1, ModbusRTU.LoadUnmannedBuses((byte)_WriteFunctionCode, 0));
                HideCaret(this.Handle);
                PeriodicRefreshTimer.Enabled = true;
            }

            if (e.KeyChar == (char)Keys.Escape)//通过Esc键取消写操作,恢复周期性读数据状态
            {
                ModbusRTU.ResumeRead((byte)_ReadFunctionCode, _ReadAddress, _ReadDataLengthInWord);
                HideCaret(this.Handle);
                PeriodicRefreshTimer.Enabled = true;
            }
        }
Exemple #8
0
 private void ModbusView_MouseClick1(object sender, MouseEventArgs e)
 {
     this.PeriodicRefreshTimer.Enabled = false;
     ShowCaret(this.Handle);
     ModbusRTU.SuspendRead((byte)_ReadFunctionCode, _ReadAddress, _ReadDataLengthInWord);//鼠标单击本控件后,进入写寄存器状态,暂停寄存器的读操作
 }
Exemple #9
0
 public ModbusView()
 {
     PeriodicRequestTimer.Elapsed += PeriodicRequestTimer_Elapsed;
     _MyModbusIndex = ModbusRTU.GetMyModbusIndex(); //初始化控件时获得自己的Modbus索引值  重中之重
     ModbusRTU.SetDataStorage();                    //每次新增一个使用Modbus功能的控件,就必须让控件自己调用ModbusRTU的这个方法以建立属于控件自己的数据和flag存储单元
 }
 public LabelModbus()
 {
     InitializeComponent();
     PeriodicRefreshTimer.Elapsed += PeriodicRefreshTimer_Elapsed;
     ModbusRTU.VoteToConfirmTransmitRegs('+', (byte)_ReadFunctionCode, _ReadAddress, _ReadDataLengthInWord);//控件初始化时,票决器根据地址值自动加1,并判断票选结果
 }