-
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.
protocol.serialport add SerialPortProtocolSimulate
- Loading branch information
Showing
18 changed files
with
157 additions
and
57 deletions.
There are no files selected for viewing
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes
File renamed without changes
File renamed without changes.
File renamed without changes.
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,32 @@ | ||
# -*- coding: utf-8 -*- | ||
from __future__ import print_function | ||
import sys | ||
import argparse | ||
from ..protocol.serialport import SerialTransactionProtocol, SerialPort | ||
|
||
if __name__ == "__main__": | ||
parser = argparse.ArgumentParser() | ||
parser.add_argument("-p", "--port", help="Serial port name", default="COM17") | ||
parser.add_argument("-t", "--timeout", help="Serial port timeout", default=1) | ||
parser.add_argument("-b", "--baudrate", help="Serial port baudrate", default=38400) | ||
args = vars(parser.parse_args()) | ||
|
||
port = SerialPort(args.get("port"), args.get("baudrate"), args.get("timeout")) | ||
serial_transaction = SerialTransactionProtocol(port.send, port.recv) | ||
|
||
# Read test | ||
result, data = serial_transaction.read(lambda x: print("Read:{}%".format(x))) | ||
if not result: | ||
print("Read error:{0:s}".format(data)) | ||
sys.exit(-1) | ||
|
||
global_data, package_data = data[0], data[1] | ||
print("Read success: global data size: {0:d}, package data size: {1:d}".format(len(global_data), len(package_data))) | ||
|
||
# Write test | ||
result, error = serial_transaction.write(global_data, package_data, lambda x: print("Write:{}%".format(x))) | ||
if not result: | ||
print("Write error:{0:s}".format(error)) | ||
sys.exit(-1) | ||
|
||
print("Write success!") |
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
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 was deleted.
Oops, something went wrong.