QT反射内存读写操作

前言

反射内存技术适用于通过以太网、光纤通道或其他串行网络连接计算机或可编程逻辑控制器的应用,尤其在实时交互和高通信要求的系统中表现突出。虽然价格较高,但其易用性和性能优势带来了显著回报。反射内存能够在微秒级内将计算机的内存副本分发到整个网络,支持高达256台设备的连接,并实现数据透明地监测和复制,无需软件开销。具体型号如美国VMIPCI5565反射内存卡,采用PCI-Express接口,支持多通道光纤和高速数据传输,适用于大型计算机系统。使用时需确保良好的光纤连接,正确安装驱动和避免硬件冲突,以确保系统稳定性。总体而言,反射内存卡是解决大数据量和快速读写需求的优秀选择,适用于各种复杂应用场景。

作用

其他更详细功能参见:http://www.vertextron.com/VMIC5565.html

使用

库加载

win32: LIBS += -L$$PWD/3rdparty/rfm/lib/ -lrfm2gdll_stdc_32

INCLUDEPATH += $$PWD/3rdparty/rfm/inc
DEPENDPATH += $$PWD/3rdparty/rfm/dll

打开

int RfmApi::open()
{
    RFM2G_INT32    numDevice = 1; // 默认读取第一张卡

    QString devPath = QString::fromLocal8Bit("%1%2").arg(DEVICE_PREFIX).arg(numDevice);

    QByteArray ba = devPath.toLatin1();
    char* device = ba.data();
    RFM2G_STATUS result = RFM2gOpen( device, &m_Handle );

    if( result != RFM2G_SUCCESS )
    {
        return result;
    }

    return 0;
}

 

 

读取

int RfmApi::read(quint32 addr, QString &value, quint32 len)
{
    char buffer[256] = {0};

//    QByteArray bufferByte = {0};
//    bufferByte.resize(len);

    RFM2G_STATUS result = RFM2gRead( m_Handle, addr, buffer, len);

    if( result != RFM2G_SUCCESS ) return result;

    QByteArray byteData;


    for(int index = len - 1; index >= 0; index--)
    {
        byteData[len - 1 - index] = buffer[index];
    }

    quint32 intValue = byteData.toHex().toUInt(nullptr, 16);
    value = QString::number(intValue);

    return 0;
}

 

 

写入

int RfmApi::write(quint32 addr, const QString &value, int len)
{
    QByteArray byteData;
    quint32 uint8Value = value.toUInt();
    byteData.append(reinterpret_cast<const char *>(&uint8Value), sizeof(uint8Value));

    bool ok = true;

    RFM2G_STATUS result = RFM2gWrite( m_Handle, addr, (void *)byteData.data(), len );

    if( result == RFM2G_SUCCESS )
    {
        return 0;
    }

    return result;
}

 

 

关闭

void RfmApi::close()
{
    RFM2gClose(&m_Handle);

    if(m_Handle != nullptr)
    {
        delete m_Handle;
        m_Handle = nullptr;
    }
}

 总结

反射内存的开发起始相对容易,但是开发时总要翻看API文档,留下此文备用。

 

版权声明:
作者:小何
链接:https://ligo100.cn/houduanjishu/qt/642.html
来源:小何博客
文章版权归作者所有,未经允许请勿转载。

THE END
分享
二维码
打赏
< <上一篇
下一篇>>
文章目录
关闭
目 录