Skip to content

Commit ab1a86f

Browse files
authored
Merge pull request #5 from TypeScriptPlayground/dev
version 1.0.0
2 parents 0944221 + e0739c1 commit ab1a86f

39 files changed

+855
-909
lines changed

.github/workflows/build.yml

Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
name: Build Binarys
2+
3+
on:
4+
push:
5+
paths:
6+
- 'src/**'
7+
- '.github/workflows/build.yml'
8+
9+
env:
10+
# Customize the CMake build type here (Release, Debug, RelWithDebInfo, etc.)
11+
BUILD_TYPE: Release
12+
13+
jobs:
14+
build_linux:
15+
name: Build linux binaries
16+
runs-on: ubuntu-latest
17+
18+
steps:
19+
- uses: actions/checkout@v3
20+
21+
- name: Configure CMake
22+
run: cmake -B ${{github.workspace}}/build -DCMAKE_BUILD_TYPE=${{env.BUILD_TYPE}}
23+
24+
- name: Build
25+
run: cmake --build ${{github.workspace}}/build --config ${{env.BUILD_TYPE}}
26+
27+
- name: Upload artifact
28+
uses: actions/upload-artifact@v3
29+
with:
30+
name: linux-binary
31+
path: ${{github.workspace}}/build/src/libserialport.so
32+
33+
build_windows:
34+
name: Build win64 binaries
35+
runs-on: windows-latest
36+
37+
steps:
38+
- uses: actions/checkout@v3
39+
40+
- name: Configure CMake
41+
run: cmake -B ${{github.workspace}}/build -DCMAKE_BUILD_TYPE=${{env.BUILD_TYPE}}
42+
43+
- name: Build
44+
run: cmake --build ${{github.workspace}}/build --config ${{env.BUILD_TYPE}}
45+
46+
- name: Upload artifact
47+
uses: actions/upload-artifact@v3
48+
with:
49+
name: windows-binary
50+
path: ${{github.workspace}}\build\src\Release\serialport.dll
51+
52+
commit:
53+
needs: [build_windows, build_linux]
54+
name: Commit binaries
55+
runs-on: ubuntu-latest
56+
57+
steps:
58+
- uses: actions/checkout@v3
59+
with:
60+
persist-credentials: false # otherwise, the token used is the GITHUB_TOKEN, instead of your personal access token.
61+
fetch-depth: 0 # otherwise, there would be errors pushing refs to the destination repository.
62+
63+
- name: Download artifact
64+
uses: actions/download-artifact@v3
65+
with:
66+
path: ${{github.workspace}}/tmp
67+
68+
- name: Create bin folder if it does not exist
69+
run: mkdir -p ${{github.workspace}}/lib/bin
70+
71+
- name: Move and rename linux binary
72+
run: mv ${{github.workspace}}/tmp/linux-binary/libserialport.so ${{github.workspace}}/lib/bin/linux.so
73+
74+
- name: Move and rename windows binary
75+
run: mv ${{github.workspace}}/tmp/windows-binary/serialport.dll ${{github.workspace}}/lib/bin/windows.dll
76+
77+
- name: Configure Git
78+
run: |
79+
git config --local user.email "github-actions[bot]@users.noreply.github.com"
80+
git config --local user.name "github-actions[bot]"
81+
82+
- name: Commit binaries
83+
run: |
84+
git add ${{github.workspace}}/lib/bin/*
85+
git diff-index --quiet HEAD || git commit -m "Commited compiled binaries"
86+
87+
- name: Push changes
88+
uses: ad-m/github-push-action@master
89+
with:
90+
github_token: ${{ secrets.RELEASE_TOKEN }}
91+
branch: ${{ github.ref }}
92+

.github/workflows/build_linux.yml

Lines changed: 0 additions & 48 deletions
This file was deleted.

.github/workflows/build_windows.yml

Lines changed: 0 additions & 40 deletions
This file was deleted.

.github/workflows/release.yml

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,11 @@
22
name: "Pre-Release"
33

44
on:
5-
push:
6-
branches: [ "main" ]
7-
paths:
8-
- 'include/**'
9-
- 'src/**'
10-
- '.github/workflows/release.yml'
115
pull_request:
126
branches: [ "main" ]
137
paths:
14-
- 'include/**'
158
- 'src/**'
9+
- '.github/workflows/release.yml'
1610

1711
env:
1812
# Customize the CMake build type here (Release, Debug, RelWithDebInfo, etc.)
@@ -69,18 +63,18 @@ jobs:
6963
path: ${{github.workspace}}/tmp
7064

7165
- name: Rename linux Binary
72-
run: mv ${{github.workspace}}/tmp/linux-binary/libserialport.so ${{github.workspace}}/lib/dls/linux.so
66+
run: mv ${{github.workspace}}/tmp/linux-binary/libserialport.so ${{github.workspace}}/lib/bin/linux.so
7367

7468
- name: Rename windows Binary
75-
run: mv ${{github.workspace}}/tmp/windows-binary/serialport.dll ${{github.workspace}}/lib/dls/windows.dll
69+
run: mv ${{github.workspace}}/tmp/windows-binary/serialport.dll ${{github.workspace}}/lib/bin/windows.dll
7670

7771
- run: cd ${{github.workspace}}
7872

7973
- name: make .tar.gz file
80-
run: tar -czvf lib.tar.gz ./lib
74+
run: tar -czvf SerialLink-lib.tar.gz ./lib
8175

8276
- name: make .zip
83-
run: zip -r lib.zip ./lib
77+
run: zip -r SerialLink-lib.zip ./lib
8478

8579
- uses: "marvinpinto/action-automatic-releases@latest"
8680
with:
@@ -89,5 +83,5 @@ jobs:
8983
prerelease: true
9084
title: "Development Build"
9185
files: |
92-
lib.tar.gz
93-
lib.zip
86+
SerialLink-lib.tar.gz
87+
SerialLink-lib.zip

.gitignore

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
#directories
22
.vscode/
33
.cache/
4-
.github/
54
build/
65
test/

CMakeLists.txt

Lines changed: 2 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1,46 +1,11 @@
1-
cmake_minimum_required(VERSION 3.10)
1+
cmake_minimum_required(VERSION 3.22)
22

33
set(PROJECT_N serialport)
44
project(${PROJECT_N} VERSION 1.0)
55

66
set(CMAKE_CXX_STANDARD 20)
77
set(CMAKE_CXX_STANDARD_REQUIRED True)
88

9-
set(LIB true)
10-
11-
file(GLOB_RECURSE SRCS ${PROJECT_SOURCE_DIR}/src/*.cpp)
12-
13-
# a macro that gets all of the header containing directories.
14-
MACRO(header_directories return_list includes_base_folder extention )
15-
FILE(GLOB_RECURSE new_list ${includes_base_folder}/*.${extention})
16-
SET(dir_list "")
17-
FOREACH(file_path ${new_list})
18-
GET_FILENAME_COMPONENT(dir_path ${file_path} PATH)
19-
SET(dir_list ${dir_list} ${dir_path})
20-
ENDFOREACH()
21-
LIST(REMOVE_DUPLICATES dir_list)
22-
SET(${return_list} ${dir_list})
23-
ENDMACRO()
24-
25-
# using said macro.
26-
header_directories(INCLUDES ${PROJECT_SOURCE_DIR}/include/ hpp)
27-
28-
message("src files:")
29-
foreach(file ${SRCS})
30-
message(STATUS ${file})
31-
endforeach()
32-
33-
message("include directories:")
34-
foreach(dir ${INCLUDES})
35-
message(STATUS ${dir})
36-
endforeach()
37-
38-
if(LIB)
39-
add_library(${PROJECT_N} SHARED ${SRCS})
40-
else()
41-
add_executable(${PROJECT_N} ${SRCS})
42-
endif(LIB)
9+
add_subdirectory(src)
4310

4411
target_include_directories(${PROJECT_N} PUBLIC include)
45-
46-
# set(CMAKE_CXX_FLAGS ${CMAKE_CXX_FLAGS} "-shared -fPIC -Wall")

README.md

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,9 @@
11
<!-- Badges -->
2-
[Build Win32 DLL]: https://img.shields.io/github/actions/workflow/status/TypeScriptPlayground/Serial/build_windows.yml?label=Build%20Win32%20DLL&labelColor=343b42&logo=github&logoColor=959DA5 'Win32 Build'
3-
[Build Linux SO]: https://img.shields.io/github/actions/workflow/status/TypeScriptPlayground/Serial/build_linux.yml?label=Build%20Linux%20SO&labelColor=343b42&logo=github&logoColor=959DA5 'Linux Build'
2+
[Build binaries]: https://img.shields.io/github/actions/workflow/status/TypeScriptPlayground/Serial/build_windows.yml?label=Build%20binaries&labelColor=343b42&logo=github&logoColor=959DA5 'Build binaries'
43
[Release Downloads]: https://img.shields.io/github/downloads/TypeScriptPlayground/Serial/total?label=Downloads%20&labelColor=343b42&logo=docusign&logoColor=959DA5 'Total Release Downloads'
54

65
# Serial
7-
[![Build Win32 DLL]](https://github.com/TypeScriptPlayground/Serial/actions/workflows/build_windows.yml)
8-
[![Build Linux SO]](https://github.com/TypeScriptPlayground/Serial/actions/workflows/build_linux.yml)
6+
[![Build binaries]](https://github.com/TypeScriptPlayground/Serial/actions/workflows/build.yml)
97
[![Release Downloads]](https://github.com/TypeScriptPlayground/Serial/releases)
108

119
<a href="https://deno.land"><img align="right" src="https://deno.land/logo.svg" height="150px" alt="the deno mascot dinosaur standing in the rain"></a>
@@ -33,10 +31,10 @@ This library provides an interface for the communication with serial devices and
3331
- Works on different operating systems (check [compatibility](#compatibility) for mor info).
3432

3533
## Compatibility
36-
| OS | Tested version | Current state |
37-
|---------|------------------|---------------|
38-
| Windows | Windows 10 (x64) | implemented |
39-
| Linux | - | in progress |
34+
| OS | Tested version | Current state |
35+
|---------|-------------------------|---------------|
36+
| Windows | Windows 10 (x64) | implemented |
37+
| Linux | Ubuntu Server 22.04 LTS | implemented |
4038

4139
## Possible/Known issues
4240
- What happens if you open multiple connections from the same instance.
@@ -45,6 +43,10 @@ This library provides an interface for the communication with serial devices and
4543
- Linux write currently not working
4644

4745
## Examples - How to use
46+
To use this library you need the following flags to run it:
47+
- `--unstable`
48+
- `--allow-ffi`
49+
4850
### Ports
4951
Get a list with all serial ports and their info that are currently available on your system.
5052

@@ -77,17 +79,17 @@ Send data to a serial device. For exampe to an [Arduino](https://www.arduino.cc/
7779
7880
`main.ts`
7981
```typescript
80-
import { Serial } from "./mod.ts";
82+
import { Serial, baudrate } from "./mod.ts";
8183
8284
// create new instance of a serial object
8385
const serial = new Serial();
8486
8587
// open the connection
86-
serial.open();
88+
serial.open('COM1', baudrate.B9600);
8789
8890
// encode the message to a Uint8Array
89-
const textToSend = 'Hello from TypeScript!'
90-
const encodedTextToSend = new TextEncoder().encode(textToSend)
91+
const textToSend = 'Hello from TypeScript!';
92+
const encodedTextToSend = new TextEncoder().encode(textToSend);
9193
9294
// send the message
9395
serial.send(encodedTextToSend, encodedTextToSend.length);
@@ -113,13 +115,13 @@ void loop() {
113115

114116
`main.ts`
115117
```typescript
116-
import { Serial } from "./mod.ts";
118+
import { Serial, baudrate } from "./mod.ts";
117119

118120
// create new instance of a serial object
119121
const serial = new Serial();
120122

121123
// open the connection
122-
serial.open();
124+
serial.open('COM1', baudrate.B9600);
123125

124126
// create a new buffer to store incoming bytes,
125127
// in this example we want to read a maximum of 100 bytes

0 commit comments

Comments
 (0)