電泳EPLAY串口傳輸的圖形數據表示是4位表示一個Y座標。把空格去掉,按Y座標畫折線圖就行。(知道4位一個Y就簡單了直接是十進制額)
數據示例(按4個字符處理一個Y座標)
/s testStr=" 2 0 0 1 3 4 6 7 8 9 12 14 17 19 24 32 43 57 73 93 124 168 228 311 417 550 708 891109112991505169618621990207321032080200618851725153713311119 914 724 556 412 297 209 146 102 73 57 49 51 57 66 80 98 124 158 199 250 315 398 509 654 8411073134716612007236627163028327734433510347333393124284825342202186715451249 992 775 599 456 347 264 205 165 137 116 103 97 98 107 120 137 157 182 215 259 319 400 510 652 830104212801534179620572300251026672753276126892546234721051841156712971040 805 600 432 303 210 148 108 84 69 62 60 63 66 69 68 64 60 60 68 86 115 158 214 287 378 488 617 764 9261092125013871488154415491503140812741112 937 766 609 473 362 276 213 168 137 120 113 113 116 125 138 157 177 202 232 269 314 371 444 539 661 817101312501532185322102589297133323645388640404094404538903640331129242504207716691299 982 722 516 361 250 176 129 101 84 71 62 52 45 38 35 32 31 30 30 30 31 32 35 37 38 37 35 31 28 24 21 20 21 23 5 0 53 97 140 179 233"
//s datastr=testStr
//s data=""
s ystr=""
f i=1:4:($l(datastr)-20) d
.s curNum=$REPLACE($e(datastr,i,i+3)," ","")
.//s data=data_$lb(+curNum)
.i $l(ystr) s ystr=ystr_"^"_(curNum)
.e s ystr=ystr_(curNum)
然後按標準畫折線圖就OK了
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using LIS.BLL.ImageCore;
using System.Drawing;
using System.Data;
using System.IO;
using System.Drawing.Drawing2D;
namespace LIS.Mach.ImageDeal
{
///<summary NoteObject="Class">
/// [功能描述:EPALY電泳畫折線圖] <para/>
/// [創建者:zlz] <para/>
/// [創建時間:2018年08月15日] <para/>
///<說明>
/// [說明:[功能描述:EPALY電泳畫折線圖]<para/>
///</說明>
///<修改記錄>
/// [修改時間:本次修改時間]<para/>
/// [修改內容:本次修改內容]<para/>
///</修改記錄>
///<修改記錄>
/// [修改時間:本次修改時間]<para/>
/// [修改內容:本次修改內容]<para/>
/// M端觸發代碼,其他的和監聽程序一樣
/// s retObj=##Class(wbsLisMsgAsyncHandler.LISMsg.wbsLisDrawImageAsyncHandlerSoap).%New()
/// s ret=retObj.DrawImage(epis,ystr,mi,"MI.MIFEPALY","-1","","LIS.Mach.ImageDeal.ImageDealEPALY,LIS.Mach.ImageDeal")
///</修改記錄>
///</summary>
public class ImageDealEPALY : BaseDeal, IDrawImage
{
/// <summary>
/// 繪圖方法
/// </summary>
/// <param name="epis">流水號</param>
/// <param name="result">結果</param>
/// <param name="machID">儀器ID</param>
/// <param name="dealProcess">處理M</param>
/// <param name="index">-1認爲傳到最後</param>
/// <param name="otherPara">其他參數</param>
/// <param name="dealClass">C#處理類格式:類全名,不帶後綴的動態庫名</param>
/// <returns>是否成功</returns>
public bool DrawImage(string epis, string result, string machID, string dealProcess, string index, string otherPara, string dealClass)
{
string imgTmpPath = "";
try
{
//分割得到數據
string[] dataArr = result.Split('^');
List<double> ddata = new List<double>();
double maxY = 0;
foreach (var d in dataArr)
{
if (d == "")
{
continue;
}
double curd = Convert.ToDouble(d);
if (maxY < curd)
{
maxY = curd;
}
ddata.Add(curd);
}
bool isDrawColor = false;
if (otherPara == "1")
{
isDrawColor = true;
}
double width = ddata.Count;
double height = 300;
//x的最小偏移量
double xmin = width / ddata.Count;
//y的最小偏移量
double ymin = (height - 10) / maxY;
Bitmap img = new Bitmap(Convert.ToInt32(width), Convert.ToInt32(height));
//畫縱座標
Graphics g = Graphics.FromImage(img);
g.SmoothingMode = SmoothingMode.AntiAlias;
g.Clear(Color.White);
Pen pen = new Pen(Color.Black);
Pen penYellow = new Pen(Color.Yellow);
penYellow.Width = 2;
Pen penred = new Pen(Color.Red);
pen.Width = 1;
g.DrawLine(pen, 2, Convert.ToInt32(height - 2), Convert.ToInt32(width), Convert.ToInt32(height - 2));
g.DrawLine(pen, 2, Convert.ToInt32(height - 2), 1, 5);
for (int i = 1; i < ddata.Count; i++)
{
if (isDrawColor)
{
g.DrawLine(penred, Convert.ToInt32((i) * xmin), Convert.ToInt32(height), Convert.ToInt32((i) * xmin), Convert.ToInt32(height - ddata[i] * ymin));
}
if (i < ddata.Count - 1)
{
//捕獲波谷
if (ddata[i - 1] > ddata[i] && ddata[i + 1] > ddata[i])
{
g.DrawLine(penYellow, Convert.ToInt32((i) * xmin), Convert.ToInt32(height - 13), Convert.ToInt32((i) * xmin), Convert.ToInt32(height));
}
}
g.DrawLine(pen, Convert.ToInt32((i - 1) * xmin), Convert.ToInt32(height - ddata[i - 1] * ymin), Convert.ToInt32((i) * xmin), Convert.ToInt32(height - ddata[i] * ymin));
}
//判斷C盤trak是否存在
string tmpPath = @"C:\TRAK\TmpMach";
if (!Directory.Exists("C:\\TRAK"))
{
//新建文件夾
Directory.CreateDirectory("C:\\TRAK");
}
if (!Directory.Exists(tmpPath))
{
//新建文件夾
Directory.CreateDirectory(tmpPath);
}
if (File.Exists(tmpPath + "\\" + epis + ".bmp"))
{
File.Delete(tmpPath + "\\" + epis + ".bmp");
}
imgTmpPath = tmpPath + "\\" + machID + "-" + epis + ".bmp";
img.Save(imgTmpPath);
img.Dispose();
string ftpPath = "";
FtpService ftp = GetFtpHelper(machID, dealProcess, out ftpPath);
////上傳圖片
ftp.Upload(imgTmpPath);
//保存圖片
SaveImg(machID, epis, "SerumP", ftpPath.Split('^')[3] + machID + "-" + epis + ".bmp", dealProcess);
File.Delete(imgTmpPath);
return true;
}
catch (Exception ex)
{
LIS.Core.Util.LogUtils.WriteExceptionLog("繪製EPALY電泳圖發生錯誤", ex);
if (imgTmpPath!=""&&File.Exists(imgTmpPath))
{
File.Delete(imgTmpPath);
}
}
return false;
}
}
}
效果