什么是上位机_上位机软件介绍

什么是上位机
上位机是一台可以发出特定操控命令的计算机,通过操作预先设定好的命令,将命令传递给下位机,通过下位机来控制设备完成各项操作(应用最多的地方如:工业、水利、供电部门、交通等方面)。上位机都有特定的编程,有专门的开发系统,或以上是已经规定好任务,只能按特定的任务进行操作。简单说上位机就是命令的下达者,而下位机则是命令的执行者。
上位机软件介绍
下面介绍一种软件:物联网应用中收集感知节点信息,进行显示,控制的应用控制台。此软件主要有两部分组成,数据收发部分和显示部分
1、上位机在系统中的位置:处于网络层中,与嵌入式网关通过网线相连。实际应用时是放置在实验室的老师工作台上,供实验室的老师使用。
2、上位机的功能:此软件实时监视实验实中每个实验台的状况,包括上电或断电状态,实验台是否发出了警告,是否发出了求助信号,并对这些信号做出应答,还控制led屏的文字显示。
3、上位机的设计实现: 此软件主要有两部分组成,数据收发部分和显示部分。数据收发指的是和嵌入式网关的数据收发。两者是通过网线连接的,所以应用的是tcp/ip 的socket 套接字编程,嵌入式网关的设计中已经提到过,它在和上位机通信中是作为服务器的,那么上位机就是作为连接发起方。为了能保证网络连接的稳定性,我们把socket读写的程序代码放在了try{} catch(){} 块中,一旦网络连接不正常,就会捕获到该异常,从而关闭程序。
4、关键代码如下:
private void readfromarm()
{
byte[] buffertocheck = new byte[1];
int bytesize = 0;
do
{
byte[] bufferofread = new byte[1024];
try { bytesize = stream.read(bufferofread, 0, bufferofread.length); }
catch (exception ex) { connection = indicator.unconnected; messagebox.show(连接中断,程序将退出。); application.exit(); read.abort(); }
//messagebox.show(bitconverter.tostring(bufferofread));
byte[] buffertochecktemp = buffertocheck;
buffertocheck = new byte[buffertochecktemp.length + bytesize];
array.copy(buffertochecktemp, 0, buffertocheck, 0, buffertochecktemp.length);
array.copy(bufferofread, 0, buffertocheck, buffertochecktemp.length, bytesize);
int index_1, index_2;
while (check7e(buffertocheck, out index_1, out index_2))
{
byte[] buffertodecode = new byte[index_2 + 1 - index_1];
array.copy(buffertocheck, index_1, buffertodecode, 0, index_2 + 1 - index_1);
byte[] bufferofdecode = ppp.decode(buffertodecode);
//messagebox.show(bitconverter.tostring(bufferofdecode));
if (bufferofdecode[0] == bufferofdecode.length && checksum(bufferofdecode))//保证从arm来的帧是正确的
{
byte[] zuohao = new byte[2];
int subindex = 1, index = bufferofdecode[1]*256+bufferofdecode[2]-1;
string status=null;
switch (bufferofdecode[3])//分别处理从arm来的帧
{
case power_on://从arm来的上电状态
status = 上电;
subindex = 1;
break;
case power_off://从arm来的断电状态
status = 断电;
subindex = 1;
break;
case abnormal://从arm来的异常状态
status = 异常;
subindex = 1;
break;
case warning://从arm来的警告信号
status = 有;
subindex = 2;
break;
case need_help://从arm来的求救信号
status = 有;
subindex = 3;
break;
}
if (0 <= index && index <= 49)
{
listview1.items[index].subitems[subindex].text = status;
if (status == 异常 || status == 有)
listview1.items[index].subitems[subindex].forecolor = color.red;
else
listview1.items[index].subitems[subindex].forecolor = color.black;
}
}
int newlength = buffertocheck.length - 1 - index_2;
if (newlength == 0)
{
buffertocheck = new byte[1];
}
else
{
buffertochecktemp = buffertocheck;
buffertocheck = new byte[newlength];
array.copy(buffertochecktemp, index_2 + 1, buffertocheck, 0, newlength);
}
}
} while (connection == indicator.connected);
}
///
/// 向arm发送
///
/// 座号 2字节
/// 命令字 1字节
public void writetoarm(byte[] zuohao, byte mingling)
{
if (connection == indicator.connected)//在与arm保持连接的情况下可写
{
byte[] frame = new byte[5];
frame[0] = 0x05;
array.copy(zuohao, 0, frame, 1, 2);
frame[3] = mingling;
byte temp = 0;
foreach (byte item in frame)
temp += item;
frame[4] = (byte)(0 - temp);
byte[] frametosend = ppp.encode(frame);
console.writeline(bitconverter.tostring(frametosend));
try { stream.write(frametosend, 0, frametosend.length); }
catch (exception ex) { }
}
}
///
/// 向arm发送
///
/// 座号 2字节
/// 命令字加asc码 n字节
public void writetoarm(byte[] zuohao, byte[] minglingandasc)
{
if (connection == indicator.connected)//在与arm保持连接的情况下可写
{
byte[] frame = new byte[4+minglingandasc.length];
frame[0] = (byte)frame.length;
array.copy(zuohao, 0, frame, 1, 2);
array.copy(minglingandasc,0,frame,3,minglingandasc.length);
byte temp = 0;
foreach (byte item in frame)
temp += item;
frame[frame.length-1] = (byte)(0 - temp);
byte[] frametosend = ppp.encode(frame);
console.writeline(bitconverter.tostring(frametosend));
try { stream.write(frametosend, 0, frametosend.length); }
catch (exception ex) { }
}
}
另外数据收发还需要协议,和嵌入式网关通信的指令和协议定制如下:
因此数据量较少,协议也就比较简单,此协议在发送接收时用ppp封装。显示部分使用c#编写的运行于windows .net framework 上的窗体应用程序,根据实际需求,对每个实验台状态的显示使用listview控件实现,当出现异常情况,或实验台出现警告、求助信号时,listview的相应字段文字会通过改变颜色来提醒监视人员,监视人员还可以通过一个文字发送窗体来向led屏发送要显示的文字。总之界面清晰直观,简便易用。

Omniverse 资讯速递 | 行业动态、应用案例、合成数据生成系列视频等你来解锁!
阀门制造和产品质量发展处于快速追赶阶段,企业经营效益相对较好
电子产业向更智能化系统转型_两个方面详细解析
微星MEGX399CREATION创世板评测 供电方面简直就是地表最强
指纹密码锁安全性能高低,怎么区分?
什么是上位机_上位机软件介绍
多用户电表的作用和用途
SNR G106.3+2.7成为银河系候选的“拍电子伏特宇宙线加速器”
行业 | 英特尔已经计划出售基带芯片业务,但苹果已放弃?
乐华车间工位机数字化工厂的应用
中国联通与贵州人民政府签署达成战略合作伙伴
晶圆代工需求热度上涨,芯片产能持续爆满
HarmonyOS应用开发-module名字冲突解决方案
Andon系统按钮拉绳盒的规格和定制要点
尼得科与瑞萨电子合作开发新一代电动汽车用电驱系统E-Axle的半导体解决方案
HP8152A好货靓价HP8152A光功率计
python中怎么使用HTTP代理
亚马逊在英国成立无人驾驶配送技术团队
OpenHarmony高校技术俱乐部计划发布
国产手机选哪个品牌?华为p10闪存门了!小米6重启门了!然而oppo却置身事外咯