Iot2040和Iot2050 修改串口参数

博客迁移

不恰饭的小站

IOT2040 串口表示 Linux将所有UARTs表示为ttyS,其中 x = 0, 1 对应内部设备,2, 3对应外部设备

修改指令

IOT2040 ```指令:switchserialmode

Usage: switchserialmode DEVICE [MODE [-t|–terminate]]

DEVICE The device for which you want to switch the mode. MODE
The mode you want to use: rs232, rs485, or rs422.
If omitted, the current mode will be printed.

Optional arguments: -t, --terminate Terminate the RS422 or
RS485 bus. ```例子:switchserialmode /dev/ttyS2 RS485 --terminate

IOT2050 ```指令:switchserialmode It’s used to set external serial port mode. Usage:

switchserialmode [ttyuart [options]] | [cp210x [options]] | [-m,--mode MODE]

Example:
switchserialmode ttyuart -h
switchserialmode cp210x -h
switchserialmode -m,–mode <rs232 | rs485 | rs422> [-t,–terminate]
-t,–terminate: Terminate the rs422 or rs485 bus.

指令:switchserialmode ttyuart -h

It’s to operate tty serial device.
-h,–help: display help information.
-D,–device: specified device, like ‘/dev/ttyS1’ etc.
-m,–mode mode: set serial work mode, the mode can be set ‘rs232’ or ‘rs485’ or ‘rs422’.
-l,–logic level: set RTS-pin logic level when sending in rs485 mode, logic can be set ‘0’ or ‘1’.
-d,–display: display the current mode of ttyuart

1. 查看:switchserialmode ttyuart -D /dev/ttyS2 -d
2. 设置:switchserialmode ttyuart -D /dev/ttyS2 -m RS485 -t

# 设置开机启动
## **IOT2040**
1. 创建文件:vi /etc/init.d/changetty.sh
2. chmod 755 /etc/init.d/changetty.sh
3. 修改文件 ```
#! /bin/sh
# /etc/init.d/changetty.sh

### BEGIN INIT INFO
# Provides:          changetty
# Required-Start:    
# Should-Start:
# Required-Stop:     
# Should-Stop:
# Default-Start:     2 3 4 5
# Default-Stop:      0 1 6
# Short-Description: changetty
### END INIT INFO

echo '/etc/init.d/changetty.sh' switchserialmode /dev/ttyS2 RS485
--terminate exit 0


  1. 将启动脚本链接到 /ect/rcX.d
/etc/init.d/changetty.sh  /etc/rc3.d/S20changetty  ln -s
/etc/init.d/changetty.sh  /etc/rc4.d/S20changetty  ln -s
/etc/init.d/changetty.sh  /etc/rc5.d/S20changetty ```

5. 执行并替换文件 ```switchserialmode /dev/ttyS2 RS485 --terminate switchserialmode /dev/ttyS2 RS422 --terminate switchserialmode
/dev/ttyS2 RS232

sed -i s/.*switchserialmode.*/'switchserialmode \/dev\/ttyS2 RS485
--terminate'/ /etc/init.d/changetty.sh

IOT2050

  1. 在/root 目录中创建 changetty.py ```
    #! /usr/bin/python3

import sys import subprocess import json from collections import
OrderedDict

class Process:
def init(self):
self.configureFile = ‘/etc/board-configuration.json’
self.config = self.getConfig()

def getConfig(self):
    with open(self.configureFile, 'r') as f:
        config = json.load(f, object_pairs_hook=OrderedDict)
        return config

def saveConfig(self, jsonSrc):
    with open(self.configureFile, 'w') as f:
        json.dump(jsonSrc, f, indent=4, separators=(',', ': '))

def setBasicBoard(self, mode, terminateStatus):
    command = 'switchserialmode ttyuart -D /dev/ttyS2 -m ' + mode
    subprocess.call(command, shell=True)
    self.config['User_configuration']['External_Serial_Init_Mode'] = mode
    if terminateStatus == 'on' or terminateStatus == 'off':
        self.config['User_configuration']['External_Serial_Terminate'] =

terminateStatus
self.saveConfig(self.config)

def main(argv):
try:
process = Process()

    print(argv[1])  # mode
    print(argv[2])  # terminateStatus
    process.setBasicBoard(argv[1], argv[2])
except:
    pass
finally:
    print('end world')
    return ''

if name == ‘main’:
main(sys.argv) 2. 在NodeRed 中调用脚本python changetty.py RS485 ‘on’ python changetty.py RS422 ‘on’ python changetty.py RS232 ‘on’

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值