To read negative values of Modbus registers, one must subtract the number 65536 from the read value from the register.
Below is an example of how this can be done:
1. We create a user variable to which the result of the action in the script will be passed
![](https://knowledgebase.grenton.com/hubfs/Knowledge%20Base%20Import/s3.amazonaws.comcdn.freshdesk.comdatahelpdeskattachmentsproduction35149721997originalLP-qzQ0W3cD_qUJLwz1rhAbefrI1DNAojg-1.png)
2. Then we will prepare the script:
if(ModBus->Rejestr_odczytu->RegisterValue>=32768) then
ModBus->temp=(ModBus->Rejestr_odczytu->RegisterValue-65536)/10
else
ModBus->temp=ModBus->Rejestr_odczytu->RegisterValue/10
end
3. The script will be triggered by the OnChange event in the Modbus virtual object:
![](https://knowledgebase.grenton.com/hubfs/Knowledge%20Base%20Import/s3.amazonaws.comcdn.freshdesk.comdatahelpdeskattachmentsproduction35150621267originalVif34k2RL6g6W-RTOIF9BT_Dq9-DFG03WQ-1.png)
4. After sending the configuration, a negative value should be returned to the user property:
![](https://knowledgebase.grenton.com/hubfs/Knowledge%20Base%20Import/s3.amazonaws.comcdn.freshdesk.comdatahelpdeskattachmentsproduction35150621854originalJbUrEQLJecM-NctaFsUDTOOPpsL7Xm4fTg-1.png)
![](https://knowledgebase.grenton.com/hubfs/Knowledge%20Base%20Import/support.grenton.plensupportsolutionsarticles35000190973-negative-values-in-the-modbus-registershit-1.gif)