-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #77 from jonyboi396825/develop
Release 0.1
- Loading branch information
Showing
17 changed files
with
167 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
Examples of COM-Server: | ||
|
||
NOTE: You need an Arduino, and you have to upload the Arduino sketches provided under each directory before running the scripts in that directory. | ||
|
||
blink - An simple example of sending data to the serial port. It allows you to manipulate the LED on the Arduino from the command line. | ||
Upload the blink.ino sketch, then run the python script. | ||
|
||
send_back - The sketch tells the Arduino to read the data from the serial port until a newline character, then it will send that data back through the serial port. | ||
Upload the send_back.ino sketch, then run each python script. Press ^C (Control-C) to exit the program. Read the files to see what output is expected. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
/* | ||
blink.ino | ||
This sketch reads data from the serial port, then changes the | ||
state of the built-in LED whenever a command comes in from the | ||
serial port. The baud rate for this is 115200. | ||
When it reads "s", then it leaves it on solid. | ||
When it reads "b", then it blinks the LED. | ||
When it reads "o", then it turns the LED off. | ||
It shows how you can write data to the Arduino using | ||
com_server. | ||
Copyright 2021 (c) Jonathan Liu | ||
Code is licensed under MIT license. | ||
*/ | ||
|
||
int curstate = 0; // 0 = off, 1 = blink, 2 = solid on | ||
|
||
void setup(){ | ||
Serial.begin(115200); | ||
|
||
pinMode(LED_BUILTIN, OUTPUT); | ||
} | ||
|
||
void loop(){ | ||
if (Serial.available()){ | ||
String s = Serial.readStringUntil('\n'); | ||
|
||
if (s == "s") | ||
curstate = 2; | ||
else if (s == "b") | ||
curstate = 1; | ||
else | ||
curstate = 0; | ||
} | ||
|
||
if (curstate == 0) { | ||
digitalWrite(LED_BUILTIN, LOW); | ||
} else if (curstate == 2) { | ||
digitalWrite(LED_BUILTIN, HIGH); | ||
} else { | ||
// blink every second so cycle = 2 seconds | ||
digitalWrite(LED_BUILTIN, ((millis() / 1000) % 2 == 0)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
#!/usr/bin/env python3 | ||
# -*- coding: utf-8 -*- | ||
|
||
""" | ||
An example of writing data to an Arduino. | ||
This sketch will ask for an input, and the | ||
built-in LED on the Arduino should turn on, | ||
blink, or turn off based on different inputs. | ||
NOTE: The sketch located in examples/blink must | ||
be uploaded to an Arduino before running this script. | ||
""" | ||
|
||
import time | ||
|
||
from com_server import Connection | ||
|
||
# make the Connection object; make send_interval 0.1 seconds because not sending large data | ||
conn = Connection(baud=115200, port="/dev/ttyUSB0", send_interval=0.1) # if Linux | ||
# conn = Connection(baud=115200, port="/dev/ttyUSB...", send_interval=0.1) # if Linux; can be "/dev/ttyACM..." | ||
# conn = Connection(baud=115200, port="/dev/cu.usbserial...", send_interval=0.1) # if Mac | ||
# conn = Connection(baud=115200, port="COM...", send_interval=0.1) # if Windows | ||
|
||
with conn: | ||
# use a context manager, which will connect and disconnect | ||
# automatically when entering and exiting. | ||
|
||
while conn.connected: | ||
# continue running as long as there is a connection established | ||
|
||
cmd = input("Enter LED state: (s)olid, (b)link, (o)ff, or (e)xit: ") | ||
|
||
if cmd == "e" or cmd == "exit": | ||
break | ||
elif cmd == "s" or cmd == "solid": | ||
conn.send("s", ending='\n') | ||
elif cmd == "b" or cmd == "blink": | ||
conn.send("b", ending='\n') | ||
elif cmd == "o" or cmd == "off": | ||
conn.send("o", ending='\n') | ||
else: | ||
print("Command not recognized; please try again.") | ||
|
||
# Recommended to include a delay when using connection | ||
# object in a loop | ||
time.sleep(0.01) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
[metadata] | ||
name = com-server | ||
version = 0.1b1 | ||
version = 0.1 | ||
author = Jonathan Liu | ||
author_email = [email protected] | ||
description = A simple Python library and a REST API server that interacts with COM ports | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -21,4 +21,4 @@ | |
|
||
from .api_builtins import Builtins | ||
|
||
__version__ = "0.1b1" | ||
__version__ = "0.1" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters