您当前的位置:五五电子网电子知识电子学习电脑-单片机-自控术语什么是上位机及位机软件介绍 正文
什么是上位机及位机软件介绍

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

点击数:7458 次   录入时间:03-04 11:49:30   整理:http://www.55dianzi.com   电脑-单片机-自控术语

    什么是上位机

    上位机是一台可以发出特定操控命令的计算机,通过操作预先设定好的命令,将命令传递给下位机,通过下位机来控制设备完成各项操作(应用最多的地方如:工业、水利、供电部门、交通等方面)。上位机都有特定的编程,有专门的开发系统,或以上是已经规定好任务,只能按特定的任务进行操作。简单说上位机就是命令的下达者,而下位机则是命令的执行者。

454

    上位机软件介绍

    下面介绍一种软件:物联网应用中收集感知节点信息,进行显示,控制的应用控制台。此软件主要有两部分组成,数据收发部分和显示部分

    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);

    }

    /// <summary>

    /// 向ARM发送

    /// </summary>

    /// <param name="Zuohao">座号 2字节</param>

    /// <param name="mingling">命令字 1字节</param>

    public void WriteToArm(byte[] Zuohao, byte mingling)

    {

    if (connection == Indicator.Connected)//在与ARM保持连接的情况下可写



www.55dianzi.com

    {

    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) { }

    }

    }

    /// <summary>

    /// 向ARM发送

    /// </summary>

    /// <param name="Zuohao">座号 2字节</param>

    /// <param name="mingling">命令字加ASC码 n字节</param>

    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) { }

    }

    }

    另外数据收发还需要协议,和嵌入式网关通信的指令和协议定制如下:

565
454

[1] [2]  下一页


本文关键字:软件  电脑-单片机-自控术语电子学习 - 电脑-单片机-自控术语

《什么是上位机及位机软件介绍》相关文章>>>