Skip to content

Commit

Permalink
fix(modbus): fix modbus after rebase
Browse files Browse the repository at this point in the history
  • Loading branch information
burgerni10 committed Jun 10, 2024
1 parent 06790b7 commit a2f96c6
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 5 deletions.
7 changes: 5 additions & 2 deletions backend/src/south/south-modbus/south-modbus.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,7 @@ class CustomStream extends Stream {
}

connect(_connectionObject: any, _callback: any) {}

end() {}
}

Expand Down Expand Up @@ -285,7 +286,7 @@ describe('SouthModbus', () => {

south.disconnect = jest.fn();
south.connect = jest.fn();
south.addValues = jest.fn();
south.addContent = jest.fn();
south.modbusFunction = jest
.fn()
.mockImplementationOnce(() => {
Expand All @@ -304,7 +305,7 @@ describe('SouthModbus', () => {
expect(south.modbusFunction).toHaveBeenCalledTimes(1);
expect(south.disconnect).not.toHaveBeenCalled();
expect(south.connect).not.toHaveBeenCalled();
expect(south.addValues).toHaveBeenCalledWith([]);
expect(south.addContent).toHaveBeenCalledWith({ type: 'time-values', content: [] });
});

it('should call read coil method', async () => {
Expand Down Expand Up @@ -432,8 +433,10 @@ describe('SouthModbus test connection', () => {
} as const;

type ErrorCodes = keyof typeof ERROR_CODES;

class ModbusError extends Error {
private code: ErrorCodes;

constructor(message: string, code: ErrorCodes) {
super();
this.name = 'ModbusError';
Expand Down
6 changes: 3 additions & 3 deletions backend/src/south/south-modbus/south-modbus.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import ModbusTCPClient from 'jsmodbus/dist/modbus-tcp-client';
import { QueriesLastPoint } from '../south-interface';
import { DateTime } from 'luxon';
import { SouthModbusItemSettings, SouthModbusSettings } from '../../../../shared/model/south-settings.model';
import { OIBusContent } from '../../../../shared/model/engine.model';
import { OIBusContent, OIBusTimeValue } from '../../../../shared/model/engine.model';

/**
* Class SouthModbus - Provides instruction for Modbus client connection
Expand All @@ -37,7 +37,7 @@ export default class SouthModbus extends SouthConnector<SouthModbusSettings, Sou
}

async lastPointQuery(items: Array<SouthConnectorItemDTO<SouthModbusItemSettings>>): Promise<void> {
const dataValues: Array<OIBusDataValue> = [];
const dataValues: Array<OIBusTimeValue> = [];
try {
const startRequest = DateTime.now().toMillis();
for (const item of items) {
Expand All @@ -63,7 +63,7 @@ export default class SouthModbus extends SouthConnector<SouthModbusSettings, Sou
/**
* Dynamically call the right function based on the given point settings
*/
async modbusFunction(item: SouthConnectorItemDTO<SouthModbusItemSettings>): Promise<Array<OIBusDataValue>> {
async modbusFunction(item: SouthConnectorItemDTO<SouthModbusItemSettings>): Promise<Array<OIBusTimeValue>> {
const offset = this.connector.settings.addressOffset === 'Modbus' ? 0 : -1;
const address =
(item.settings.address.match(/^0x[0-9a-f]+$/i) ? parseInt(item.settings.address, 16) : parseInt(item.settings.address, 10)) + offset;
Expand Down

0 comments on commit a2f96c6

Please sign in to comment.