/// <summary> /// Writes a user specified value to the specified register address. /// </summary> /// <param name="location"> /// The user specified RegisterAddress to which to save the value. /// </param> /// <param name="value"> /// The value to store in the specified RegisterAddress /// </param> public void StoreParameter(ServoDriveEnums.RegisterAddress location, int value) { try { lock (_objLock) { //Debug.WriteLine("Entering ServoDrive.StoreParameter() \n\t value: {0}\n\t RegisterLocation: {1}", new object[] { value, location.ToString() }); _server.Connect(IP_ADDRESS); // for clarity, defining parameters var byteValue = BitConverter.GetBytes(value); Array.Reverse(byteValue); ushort transId = 1; var startAddress = (ushort)location; var response = new byte[5]; // per Modbus standard, response is 5 bytes. _server.WriteMultipleRegister(transId, startAddress, byteValue, ref response); _server.Dispose(); } } catch (Exception ex) { Debug.WriteLine("EXCEPTION: \n\t{0}", new object[] { ex.Message }); } }
public int RetrieveParameter(ServoDriveEnums.RegisterAddress location) { if (location != ServoDriveEnums.RegisterAddress.DiffLimit) { return((int)GetType().GetProperty(_addressDictionary[location], BindingFlags.NonPublic | BindingFlags.Instance).GetValue(this)); } return((int)this.DiffLimit); }
public void StoreParameter(ServoDriveEnums.RegisterAddress location, float value) { PropertyInfo property = GetType().GetProperty(_addressDictionary[location], BindingFlags.NonPublic | BindingFlags.Instance); if (property.PropertyType == typeof(int)) { value = (int)value; } property.SetValue(this, value); }
private float RetrieveAngleLimits(ServoDriveEnums.RegisterAddress address) { float limit = 0f; lock (_objLock) { _server.Connect(IP_ADDRESS); ushort transId = 1; ushort startAddr = (ushort)address; ushort qtyRegisters = 4; // 64 bit value. var data = new byte[16]; _server.ReadHoldingRegister(transId, startAddr, qtyRegisters, ref data); if (data != null) { Array.Reverse(data); var value = BitConverter.ToInt64(data, 0); if (value == 0) { GearboxAngle = 0f; } else { // represents the PL.FB from the ADK drive. long count = 0; if (Math.Abs(value) < COUNTS_PER_REV) { count = value; } else { count = value % COUNTS_PER_REV; } limit = count * (360f / COUNTS_PER_REV); } } _server.Dispose(); } return(limit); }
/// <summary> /// Gets a value from a specific register address. /// </summary> /// <param name="location"> /// The user specified RegisterAddress /// </param> /// <returns> /// A 32 bit signed integer representing the value in the /// holding register on the servo drive. /// </returns> public int RetrieveParameter(ServoDriveEnums.RegisterAddress location) { try { // in case the value is not retrieved, I will know with this insane number. var value = -5000; lock (_objLock) { _server.Connect(IP_ADDRESS); // for clarity, defining parameters ushort transId = 1; var startAddress = (ushort)location; ushort qtyRegisters = 2; var response = new byte[8]; // per Modbus standard, response is 8 bytes. _server.ReadHoldingRegister(transId, startAddress, qtyRegisters, ref response); // response null means the connection was temporarily lost if (response != null) { Array.Reverse(response); value = BitConverter.ToInt32(response, 0); } _server.Dispose(); } return(value); } catch (Exception ex) { Debug.WriteLine("EXCEPTION: \n\t{0}", new object[] { ex.Message }); return(22); // memorable value, at least today it is... } }
/// <summary> /// Stores a test parameter for a bench component. The bench component will behave /// in a certain way, based off the value of that parameter. /// </summary> /// <param name="location"></param> /// <param name="value"></param> internal void LoadTestParameter(ServoDriveEnums.RegisterAddress location, float value) { _acDrive.StoreParameter(location, value); }
public void StoreParameter(ServoDriveEnums.RegisterAddress location, int value) { GetType().GetProperty(_addressDictionary[location], BindingFlags.NonPublic | BindingFlags.Instance).SetValue(this, value); }