良好的设计源自实践,优秀的基础决定上限
上一篇用JRT连设备实现了比较有难度的Sebia绘图设备和TCP模式连接。这次连接最常见的检验设备(西森美康),读文件和图上传出图。
结果格式
通道对应
接口设置
接口处理实现,JRT设备连接全部采用CMD驱动方式实现,所以需要客户端执行对应操作返回对应CMD即可。客户端对CMD负责,实现了对应的CMD执行器。
import JRT.Core.Dto.CmdDto;
import JRT.Core.Dto.OutValue;
import JRT.Core.Util.LogUtils;
import JRT.Core.Util.MakeCmdUtil;
import JRT.Model.Bussiness.Parameters;
import JRTBLLBase.BaseHttpHandlerMachine;
import JRTBLLBase.Helper;
import java.util.ArrayList;
import java.util.List;
/**
* 希森美康XN9000仪器接口
*/
public class miXN9000 extends BaseHttpHandlerMachine {
/**
* 流水号
*/
private static String dataEpis="";
/**
* 数据的日期
*/
private static int date=Helper.GetNowDate();
/**
* 数据的时间
*/
private static int time=Helper.GetNowTime();
/**
* 缓存结果
*/
private static String result="";
/**
* 保存仪器数据
*
* @param Param 参数
* @param Session
* @param Output
* @return
* @throws Exception
*/
public String SaveData(Parameters Param, OutValue Session, OutValue Output) throws Exception {
String mi = Param.P0;
String data = Param.P1;
String epis = Param.P2;
String fileName = Param.P3;
String DBColName = Param.P4;
Trace(mi, data, "M->H");
//读取文件到第几行数据
int index = Helper.ValidParam(Param.P5, -1);
//返回的数据
List<CmdDto> cmdList = new ArrayList<>();
try {
String [] arr=data.split(",");
//第一行解析流水号和结果日期时间
if(arr[0].equals("0"))
{
String dateStr=arr[1];
date=Helper.DateToInt(dateStr);
String timeStr=arr[2];
time=Helper.TimeToInt(timeStr);
dataEpis=arr[3];
result="";
}
//解析结果
else if(arr[0].equals("1"))
{
String chl=arr[1];
String res=arr[3];
result+=chl+"\\"+res+",";
}
//解析图片
else if(arr[0].equals("3"))
{
String imgClass=arr[2];
String imgPath=arr[3];
//取图
MakeCmdUtil.AddGetImageCmd(cmdList, dataEpis, imgClass, imgPath, "");
//删图
//MakeCmdUtil.AddRMCmd(cmdList,imgPath);
}
//最后一行保存结果
if(index==-1&&!dataEpis.isEmpty())
{
Trace(mi, result, "解析结果");
//处理数据
Helper.GetBllMethodData("mi.miBase", "SaveResult", mi, dataEpis, result, date, time);
}
Trace(mi, "解析完成", "M->H");
} catch (Exception ex) {
LogUtils.WriteExceptionLog("解析XN9000仪器结果发生错误", ex);
}
return Helper.Object2Json(cmdList);
}
/**
* 得到文件服务地址供接口上传图片
*
* @param Param
* @param Session
* @param Output
* @return
* @throws Exception
*/
public String GetFileService(Parameters Param, OutValue Session, OutValue Output) throws Exception {
String mi = Param.P0;
String path = (String) Helper.GetBllMethodData("mi.miBase", "GetFileService", mi);
//返回文件服务路径
return path;
}
/**
* 保存文件到数据库
*
* @param Param
* @param Session
* @param Output
* @return
* @throws Exception
*/
public String SaveImage(Parameters Param, OutValue Session, OutValue Output) throws Exception {
String mi = Param.P0;
String epis = Param.P1;
String ImageClass = Param.P2;
String fileName = Param.P3;
String fullName = Param.P4;
String caption = "";
String displayRatio = "";
String width = "";
String height = "";
String sequence = "";
Integer receiveDate = null;
String ret = (String) Helper.GetBllMethodData("mi.miBase", "SaveImage", mi, epis, ImageClass, "", fileName, null, caption, displayRatio, width, height, sequence);
return ret;
}
/**
* 查询要上传的指令
*
* @param Param
* @param Session
* @param Output
* @return
* @throws Exception
*/
public String QryUpdata(Parameters Param, OutValue Session, OutValue Output) throws Exception {
String mi = Param.P0;
//先写Log测试
LogUtils.WriteDebugLog("mi:" + mi + ",调用上传查询");
//返回的数据
List<CmdDto> cmdList = new ArrayList<>();
return Helper.Object2Json(cmdList);
}
/**
* 设置上传指令执行状态
*
* @param Param
* @param Session
* @param Output
* @return
* @throws Exception
*/
public String SetQryStatus(Parameters Param, OutValue Session, OutValue Output) throws Exception {
String mi = Param.P0;
String setStatusKey = Param.P1;
//先写Log测试
LogUtils.WriteDebugLog("mi:" + mi + ",setStatusKey:" + setStatusKey + "设置状态");
return "";
}
}
效果
这就是第二个仪器接口演示