public FBoxMachine(FBoxType fBoxType, string connectionString, SignalRSigninMsg msg, IEnumerable<AddressUnit> getAddresses, bool keepConnect) : base(getAddresses, keepConnect) { AddressFormater = new AddressFormaterFBox(); AddressCombiner = new AddressCombinerFBox(); BaseUtility = new FBoxUtility(fBoxType, connectionString, CommunicateAddresses, msg); }
public override byte[] SendMsg(byte[] message) { var formater = new AddressFormaterFBox(); var translator = new AddressTranslatorFBox(); byte[] ans; lock (_connectionTokenState) { if (_connectionTokenState.ContainsKey(ConnectionToken) && _connectionTokenState[ConnectionToken] != 1) { Console.WriteLine($"Return Value Rejected with connectionToken {ConnectionToken}"); return null; } } lock (_machineData) { if (!_machineData.ContainsKey(ConnectionToken) || !_machineDataType.ContainsKey(ConnectionToken)) { Console.WriteLine($"Return Value Rejected with connectionToken {ConnectionToken}"); return null; } var machineDataValue = _machineData[ConnectionToken]; var machineDataType = _machineDataType[ConnectionToken]; int pos = 0; int area = ValueHelper.Instance.GetInt(message, ref pos); int address = ValueHelper.Instance.GetInt(message, ref pos); //short count = ValueHelper.Instance.GetShort(message, ref pos); object[] dataAns = new object[1]; try { dataAns[0] = Convert.ChangeType( machineDataValue[formater.FormatAddress(translator.GetAreaName(area), address)], machineDataType[formater.FormatAddress(translator.GetAreaName(area), address)]); } catch (Exception) { dataAns[0] = Convert.ChangeType( 0, machineDataType[formater.FormatAddress(translator.GetAreaName(area), address)]); } finally { ans = ValueHelper.Instance.ObjectArrayToByteArray(dataAns); } } return ans; }