private void SystemForm_Load(object sender, EventArgs e) { myFunction myfunction = new myFunction(); string ver = "当前版本:" + myfunction.GetVersion(); if (GlobalVar.PCSoftware != null && GlobalVar.PCSoftware.NeedUpdate) { ver += "\r\n升级版本:" + GlobalVar.PCSoftware.Download_Ver; } this.label_Ver.Text = ver; byte[] plcver = GlobalVar.c_Modbus.HoldingRegisters.PLCVer.GetByte(); this.label_PLCVer.Text = "PLC版本:" + Encoding.Default.GetString(ModbusTool.WordTwo(plcver, 0, plcver.Length)).Trim('\0'); }
/// <summary> /// 修改单个保持寄存器的值 /// </summary> /// <param name="register">保持寄存器</param> /// <param name="Value">修改的值(包含小数的值,将数值*100后写入)</param> internal void AddMsgList(HoldingRegister register, int Value) { InputModule input = new InputModule(); input.nStartAddr = register.Addr; input.nDataLength = register.Size; if (register.Size > 1) { input.byFunction = Modbus.byWRITE_MULTI_HOLDING_REG; input.byWriteData = ModbusTool.HostToNetOrder32(Value); } else { input.byFunction = Modbus.byWRITE_SINGLE_HOLDING_REG; input.byWriteData = ModbusTool.HostToNetOrder16((short)Value); } AddMsgList(input); }