Skip to content

Commit

Permalink
Merge branch 'main' into dependabot/github_actions/toitlang/pkg-publi…
Browse files Browse the repository at this point in the history
…sh-1.5.0
  • Loading branch information
floitsch authored Sep 4, 2024
2 parents d29c589 + a842e4f commit cf04410
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 4 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@ jobs:
os: [ ubuntu-latest, macos-latest ]
# The versions should contain (at least) the lowest requirement
# and a version that is more up to date.
toit-version: [ v2.0.0-alpha.118, latest ]
toit-version: [ v2.0.0-alpha.144, latest ]
include:
- toit-version: v2.0.0-alpha.118
- toit-version: v2.0.0-alpha.144
version-name: old
- toit-version: latest
version-name: new
Expand Down
13 changes: 13 additions & 0 deletions src/protocol.toit
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,19 @@ class Response:
--frame=frame
throw exception

class RawRequest extends Request:
payload/ByteArray
constructor function-code/int .payload:
super function-code
to-byte-array -> ByteArray:
return payload

class RawResponse extends Response:
bits/ByteArray
constructor.deserialize frame/Frame function-code/int:
Response.check-frame_ function-code frame
bits = frame.data

class ReadBitsRequest extends Request:
static COILS-ID ::= 1
static DISCRETE-INPUTS-ID ::= 2
Expand Down
17 changes: 16 additions & 1 deletion src/station.toit
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ class Station:
return holding-registers_

/**
Reads the server identifaction.
Reads the server identification.
This function is only available for serial Modbus devices, although it may also work on some Modbus TCP devices.
*/
Expand All @@ -94,6 +94,21 @@ class Station:
server-response := response as ReportServerIdResponse
return ServerIdResponse server-response.server-id server-response.on-off

/**
Reads a raw byte response for a specific $function-code.
The request may optionally include a $payload of bytes and the
result is the raw, unframed bytes in the server response.
*/
read-raw --function-code/int --payload/ByteArray=#[] -> ByteArray:
if is-broadcast: throw "Can't read from broadcast station"
logger_.debug "read-raw" --tags={"unit_id": unit-id, "function_code": function-code}
request := RawRequest function-code payload
response := bus_.send_ request --unit-id=unit-id --is-broadcast=false:
RawResponse.deserialize it function-code
raw-response := response as RawResponse
return raw-response.bits

/**
A register reader for Modbus stations.
Expand Down
2 changes: 1 addition & 1 deletion tests/test_server.toit
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ with-test-server --logger/log.Logger --mode/string [block]:
// If it didn't start we might be looking for the wrong line in its output.
// There was a change between 1.6.9 and 2.0.14. Could be that there is
// going to be another one.
with-timeout --ms=1_000:
with-timeout --ms=5_000:
server-is-running.get

network := net.open
Expand Down

0 comments on commit cf04410

Please sign in to comment.