zhonggp 发表于 2018-6-21 14:14:48

SuperView FlyThingsOS 串口显示屏上移植modbus协议支持串口RTU功能

SuperView 串口屏 运行的操作系统是中科世为基于Linux 开发的FlyThings OS;系统提供集成GUI开发环境,方便客户快速开发应用。
开发者页面:doc.zkswe.com;
modbus开源代码下载
可从github上下载libmodbus源码,然后先按照github说明完成configure ;

当然也可以下载我们配置好的第三方库文件:

https://github.com/zkswe/thirdPart/tree/master/libmodbus

将代码放入jni目录下的modbus目录:


注意新建项目后,系统默认打开的是串口模式,需要在main.cpp 里面注释掉串口的启动部分

void onEasyUIInit(EasyUIContext *pContext) {
    // 初始化时打开串口
    // modbus 注释掉串口应用
    //UARTCONTEXT->openUart(CONFIGMANAGER->getUartName().c_str(), CONFIGMANAGER->getUartBaudRate());
}

void onEasyUIDeinit(EasyUIContext *pContext) {
    // modbus 注释掉串口应用
    //UARTCONTEXT->closeUart();
}

const char* onStartupApp(EasyUIContext *pContext) {
    return "mainActivity";
}
libmodbus RTU的接口介绍
modbus 上下文: modbus_t

通过modbus_t 可以操作写入,读取等操作。

1.新建一个modbus_t的上下文,在mainLogic.cc 里面添加如下代码:
#include "modbus/modbus.h"

modbus_t* mctx;

在onUI_init()里面添加mctx的初始化:

static void onUI_init(){
    //Tips :添加 UI初始化的显示代码到这里,如:mText1->setText("123");
    mctx = modbus_new_rtu("/dev/ttyS1", 9600, 'N', 8, 1); // Z11s平台为ttyS1,Z6s平台为ttyS2; 9600波特率,无校验,8数据位,1停止位;
    modbus_set_slave(mctx, 1);   // 设置从设备地址为1
    modbus_connect(mctx);    // 链接
    modbus_set_byte_timeout(mctx, 5,0);    // 设置数据超时为5秒,0 us
}
modbus_new_rtu:建立一个modbus RTU链接

modbus_set_slave:设置slave的设备地址

modbus_connect:modbus 链接

modbus_set_byte_timeout:设置modbus超时

写数据
modbus_write_register如果需要切换设备地址,需要先调用modbus_set_slave;

读数据
modbus_read_registers 如果需要切换设备地址,需要先调用modbus_set_slave


样例程序:
static bool onButtonClick_ButtonRead(ZKButton *pButton) {
    LOGD(" ButtonClick ButtonRead !!!\n");
    addr = atoi(mEdittextAddrPtr->getText().c_str());
    reg = atoi(mEdittextRegPtr->getText().c_str());
    modbus_set_slave(mctx, addr);
    UINT16 buff={0};
    int ret = modbus_read_registers(mctx, reg,1, buff);
    LOGD("read ret %d buff %x,%x",ret,buff,buff);

    mEdittextDataPtr->setText((int)buff);
    return true;
}

static bool onButtonClick_ButtonWrite(ZKButton *pButton) {
    //LOGD(" ButtonClick ButtonWrite !!!\n");
    addr = atoi(mEdittextAddrPtr->getText().c_str());
    reg = atoi(mEdittextRegPtr->getText().c_str());
    data = atoi(mEdittextDataPtr->getText().c_str());
    modbus_set_slave(mctx, addr);
    modbus_write_register(mctx, reg, data);
    return true;
}

RTU测试工具界面:


终端显示界面


源码包

gaolf_2012 发表于 2018-7-4 07:59:20

开发环境下载挂了!


zhonggp 发表于 2018-7-4 12:18:00

gaolf_2012 发表于 2018-7-4 07:59
开发环境下载挂了!

这里进去试试
https://doc.zkswe.com/download

gaolf_2012 发表于 2018-7-4 12:23:15

10:30左右已经恢复正常,杭州的曲奇云盘工作人员特意回电话询问结果,可见还不算太不靠谱.
不过我试了下连PC,驱动一直没有装成功

linbin250 发表于 2018-7-4 14:25:06

刚好要用串口屏,参考一下!
用LINUX,不知能否读写一些数据到TF卡或者FLASH中.

zhonggp 发表于 2018-7-4 19:20:47

linbin250 发表于 2018-7-4 14:25
刚好要用串口屏,参考一下!
用LINUX,不知能否读写一些数据到TF卡或者FLASH中.

是的,非常方便就可以操作内部的存储或者是外部的tfcard

zhonggp 发表于 2018-7-4 19:25:55

gaolf_2012 发表于 2018-7-4 12:23
10:30左右已经恢复正常,杭州的曲奇云盘工作人员特意回电话询问结果,可见还不算太不靠谱.
不过我试了下连PC, ...

自己部署这么高带宽的服务器不太现实,所以只能依靠第三方的共享盘。而百度这类盘限速太严重了。所以只选择了曲奇办公。

驱动可以通过驱动精灵,豌豆荚安装。

huike 发表于 2018-7-4 20:56:53

屏的排线还是有点怪怪的
另外这个屏长期看,价格有不有打算涨?涨多少?有些厂家是看用户差不多了,直接翻倍上去。你们的计划呢?100元?150?,,,

zhonggp 发表于 2018-7-4 21:36:10

huike 发表于 2018-7-4 20:56
屏的排线还是有点怪怪的
另外这个屏长期看,价格有不有打算涨?涨多少?有些厂家是看用户差不多了,直接翻 ...

可以进店看看,已经调整到正常销售价格了。

gaolf_2012 发表于 2018-7-5 07:33:05

huike 发表于 2018-7-4 20:56
屏的排线还是有点怪怪的
另外这个屏长期看,价格有不有打算涨?涨多少?有些厂家是看用户差不多了,直接翻 ...

利用手上现成的usb转485板飞了个232TTL转485,隔离处理后放心多了.


huike 发表于 2018-7-5 10:50:55

gaolf_2012 发表于 2018-7-5 07:33
利用手上现成的usb转485板飞了个232TTL转485,隔离处理后放心多了.

我是指屏背后的排线

gaolf_2012 发表于 2018-7-5 11:08:19

huike 发表于 2018-7-5 10:50
我是指屏背后的排线

当时我也纳闷了一会儿,三组排线变一组?后来仔细看才发现有的直接焊到板上了.

linbin250 发表于 2018-7-5 12:32:18

zhonggp 发表于 2018-7-4 19:20
是的,非常方便就可以操作内部的存储或者是外部的tfcard

谢谢!
我认真看了网页上的介绍,似乎入手还是需要一些基础,看来需要摸爬滚打一下.

有关存储.似乎支持的是 KEY与Value的方式.感觉像是读写INI文件的感觉.

链接如下:
https://doc.zkswe.com/data

内容描述如下:
本框架提供了一套简单的数据存储接口,以键-值对的方式存储,接口见storage/StoragePreferences.h:

// 存储接口
static bool putString(const std::string &key, const std::string &val);
static bool putInt(const std::string &key, int val);
static bool putBool(const std::string &key, bool val);
static bool putFloat(const std::string &key, float val);

// 删除指定键
static bool remove(const std::string &key);
// 清空存储数据
static bool clear();

// 获取接口,获取不到对应键值,返回defVal默认值
static std::string getString(const std::string &key, const std::string &defVal);
static int getInt(const std::string &key, int defVal);
static bool getBool(const std::string &key, bool defVal);
static float getFloat(const std::string &key, float defVal);


第1个问题
=============
这个空间能存多少?
现在有一个需求是,记录事件,我不想把事件存到单片机里面,空间实在有限.
事件要求是:
1. 年月日时分秒,
2. 事件内容字符串

所以,我打算建立一组KEY
例如 EVENT_00-> EVENT_99    内容为字符串,预计字符串长度为50个字节.

不知能不能存储这么多.
其次,需要用列表框显示,并且在右边有一个下拉滚动条,以拖动显示.

第2个问题
=============
你的商店里面有2个7寸屏幕,
分别是
7寸高清1024x600串口屏 Linux替换Android 音视频 电容屏 WiFi
中科世为SuperView Z11s 7寸串口屏 800x480 Linux FlyThingsOS

链接就不贴了
问一下,这2个7寸屏幕除了分辨率,其余都一样么?

zhonggp 发表于 2018-7-5 21:02:04

linbin250 发表于 2018-7-5 12:32
谢谢!
我认真看了网页上的介绍,似乎入手还是需要一些基础,看来需要摸爬滚打一下.



回答你的问题:

zhonggp 发表于 2018-7-4 19:20
是的,非常方便就可以操作内部的存储或者是外部的tfcard

谢谢!
我认真看了网页上的介绍,似乎入手还是需要一些基础,看来需要摸爬滚打一下.

有关存储.似乎支持的是 KEY与Value的方式.感觉像是读写INI文件的感觉.

链接如下:
https://doc.zkswe.com/data

内容描述如下:
本框架提供了一套简单的数据存储接口,以键-值对的方式存储,接口见storage/StoragePreferences.h:

// 存储接口
static bool putString(const std::string &key, const std::string &val);
static bool putInt(const std::string &key, int val);
static bool putBool(const std::string &key, bool val);
static bool putFloat(const std::string &key, float val);

// 删除指定键
static bool remove(const std::string &key);
// 清空存储数据
static bool clear();

// 获取接口,获取不到对应键值,返回defVal默认值
static std::string getString(const std::string &key, const std::string &defVal);
static int getInt(const std::string &key, int defVal);
static bool getBool(const std::string &key, bool defVal);
static float getFloat(const std::string &key, float defVal);


第1个问题
=============
这个空间能存多少?
内部存储1M空间,当然可以定制大小。

现在有一个需求是,记录事件,我不想把事件存到单片机里面,空间实在有限.
事件要求是:
1. 年月日时分秒,
2. 事件内容字符串

所以,我打算建立一组KEY
例如 EVENT_00-> EVENT_99    内容为字符串,预计字符串长度为50个字节.

不知能不能存储这么多.
其次,需要用列表框显示,并且在右边有一个下拉滚动条,以拖动显示.

这个建议使用sqlite数据库的方式,具体的方法建议参考我们有个sqlite 的使用方法。

第2个问题
=============
你的商店里面有2个7寸屏幕,
分别是
7寸高清1024x600串口屏 Linux替换Android 音视频 电容屏 WiFi
中科世为SuperView Z11s 7寸串口屏 800x480 Linux FlyThingsOS

链接就不贴了
问一下,这2个7寸屏幕除了分辨率,其余都一样么?

是的,只有分辨率不同

zhonggp 发表于 2018-7-5 21:03:10

gaolf_2012 发表于 2018-7-5 11:08
当时我也纳闷了一会儿,三组排线变一组?后来仔细看才发现有的直接焊到板上了. ...

板上预留了485的接口位置。

zhonggp 发表于 2018-7-5 21:04:36

huike 发表于 2018-7-4 20:56
屏的排线还是有点怪怪的
另外这个屏长期看,价格有不有打算涨?涨多少?有些厂家是看用户差不多了,直接翻 ...

那个不是焊接了。是被压倒板子下面了。实际背面在店里面有图片

linbin250 发表于 2018-7-6 16:15:23

zhonggp 发表于 2018-7-5 21:02
回答你的问题:

zhonggp 发表于 2018-7-4 19:20


谢谢:)
我测试安装软件,没有找到模拟运行功能,似乎自由连上板子之后才能运行,是么?

zhonggp 发表于 2018-7-6 19:04:47

linbin250 发表于 2018-7-6 16:15
谢谢:)
我测试安装软件,没有找到模拟运行功能,似乎自由连上板子之后才能运行,是么? ...

是的,PC端模拟器还在开发中

gaolf_2012 发表于 2018-7-7 14:18:36

14:11:53 **** 构建 of configuration Debug for project modbusTest ****
ndk-build.cmd -j4 all
无法运行程序“ndk-build.cmd”:Launching failed

Error: Program "ndk-build.cmd" not found in PATH
PATH=

14:11:53 Build Finished (took 34ms)
1楼工程下载后编译失败.这个如何解决呢?

zhonggp 发表于 2018-7-7 15:33:08

gaolf_2012 发表于 2018-7-7 14:18
14:11:53 **** 构建 of configuration Debug for project modbusTest ****
ndk-build.cmd -j4 all
无法运 ...

https://doc.zkswe.com/problems

砂山老妖 发表于 2018-7-7 15:34:20

ok      

linbin250 发表于 2018-7-31 09:04:16

屏幕买到了,开始实测。。。


linbin250 发表于 2018-8-16 17:59:00

询问一个需求:

大约5寸的屏幕,我想显示一个从上位机(电脑)传送过来的图片,希望是USB接口的方式,(串口估计传送估计比较慢)
上位机(电脑),发送一张图片的内容,然后显示屏上显示出来.

不知道行不行.

追杀小妖龙 发表于 2021-3-11 11:44:23

fly things ide编译出现这个问题, 请问要怎么解决啊?
页: [1]
查看完整版本: SuperView FlyThingsOS 串口显示屏上移植modbus协议支持串口RTU功能