Modelosensorvirtual: Difference between revisions
No edit summary Tag: Reverted |
No edit summary Tags: Reverted Visual edit: Switched |
||
| Line 16: | Line 16: | ||
==== Activação do sensor e da respectiva coluna no sistema ==== | ==== Activação do sensor e da respectiva coluna no sistema ==== | ||
< | <syntaxhighlight lang="csharp"> | ||
// VOLTAGEM 3 - DataValue3 | // VOLTAGEM 3 - DataValue3 | ||
bool enable3 = true; | bool enable3 = true; | ||
| Line 243: | Line 243: | ||
// OutputValue = OutputRecord.FMSFuelLevelPercentage; | // OutputValue = OutputRecord.FMSFuelLevelPercentage; | ||
} | } | ||
</ | </syntaxhighligh> | ||
{{QuatenusFooter}} | {{QuatenusFooter}} | ||
Revision as of 09:08, 2 April 2026
MODELO SENSORES VIRTUAIS EXEMPLO
Sensores Virtuais são uma forma de poder converter uma leitura analógica de uma sonda combustivel em que o valor é em Volts e é convertido em Litros e em percentagem de depósito.
Modelo de sensor virtual: SENSORESVIREXEMPLOS
Permite até de um a quatro sensores em simultâneo.
Exemplos
Sendo que é um GV300 com 2 sondas devem trabalhar sobre os DATAVALUE3 e DATAVALUE4.
Devem ajustar os valores nas seguintes variáveis.
Activação do sensor e da respectiva coluna no sistema
<syntaxhighlight lang="csharp"> // VOLTAGEM 3 - DataValue3 bool enable3 = true;
Se alterarem o true para false este sensor deixará de ser contabilizado para as contas dos litros.
E se estiver a false e for colocado true passa a ser contabilizado para as contas dos litros.
Variáveis a configurar
| Variável | Descrição |
|---|---|
outputMax3 |
Litros - Preencher com capacidade do tanque 1 |
outputMax4 |
Litros - Preencher com capacidade do tanque 2 |
inputMin3 |
Volts - Valor mínimo que a sonda irá enviar para o tanque 1 vazio |
inputMin4 |
Volts - Valor mínimo que a sonda irá enviar para o tanque 2 vazio |
inputMax3 |
Volts - Valor máximo em volts que a sonda irá enviar para o tanque 1 cheio |
inputMax4 |
Volts - Valor máximo em volts que a sonda irá enviar para o tanque 2 cheio |
Código
Exemplo de código em C# para ser copiado e colado, ou num novo sensor diretamente ou para usar num novo modelo de sensor virtual.
// VOLTAGEM 1 - DataValue1
bool enable1 = false;
decimal inputMin1 = 1m; //Volts - Valor mínimo que a sonda irá enviar
decimal inputMax1 = 100.0m; //Volts - Valor máximo em volts que a sonda irá enviar
decimal outputMin1 = 0.0m; //Litros - Nivel do tanque com voltagem no minimo
decimal outputMax1 = 100.0m; //Litros - Nivel do tanque com voltagem no máximo
// VOLTAGEM 2 - DataValue2
bool enable2 = false;
decimal inputMin2 = 1m; //Volts - Valor mínimo que a sonda irá enviar para o tanque vazio
decimal inputMax2 = 100.0m; //Volts - Valor máximo em volts que a sonda irá enviar para o tanque cheio
decimal outputMin2 = 0.0m; //Litros - Capacidade minima tanque
decimal outputMax2 = 100.0m; //Litros - Preencher com capacidade do tanque
// VOLTAGEM 3 - DataValue3
bool enable3 = true;
decimal inputMin3 = 1m; //Volts - Valor mínimo que a sonda irá enviar para o tanque vazio
decimal inputMax3 = 9.0m; //Volts - Valor máximo em volts que a sonda irá enviar para o tanque cheio
decimal outputMin3 = 0.0m; //Litros - Capacidade minima tanque
decimal outputMax3 = 505.0m; //Litros - Preencher com capacidade do tanque
// VOLTAGEM 4 - DataValue4
bool enable4 = true;
decimal inputMin4 = 1m; //Volts - Valor mínimo que a sonda irá enviar para o tanque vazio
decimal inputMax4 = 9.0m; //Volts - Valor máximo em volts que a sonda irá enviar para o tanque cheio
decimal outputMin4 = 0.0m; //Litros - Capacidade minima tanque
decimal outputMax4 = 350.0m; //Litros - Preencher com capacidade do tanque
//NÃO MEXER DAQUI PARA BAIXO
//NÃO MEXER DAQUI PARA BAIXO
//NÃO MEXER DAQUI PARA BAIXO
decimal? outputLevel = null;
decimal? maxOutputLevel = null;
if(enable1)
{
if(InputRecord.DataValue1 != null)
{
decimal tempOutputValue;
if(InputRecord.DataValue1 <= inputMin1)
{
tempOutputValue = outputMin1;
}
else if(InputRecord.DataValue1 >= inputMax1)
{
tempOutputValue = outputMax1;
}
else
{
tempOutputValue = outputMin1
+ (InputRecord.DataValue1.Value - inputMin1)
* (outputMax1 - outputMin1)
/ (inputMax1 - inputMin1);
tempOutputValue = System.Math.Abs(tempOutputValue);
}
if(outputLevel == null)
{
outputLevel = tempOutputValue;
}
else
{
outputLevel += tempOutputValue;
}
}
decimal max = System.Math.Max(outputMin1, outputMax1);
if(maxOutputLevel == null)
{
maxOutputLevel = max;
}
else
{
maxOutputLevel += max;
}
}
if(enable2)
{
if(InputRecord.DataValue2 != null)
{
decimal tempOutputValue;
if(InputRecord.DataValue2 <= inputMin2)
{
tempOutputValue = outputMin2;
}
else if(InputRecord.DataValue2 >= inputMax2)
{
tempOutputValue = outputMax2;
}
else
{
tempOutputValue = outputMin2
+ (InputRecord.DataValue2.Value - inputMin2)
* (outputMax2 - outputMin2)
/ (inputMax2 - inputMin2);
tempOutputValue = System.Math.Abs(tempOutputValue);
}
if(outputLevel == null)
{
outputLevel = tempOutputValue;
}
else
{
outputLevel += tempOutputValue;
}
}
decimal max = System.Math.Max(outputMin2, outputMax2);
if(maxOutputLevel == null)
{
maxOutputLevel = max;
}
else
{
maxOutputLevel += max;
}
}
if(enable3)
{
if(InputRecord.DataValue3 != null)
{
decimal tempOutputValue;
if(InputRecord.DataValue3 <= inputMin3)
{
tempOutputValue = outputMin3;
}
else if(InputRecord.DataValue3 >= inputMax3)
{
tempOutputValue = outputMax3;
}
else
{
tempOutputValue = outputMin3
+ (InputRecord.DataValue3.Value - inputMin3)
* (outputMax3 - outputMin3)
/ (inputMax3 - inputMin3);
tempOutputValue = System.Math.Abs(tempOutputValue);
}
if(outputLevel == null)
{
outputLevel = tempOutputValue;
}
else
{
outputLevel += tempOutputValue;
}
}
decimal max = System.Math.Max(outputMin3, outputMax3);
if(maxOutputLevel == null)
{
maxOutputLevel = max;
}
else
{
maxOutputLevel += max;
}
}
if(enable4)
{
if(InputRecord.DataValue4 != null)
{
decimal tempOutputValue;
if(InputRecord.DataValue4 <= inputMin4)
{
tempOutputValue = outputMin4;
}
else if(InputRecord.DataValue4 >= inputMax4)
{
tempOutputValue = outputMax4;
}
else
{
tempOutputValue = outputMin4
+ (InputRecord.DataValue4.Value - inputMin4)
* (outputMax4 - outputMin4)
/ (inputMax4 - inputMin4);
tempOutputValue = System.Math.Abs(tempOutputValue);
}
if(outputLevel == null)
{
outputLevel = tempOutputValue;
}
else
{
outputLevel += tempOutputValue;
}
}
decimal max = System.Math.Max(outputMin4, outputMax4);
if(maxOutputLevel == null)
{
maxOutputLevel = max;
}
else
{
maxOutputLevel += max;
}
}
if(outputLevel != null)
{
OutputRecord.FMSFuelLevel = outputLevel;
OutputRecord.FMSFuelLevelPercentage = (outputLevel / maxOutputLevel) * 100m;
OutputValue = OutputRecord.FMSFuelLevel;
// OutputValue = OutputRecord.FMSFuelLevelPercentage;
}
</syntaxhighligh>
