仰邦LED-bx_y08二次开发的java版流程梳理记录

首次开发的项目是一个停车场主要显示剩余多少车辆 遇到很多难题;主要还要搞清楚二次开发LED的发送流程,在这记录下

//初始化API环境 仅一次
Y2Env.initial("log.properties");
//链接固定的LEDIPString url="http://172.111.30.11";Y2Screen screen = new Y2Screen(url);//登陆if(!screen.login("guest", "guest")){System.out.println("登入失败!");//登录成功 初始化资源screen.turnOff();//关机screen.turnOn(); //开机screen.syncTime();//校时screen.changeVolume(60); //音量调至60screen.clearPlayResources();//清除播放资源(删除播放节目)// 建立动态节目DynamicPlayFile file = new DynamicPlayFile();//建立区域DynamicArea darea = file.createArea(0,0,80,32,1);//top ,left ,width.height ,节目编码;节目最终的显示位置大小DynamicArea darea2 = file.createArea(0,40,80,30,2);
//它的动态展示效果   二次开发包里的 PDF 有介绍 animationType(0)  0代表快速打印darea.addText("剩余车位").fgColor(Color.red).stayTime(200).animationSpeed(10).rowHeight(height).animationType(0).setFont(new Y2Font() .size(fontSize));darea2.addText("数量"+5).fgColor(Color.green).setFont(new Y2Font().size(24));System.out.println(i);boolean write = dyn.write(file);System.out.println("是否成功"+ write);
screen.logout();//退出

关于项目测试时用的代码 的逻辑实现
中文 乱码问题 自己转的utf-8 失败告终 :没在去测试别的
二次开发包里 C#示例代码里 是转化成的 base64 ( java里应该也是这 没有测试)

上面与图片只是很简陋测试代码
如有错误,想法请告知
部署tomcat后 现场返回的日志 只有重启服务才会登陆一次 中间无写入失败再去登陆的情况 ,隔上两三天 LED 黑屏 ,只能强制每天登陆两次,具体的状况没搞清楚? -_-?
当时写完 没有优化过的 凑活着看吧`

package com.example.carboen.main;import onbon.y2.Y2DynamicManager;
import onbon.y2.Y2Env;
import onbon.y2.Y2Exception;
import onbon.y2.Y2Screen;
import onbon.y2.common.AlignmentType;
import onbon.y2.common.Y2Font;
import onbon.y2.play.DynamicArea;
import onbon.y2.play.DynamicPlayFile;
import onbon.y2.play.ProgramPlayFile;
import onbon.y2.play.TextArea;
import org.apache.http.impl.client.HttpClients;
import org.apache.juli.logging.Log;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.boot.ApplicationArguments;
import org.springframework.boot.ApplicationRunner;
import org.springframework.core.io.ClassPathResource;
import org.springframework.core.io.support.PropertiesLoaderUtils;
import org.springframework.http.client.ClientHttpRequestFactory;
import org.springframework.http.client.HttpComponentsClientHttpRequestFactory;
import org.springframework.stereotype.Component;import java.awt.*;
import java.io.*;
import java.net.URL;
import java.net.URLConnection;
import java.text.SimpleDateFormat;
import java.util.*;@Component
public class CarInfo implements ApplicationRunner {// public Y2Screen screen;//  public Y2Screen screen2;public static int oldInt = -1;public static int newInt = -1;static  SimpleDateFormat simpleDateFormat = new SimpleDateFormat("HH");static Y2Screen screen;static  Y2Screen screen2;// 于节目中新增一个动态区Date date;SimpleDateFormat ss = new SimpleDateFormat("ss");SimpleDateFormat mm = new SimpleDateFormat("mm");static  String ip1 = "";static  String ip2 = "";static Logger logger =LoggerFactory.getLogger(CarInfo.class);// public  static   Map<String,String> forObject;@Overridepublic void run(ApplicationArguments args) throws Exception {Properties properties = new Properties();properties = PropertiesLoaderUtils.loadProperties(new ClassPathResource("db.properties"));logger.info("正在链接--稍等");System.out.println("正在链接--稍等");//初始化API环境 仅一次Y2Env.initial("log.properties");//连上特定的屏幕并执行一些命令//建立一个新的屏幕try {Properties properties1 = new Properties();properties1 = PropertiesLoaderUtils.loadProperties(new ClassPathResource("db.properties"));ip1 = properties.getProperty("ip1");ip2 = properties.getProperty("ip2");}catch (Exception e){logger.info( e.getMessage());System.out.println(e.getMessage());}screen = startInfo(ip1);screen2 = startInfo(ip2);timerStart();}public Y2Screen startInfo(String ip) {try {Y2Screen screen3 = new Y2Screen("http://" + ip);//登入if (!screen3.login("guest", "guest")) {logger.info("登入失败!"+ip);System.out.println("登入败!"+ip);}else {logger.info("登入成功!"+ip);System.out.println("登入成功!"+ip);}//403968491// screen3.turnOff();//关机boolean b = screen3.turnOn();//开机screen3.syncTime();//校时screen3.changeVolume(60); //音量调至60screen3.clearPlayResources();//清除播放资源(删除播放节目)// textArea(screen,0);//   timerStart();return screen3;} catch (Exception e) {logger.info(e.getMessage());System.out.println(e.getMessage());return null;}}public void timerStart() {try {Properties properties = new Properties();properties = PropertiesLoaderUtils.loadProperties(new ClassPathResource("db.properties"));int timeStart1 = Integer.parseInt(properties.getProperty("timeStart"));int timeOut = Integer.parseInt(properties.getProperty("timeOut"));String interfaseIP = properties.getProperty("interfaseIP");String intervalTime = properties.getProperty("intervalTime");long period = Long.parseLong(intervalTime);
//            ip1 = properties.getProperty("ip1");
//            ip2 = properties.getProperty("ip2");Timer timer = new Timer();//  Integer oldMes = OldStopCarInfo.getTotalRemainNum();logger.warn("开启 定时循环");timer.schedule(new TimerTask() {//网络 接口 待定@Overridepublic void run() {logger.warn("定时循环开始--"+oldInt+"--"+newInt);//上次的 记录数据 = 新数据  下面作比较oldInt = newInt;ClientHttpRequestFactory requestFactory = new HttpComponentsClientHttpRequestFactory(HttpClients.createDefault());//post 取数据String s = sendPost("http://" + interfaseIP, null);//取不到 一直取while (s==null){s= sendPost("http://" + interfaseIP, null);try {Thread.sleep(5000);} catch (Exception e) {System.out.println(e.getMessage());}}net.sf.json.JSONObject jsonObject = net.sf.json.JSONObject.fromObject(s);//    StopCarInfo stopCarInfo = (StopCarInfo) net.sf.json.JSONObject.toBean(jsonObject, StopCarInfo.class);newInt = jsonObject.getInt("totalRemainNum");logger.warn("http接口参数分析"+newInt+" "+oldInt);System.out.println("http接口参数分析"+newInt+" "+oldInt);//解析的数据 传给 newintint old1= oldInt;
int new1=newInt;//    System.out.println(anInt);date = new Date();String format = simpleDateFormat.format(date);int dateInt = Integer.parseInt(format);String formatss = ss.format(date);String formatmm = mm.format(date);if(dateInt==5){if (formatmm.equals("15")){if(formatss.equals("01")||formatss.equals("02")||formatss.equals("03")||formatss.equals("04")||formatss.equals("05")||formatss.equals("06")||formatss.equals("07")||formatss.equals("08"))screen = startInfo(ip1);screen2 = startInfo(ip2);}}//强制每天登陆2次if(dateInt==16) {if (formatmm.equals("30")) {if (formatss.equals("01") || formatss.equals("02") || formatss.equals("03") || formatss.equals("04") || formatss.equals("05") || formatss.equals("06") || formatss.equals("07") || formatss.equals("08"))screen = startInfo(ip1);screen2 = startInfo(ip2);}}//时间 设定 关机if (dateInt >= timeStart1 && dateInt < timeOut) {try {//       System.out.println("黑屏时间已到");screen.clearPlayResources();screen2.clearPlayResources();logger.warn("时间 设定 清屏");System.out.println("时间 设定 清屏");Long aLong = (1000 * 60 * 25L);try {Thread.sleep(aLong);} catch (Exception e) {System.out.println(e.getMessage());}} catch (Y2Exception e) {e.printStackTrace();};//参数判断 一致不作为}else if (old1 == new1) {logger.warn(oldInt+"相等"+newInt+"参数判断一致不写入LED");System.out.println(oldInt+"相等"+newInt+"参数判断一致不写入LED");// 参数不一致 写入数据}else if(old1 != new1) {//执行 节目 分类 发送 把 newMes字符 传递//写入是否成功 不成功  重新登入logger.warn(oldInt+"不相等"+newInt);System.out.println(oldInt+"不相等"+newInt);try{screen.clearPlayResources();screen2.clearPlayResources();}catch (Exception e){logger.info(e.getMessage());System.out.println(e.getMessage());}Boolean he = he(screen, newInt);Boolean he1 = he(screen2, newInt);if (!he){logger.warn("写入失败"+ip1+"登陆");System.out.println("写入失败"+ip1+"登陆");screen = startInfo(ip1);}else {logger.warn("写入成功"+ip1);System.out.println("写入成功"+ip1);}if (!he1){System.out.println("写入失败"+ip2+"登陆");logger.info("写入失败"+ip2+"登陆");screen2 = startInfo(ip2);}else {logger.warn("写入成功"+ip2);System.out.println("写入成功"+ip2);}}else {logger.info(oldInt+"---"+newInt);}//   stopCarInfo = OldStopCarInfo;}}, 8000, period);//延迟8秒启动,每?秒执行一次;0} catch (Exception e) {System.out.println(e.getMessage());//  timerStart();}}public Boolean he(Y2Screen screen, int textArea1) {logger.warn("写入动态区域");System.out.println("写入动态区域");try {Properties properties1 = new Properties();properties1 = PropertiesLoaderUtils.loadProperties(new ClassPathResource("db.properties"));int x = Integer.parseInt(properties1.getProperty("x"));int y = Integer.parseInt(properties1.getProperty("y"));int width = Integer.parseInt(properties1.getProperty("width"));int height = Integer.parseInt(properties1.getProperty("height"));int fontSize = Integer.parseInt(properties1.getProperty("fontsize"));int rowheight = Integer.parseInt(properties1.getProperty("rowHeight"));int x2 = Integer.parseInt(properties1.getProperty("x2"));int y2 = Integer.parseInt(properties1.getProperty("y2"));int width2 = Integer.parseInt(properties1.getProperty("width2"));int height2 = Integer.parseInt(properties1.getProperty("height2"));int fontSize2 = Integer.parseInt(properties1.getProperty("fontsize2"));String row1 = properties1.getProperty("row1");String row2 = properties1.getProperty("row2");String texarea = "";if (10 > textArea1) {texarea = "00" + textArea1;} else if (100 > textArea1) {texarea = "0" + textArea1;} else {texarea = "" + textArea1;}//字体行数int rwo = Integer.parseInt(properties1.getProperty("row"));Y2DynamicManager dyn = screen.dynamic();DynamicPlayFile file = new DynamicPlayFile();DynamicArea darea = file.createArea(x,y,width,height,1);DynamicArea darea2 = file.createArea(x2,y2,width2,height2,2);darea.addText("剩余车位").fgColor(Color.red).stayTime(200).animationSpeed(10).rowHeight(height).animationType(0).setFont(new Y2Font().size(fontSize));darea2.addText(texarea).fgColor(Color.green).stayTime(200).animationSpeed(10).animationType(0).rowHeight(height2).setFont(new Y2Font().size(fontSize2));//  将动态区上传boolean write = dyn.write(file);return write;} catch (Exception e) {logger.warn("写入动态区域出错"+e.getMessage());System.out.println("写入动态区域出错"+e.getMessage());}return false;}public static String sendPost(String url, String param) {logger.warn("接口取参");PrintWriter out = null;BufferedReader in = null;String result = "";try {URL realUrl = new URL(url);// 打开和URL之间的连接URLConnection conn = realUrl.openConnection();// 设置通用的请求属性conn.setRequestProperty("accept", "*/*");conn.setRequestProperty("connection", "Keep-Alive");conn.setRequestProperty("user-agent","Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1;SV1)");// 发送POST请求必须设置如下两行conn.setDoOutput(true);conn.setDoInput(true);// 获取URLConnection对象对应的输出流out = new PrintWriter(conn.getOutputStream());// 发送请求参数out.print(param);// flush输出流的缓冲out.flush();// 定义BufferedReader输入流来读取URL的响应in = new BufferedReader(new InputStreamReader(conn.getInputStream()));String line;while ((line = in.readLine()) != null) {result += line;}} catch (Exception e) {logger.info("发送 POST 请求出现异常!" + e);System.out.println("发送 POST 请求出现异常!" + e);
return null;}//使用finally块来关闭输出流、输入流finally {try {if (out != null) {out.close();}if (in != null) {in.close();}} catch (IOException ex) {System.out.println(ex.getMessage());}}return result;}
}
                   `

仰邦LED(BX-Y08)二次开发的java版流程梳理记录相关推荐

  1. 仰邦BX-Y1L的SDK二次开发--->用python32调用C++的dll库

    https://blog.csdn.net/inch2006/article/details/79930414 https://www.cnblogs.com/gaowengang/p/7919219 ...

  2. 海康摄像头的二次开发(java)

    海康摄像头的二次开发(java) 我第一次接触海康摄像头的二次开发的项目,一开始的时候摸不清套路,走了不少弯路,现在准备把我的一些经验留下来,让大家参考一下. 1.首先到海康的官网下载设备网络SDK: ...

  3. 二次开发:flowable审批流程实践与创建流程源码分析

    二次开发:flowable审批流程实践与创建流程源码分析 上一篇已经描述了基于开源项目https://doc.iocoder.cn/的flowable的快速开发,创建了一个租户,创建了用户和相应的岗位 ...

  4. 第六篇 :微信公众平台开发实战Java版之如何自定义微信公众号菜单

    我们来了解一下 自定义菜单创建接口: http请求方式:POST(请使用https协议) https://api.weixin.qq.com/cgi-bin/menu/create?access_to ...

  5. 第三篇 :微信公众平台开发实战Java版之请求消息,响应消息以及事件消息类的封装...

    微信服务器和第三方服务器之间究竟是通过什么方式进行对话的? 下面,我们先看下图: 其实我们可以简单的理解: (1)首先,用户向微信服务器发送消息: (2)微信服务器接收到用户的消息处理之后,通过开发者 ...

  6. 第八篇 :微信公众平台开发实战Java版之如何网页授权获取用户基本信息

    第一部分:微信授权获取基本信息的介绍 我们首先来看看官方的文档怎么说: 如果用户在微信客户端中访问第三方网页,公众号可以通过微信网页授权机制,来获取用户基本信息,进而实现业务逻辑. 关于网页授权回调域 ...

  7. 第一篇:微信公众平台开发实战Java版之了解微信公众平台基础知识以及资料准备...

    相信很多人或多或少听说了微信公众平台的火热.但是开发还是有一点门槛,鉴于挺多朋友问我怎么开发,问多了,自己平时也进行以下总结. 所以下面给大家分享一下我的经验: 第一部分   介绍微信公众号的一些简单 ...

  8. 微信公众平台开发教程Java版(六) 事件处理(菜单点击/关注/取消关注)

    前言: 事件处理是非常重要的,这一章讲讲常见的事件处理 1.关注/取消关注 2.菜单点击 事件类型介绍: 在微信中有事件请求是消息请求中的一种.请求类型为:event 而event事件类型又分多种事件 ...

  9. 海康摄像头二次开发python_海康摄像头的二次开发(java)

    海康摄像头的二次开发(java) 我第一次接触海康摄像头的二次开发的项目,一开始的时候摸不清套路,走了不少弯路,现在准备把我的一些经验留下来,让大家参考一下. 1.首先到海康的官网下载设备网络SDK: ...

最新文章

  1. LSD-SLAM解读——帧间追踪(详细推导)
  2. 大多数人对AI的理解,都是错的
  3. web移动端_移动端的轮播
  4. yolo3(目标检测)实测
  5. mysql raiserror_RAISERROR在SQL Server数据库中的用法
  6. 【电子信息复试】考研复试常考问题——数据结构
  7. Spring Boot微服务,Docker和Kubernetes研讨会–第3部分
  8. OOB套接字传输实例(达不到预期结果)
  9. html页面手机端console,vue项目以及独立HTML项目在手机端查看控制台日志 vconsole
  10. Mavlink 协议硬解析主要代码
  11. javascript实现窗口随着鼠标移动且移动路径重现
  12. 编译原理:CH3 语法分析
  13. 一些易被忽视且难度较高的Web前端面试题汇总
  14. MiniOSD DIY记
  15. IMAP常用命令汇总
  16. ns手柄pc驱动_颜值、功能、手感同步在线 北通宙斯机械游戏手柄体验
  17. SDHC (High Capacity SD Memory Card)
  18. wuc-tab标签点击不了_微信公众号新增标签功能,格力被中国移动取消竞标资格,全国电子无偿献血证上线,QQ新增辣椒酱表情,这就是今天的其他大新闻!...
  19. 微信/QQ域名防封防拦截360不报毒任意链接跳转源码
  20. CSS3 制作旋转的大风车

热门文章

  1. 2020极客大挑战web部分复现
  2. 十三、机器学习四大神器之XGBoost、LightGBM、Catboost和NGBoost
  3. Nmap使用NSE进行漏洞扫描
  4. h5棋牌房间如何安装 现在分享一套搭建教程
  5. 中山大学 计算机学院 数字图像处理 2020 期末考试(A卷)
  6. 递归算法 -- 计算n!(n的阶乘)
  7. win11怎么关闭系统通知和软件通知?
  8. jQuery 间歇式无缝滚动特效分享(三张图片平行滚动)
  9. 大津法(Python实现)
  10. VScode修改插件安装位置最有效的方法