Linux上位机 C++与三菱上位机MC 3E 二进制通信协议实例,源码。国产系统麒麟上位机与PLC通信实战实例,快速上手国产化系统的统信UOS上位机 硬核国产化 自主可控上位机 Deepin+Qt

#ifndef MCBINARYTCP_H
#define MCBINARYTCP_H

#include <iostream>
#include <string>
#include <sstream>
#include <vector>
#include <iomanip>
#include <sstream>
#include <chrono>
#include <thread>
#include <stdio.h>
#include <algorithm>
#include <QObject>
#include <QTcpSocket>
#include <QHostAddress>

using namespace std;

class McBinaryTCP
{

public:
    McBinaryTCP(const string& server, uint16_t port);
    ~McBinaryTCP();
    void Close();
    bool isConnected();
    bool connectToServer();
    bool Tsend(const string& message);
    bool sendHex(const vector<uint8_t>& bytesToSend);
    string receive();
    string receiveHex();
    string ReadPLC(uint16_t intPlcAddress, uint16_t intCount, const string& strAddressType,const string& indexBit);
    vector<int> ReadWordToListInt(const string& key, uint16_t intCount);
    vector<int> ReadWordToListShort(const string& key, uint16_t intCount);
    vector<string> ReadWordListstring(const string& key, uint16_t intCount);
    vector<string> ReadBitToListstring(const string& key, uint16_t intCount);
    vector<bool> ReadBitToList(const string& key, uint16_t intCount);
    bool WritePlc(uint16_t intPlcAddress, const string&  strValue, const string&  strAddressType);
    bool WritePlcBit(uint16_t intPlcAddress, const string&  strValue, const string&  strAddressType, const string&  index);
    bool WritePlcFormListBit(const string& key, const vector<int>& list);
    bool WritePlcFormListInt(const string& key, const vector<int>& list);
    bool WritePlcFormListShort(const string& key, const vector<int>& list);


private:
    vector<uint8_t> hexStringToBytes(const string& hexStr);
    uint16_t StringToUShort(const string& str);
    string decimalToHex(int decimal) ;
    string PadLeft(const string& input, size_t length, char paddingChar = ' ') ;
    string hexReversal(const string& key);
    string server_;
    uint16_t port_;
    QTcpSocket qtsocket;
    string DA1=""; //plc的IP后缀信息
    bool firstconnect=false;

};

#endif // FINSTCP_H

源码下载https://8ma.co/res/ZUDR1EJJ

在国产化浪潮下,Deepin系统作为国产操作系统标杆,为工业控制领域提供了稳定可靠的部署平台。本文以Qt C++框架开发欧姆龙PLC上位机通信为例,阐述国产化适配实践。

核心实现:上位机与三菱PLC通信时,可以使用3E二进制协议。这是一种专用的通信协议,用于实现上位机软件与三菱PLC之间的数据交换。通过这种协议,上位机可以发送指令给PLC,同时从PLC读取所需的数据,从而实现对工业自动化过程的监控和控制。这种协议的应用可以提高通信的效率和可靠性,确保工业自动化系统的稳定运行。

国产化亮点:Deepin对Qt5/6的完美兼容,使跨平台编译零成本;其内核级实时性优化,显著降低通信抖动。实测在鲲鹏CPU架构下,数据刷新周期稳定在10ms以内,满足严苛的产线节拍要求。

开发建议:封装三菱MC3E协议库为独立模块,利用Qt信号槽机制实现异步通信,避免界面卡顿。通过qmake条件编译适配不同国产平台,一套代码即可覆盖龙芯、飞腾等架构,助力工业软件自主可控。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值