tweterm.py
This program incorporates the pyftdi (https://github.com/eblot/pyftdi) library sample script pyterm.py with a firmware write script for TWELITE. It has the following features
  • Writing firmware for TWELITE (TWELITE R/MONOSTICK)
  • Checking the behaviour via the serial port
This script requires the Python3 interpreter to run on OS X. It is intended for users who are familiar with the command line environment and the Python interpreter.
In order to make this script work on Linux, you will need the equivalent packages (libusb-dev, pyserial, pyftdi). It is intended for people who are familiar with the command line environment and the Python interpreter.
  • reference environment:Ubuntu 16.04 (i386 32bit), Python3.5.2 / Ubuntu 18.04 (x86-64 64bit), Python 3.6.5

Warranty and license

Anything in this package that is not specifically mentioned in the license is governed by the Mono Wireless Software License Agreement.
This software is not officially supported by Mono Wireless Inc. Please note that we may not be able to answer your enquiries. Please understand beforehand.
In response to reports of defects or other problems, Mono Wireless Inc. does not promise to fix or improve the product.
It may not work in all cases, depending on the package you have installed and your environment.
1
# Copyright (C) 2017 Mono Wireless Inc. All Rights Reserved.
2
# Released under MW-SLA-*J,*E (MONO WIRELESS SOFTWARE LICENSE
3
# AGREEMENT)
Copied!

System requirements and required packages

  • Mac OS X or Linux
  • python3.5 or later
  • libusb
  • pyserial
  • pyftdi

reference environment

We have developed and tested the software in the following environments. However, we do not guarantee that it will work in these environments.
environment
Mac OS X 10.11.6, Python3.5.1 (2018/05)
Ubuntu 18.04, Python3.6.7 (2018/05)
Mac OS X 10.14.2, Python3.7.2 (2019/01)

installation

packages

OS X
Linux
Below is an example of installing all new packages using Homebrew.

Homebrew

install Homebrew.
1
/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
Copied!

Python3

1
$ brew install python3
Copied!

libusb

1
$ brew install libusb
Copied!

pyserial

1
$ pip3 install pyserial
Copied!

pyftdi

1
$ pip3 install pyftdi
Copied!
Please check your distribution's package installation instructions. You will need the following packages.
  • python3.5 or later (In many cases, it has been introduced)
  • libusb-dev
  • pyserial
  • pyftdi
example for package installation.
1
$ sudo apt-get install libusb-dev
2
$ sudo apt-get install python3-pip
3
$ pip3 install pyserial
4
$ pip3 install pyftdi
Copied!

実行

The directory where the TWELITE SDK was installed is described as ${TWELITESDK}.
The script can be found below.
1
${TWELITESDK}/Tools/tweterm/tweterm.py
Copied!
Gives the script permission to run.
1
$ chmod +x ${TWELITESDK}/Tools/tweterm/tweterm.py
Copied!
If necessary, add it to the PATH environment variable.
1
$ PATH=${TWELITESDK}/Tools/tweterm:$PATH
Copied!

Usage

Unload USB driver

Unload the driver as libusb conflicts with the OS driver.
OS X
Linux
Unloads FTDI-related drivers.
1
$ sudo kextunload -b com.apple.driver.AppleUSBFTDI
Copied!
No need to unload the driver.
If you get an error, try unloading the driver.
1
$ sudo rmmod ftdi_sio
2
$ sudo rmmod usbserial
Copied!

Command parameters

parameter
remark
-p ftdi:///? or -p
Enumerates the list of devices.
-p [device name]
Specify the device.
ftdi:///1 When no other device is available.
ftdi://::MW19ZZUB/1 Designation by serial number.
-b [baud]
Specify the baud rate
-b 115200 115200bps
-F [firmware bin file name]
Program the specified firmware.
-F App_Twelite.bin Program a file named App_Twelite.bin.
--no-color
Suppresses colour output of text.
--no-term
It only programs the firmware and does not open the terminal.

keyboard operation

Typing Ctrl+C will bring up a control prompt, which allows you to perform some special operations. Otherwise, the input string will be sent directly to the TWELITE radio module.
Key sequence
Remark
Ctrl+C Ctrl+C
quit the terminal
Ctrl+C Ctrl+R または Ctrl+C r
Reset TWELITE microcontroller.
Ctrl+C Ctrl+I または Ctrl+C i
Enter the + + + command to enter interactive mode. Only available with firmware that supports interactive mode.
Ctrl+C A
Start interpreting the format: for the output from the TWELITE wireless microcontroller and for the key input, the ascii format (like :00112233X) is interpreted.
Ctrl+C B
Starts interpreting the format; binary format is interpreted for the output from the TWELITE microcontroller. Key input is interpreted in ASCII format.
Ctrl+C N
Stops interpreting the format.
During format interpretation, only messages from TWELITE that have been interpreted will be displayed, and keyboard input will be echoed back, but will be sent to TWELITE when the ASCII format has been completed.

[Execution example]

In the example, line breaks are inserted as appropriate.
If you get an error, it may be a problem with the permissions on the serial port, run it with root privileges (e.g. sudo).

Make sure your device is listed first.

1
$ tweterm.py -p ftdi:///?
2
Available interfaces:
3
ftdi://ftdi:232:MW19ZZUB/1 (MONOSTICK)
4
Please specify the USB device
Copied!

Program the firmware and start the terminal

The following example writes App_UART (UART communication app) and checks the boot message.
1
$ tweterm.py -p ftdi://ftdi:232:MW19ZZUB/1 -b 115200 -F ../App_Uart_Master_RED_L1101_V1-2-15.bin
2
*** TWE Wrting firmware ... ../App_Uart_Master_RED_L1101_V1-2-15.bin
3
MODEL: TWEModel.TWELite
4
SER: 102eebd
5
6
file info: 0f 03 000b
7
erasing sect #0..#1..#2..
8
0%..10%..20%..30%..40%..50%..60%..70%..80%..90%..done - 10.24 kb/s
9
Entering minicom mode
10
11
!INF TWE UART APP V1-02-15, SID=0x8102EEBD, LID=0x78
12
8102EEBD:0>
Copied!

Typing Ctrl+C will bring up a control prompt

1
*** r:reset i:+++ A:ASCFMT B:BINFMT x:exit>
Copied!

Then enter i. You are now in interactive mode

1
*** r:reset i:+++ A:ASCFMT B:BINFMT x:exit>[+ + +]
2
--- CONFIG/TWE UART APP V1-02-15/SID=0x8102eebd/LID=0x00 -E ---
3
a: set Application ID (0x67720103)
4
i: set Device ID (121=0x79)
5
... <省略>
Copied!
If you type + + + three times as usual operation, you will get the same result.

Example of format interpretation: Set App_UART to binary format

In interactive mode, type m B Enter S in that order.
1
--- CONFIG/TWE UART APP V1-02-15/SID=0x8102eebd/LID=0x00 -E ---
2
a: set Application ID (0x67720103)
3
i: set Device ID (121=0x79)
4
c: set Channels (18)
5
x: set RF Conf (3)
6
r: set Role (0x0)
7
l: set Layer (0x1)
8
b: set UART baud (38400)
9
B: set UART option (8N1)
10
m: set UART mode (B)*
11
h: set handle name [sadkasldja]
12
C: set crypt mode (0)
13
o: set option bits (0x00000000)
14
---
15
S: save Configuration
16
R: reset to Defaults
17
18
!INF Write config Success
19
!INF RESET SYSTEM...
Copied!

Examples of format interpretation

In the following example, App_UART does input and output in binary format. Input Ctrl+C B.
1
*** r:reset i:+++ A:ASCFMT B:BINFMT x:exit>
2
[FMT: console ASCII, serial BINARY]
Copied!
In this state, input and output is in format. Keyboard input is interpreted as ASCII (input is converted to binary and sent to the TWELITE) and messages from the TWELITE as binary.
Here is an example of receiving a message from TWELITE. The easiest way to do this is to reset the TWELITE. Type Ctrl+C r.
1
*** r:reset i:+++ A:ASCFMT B:BINFMT x:exit>[RESET TWE]
2
[dbf1677201030001020f008102eebd0000]
Copied!
The output [dbf...] is the message from TWELITE, which is actually 0xdb 0xf1 0x67... which is actually a binary sequence.
Conversely, to send a message to TWELITE, enter it in ASCII format. Type :7800112233AABBCCDDX. This sends the data with a payload of 0x7800112233AABBCCDD to TWELITE in binary format. Immediately afterwards, [dba18001] is returned as the response.
1
:7800112233AABBCCDDX[dba18001]
Copied!

Quitting

Input Ctrl+C Ctrl+C to quit terminal.
1
*** r:reset i:+++ A:ASCFMT B:BINFMT x:exit>[
2
[EXIT]
3
Bye.
Copied!