Mobile and Embedded
2022.04.30 15:43

Qt로 작성된 iOS 앱에서 시리얼 통신

조회 수 9559 추천 수 0 댓글 0
?

단축키

Prev이전 문서

Next다음 문서

크게 작게 위로 아래로 댓글로 가기 인쇄 첨부
?

단축키

Prev이전 문서

Next다음 문서

크게 작게 위로 아래로 댓글로 가기 인쇄 첨부

Qt 로 작성된 iOS 에서 앱이 외부장치와 Serial 통신을 해본다.

 

일반적으로 크로스 플랫폼 프레임워크 애플리케이션은 iOS에서 외부장치와 시리얼 통신이 불가능하다. Apple 디바이스에서는 Apple에서 인증하고 MFi 배지가 있는 액세서리만 사용하고 독점 프로토콜(iAP2)과 소프트웨어로만 작동되게 했기 때문이다.

 

Redpark 의 Lightning Serial Cable은 RS-232 통신이 가능한 애플의 MFi 액세서리중 하나다. 함께 제공되는 SDK(라이브러리)는 External Accessory Framework의 관련된 세부 구현을 추상화하고 단순화하여 쉽게 앱을 개발할 수 있게 해준다. 따라서 Redpark 시리얼 케이블을 iPhone에 연결하고 Qt/C++로 작성하는 애플리케이션에서 Redpark 라이브러리를 링크하여 최대 115.2Kbps의 전송 속도로 다른 직렬 장치에 연결할 수 있다.

 

시리얼 케이블 구매와 SDK 및 샘플 프로젝트는 Redpark 웹사이트에서 얻을 수 있다. SDK는 Objective-C를 위해서도 제공되며 Objective-C코드에서 우리의 C++ 코드를 혼합할 수 있다. qmake는 “mm” 확장자를 컴파일러에게 이것이 Objective-C++ 파일임을 알려준다.

QMAKE_LFLAGS += -ObjC


....
OBJECTIVE_HEADERS += \
    IOSSerialPort.h \
...


OBJECTIVE_SOURCES += \
    ios/IOSSerialPort.mm \
...


기본적인 iOS 용 Qt 앱을 구축하는 방법에 대해서 다음 블로그를 참고하면 많은 도움이 된다.
https://appbus.wordpress.com/

 

테스트를 위해 아주 단순한 사용자 인터페이스를 구현한다.

스크린샷, 2022-04-29 오후 6.17.41.png

 

main.qml

import QtQuick 2.12
import QtQuick.Window 2.12
import QtQuick.Controls 2.12

Window {
    width: 640
    height: 480
    visible: true
    title: qsTr("Hello World")

    Connections {
        target: serial

        function onDebugMessage(message){
            info.append(message)
        }
    }

    Rectangle {
        anchors.fill: parent

        TextEdit {
            id: info
            anchors.top: parent.top
            anchors.topMargin: 20
            anchors.left: parent.left
            anchors.right: parent.right

            horizontalAlignment: Text.AlignLeft

            font.pixelSize: 20
        }

        Column {
            anchors.horizontalCenter: parent.horizontalCenter
            anchors.bottom: parent.bottom
            anchors.bottomMargin: 15
            spacing: 10

            Button{
                width: 200
                height: 50
                anchors.horizontalCenter: parent.horizontalCenter

                text: "Open"

                onClicked: {
                    serial.open()
                }
            }

            Button{
                width: 200
                height: 50
                anchors.horizontalCenter: parent.horizontalCenter

                text: "Send"

                onClicked: {
                    serial.send("Hello Makersweb.net")
                }
            }
        }
    }
}


serial 인스턴스의 클래스 구현은 Redpark 의 샘플 프로젝트 코드에서 많은 부분을 사용하며 실제 sendData 및 recvData를 호출하여 시리얼 포트를 통해 바이트를 보내거나 받을 수 있다.

#include "Serialdevice.h"
#include "IOSSerialPort.h"

#include <QDebug>

SerialDevice::SerialDevice(QObject *parent)
    : QObject{parent}
    , backend(new IOSSerialPort())
{
    connect(backend, &IOSSerialPort::receivedMessage, this, [&](QString msg){
        emit debugMessage(msg);
    });
}

SerialDevice::~SerialDevice()
{
    if(backend){
        backend->close();
        delete backend;
        backend = nullptr;
    }
}

void SerialDevice::open()
{
    backend->open();
}

void SerialDevice::send(const QString &text)
{
    if(text.isEmpty())
        return;

    backend->sendMessage(text);
}

 

데이터를 수신하면 바이트를 화면에 표시한다. Send 버튼을 누르면 문자열을 송신한다.

스크린샷, 2022-04-29 오후 6.18.39.png

 

Windows 터미널 에뮬레이터 측

rs232.png


  1. No Image notice

    Qt프로그래밍(QtQuick) Beginner를 위한 글 읽는 순서

    Date2019.01.05 CategoryQML and Qt Quick By운영자 Views131099
    read more
  2. No Image

    clazy 로 13개의 시그널, 슬롯 오류 해결

    Date2022.08.23 CategoryGeneral and Desktop Bymakersweb Views8527
    Read More
  3. No Image

    Qt 스마트 포인터 (QSharedPointer, QScopedPointer, QPointer)

    Date2022.08.18 CategoryC++ Class Bymakersweb Views5993
    Read More
  4. Qt 6.4에 추가될 Qt Quick 3D Physics

    Date2022.08.07 CategoryQt 6 Bymakersweb Views4519
    Read More
  5. No Image

    HTTPS URL을 연결할 때 SslHandshakeFailedError 오류

    Date2022.07.31 CategoryC++ Class Bymakersweb Views5379
    Read More
  6. No Image

    단일 인스턴스 Qt 응용 프로그램(Single-instance Application)

    Date2022.06.23 CategoryGeneral and Desktop Bymakersweb Views5972
    Read More
  7. Qt로 작성된 iOS 앱에서 시리얼 통신

    Date2022.04.30 CategoryMobile and Embedded Bymakersweb Views9559
    Read More
  8. No Image

    VirtualKeyboard 스타일 커스터 마이징

    Date2022.03.13 CategoryGeneral and Desktop Bymakersweb Views5770
    Read More
  9. No Image

    성능 고려 및 제안 사항

    Date2022.03.07 Bymakersweb Views4425
    Read More
  10. No Image

    Binding 타입으로 객체 속성 간 묶기

    Date2022.03.04 CategoryQML and Qt Quick Bymakersweb Views6719
    Read More
  11. No Image

    Qt Bluetooth Low Energy 개요

    Date2022.02.13 CategoryMobile and Embedded Bymakersweb Views5697
    Read More
  12. Qt Android 앱에 AdMob 배너달기

    Date2021.12.04 CategoryMobile and Embedded Bymakersweb Views3778
    Read More
  13. No Image

    Qt 6의 C++ 프로퍼티 바인딩 예제

    Date2021.11.01 CategoryQt 6 Bymakersweb Views6814
    Read More
  14. QML에서 앵커(anchors)로 위치 지정

    Date2021.10.05 CategoryQML and Qt Quick Bymakersweb Views10019
    Read More
  15. No Image

    안드로이드용 Qt 6.2

    Date2021.10.02 CategoryQt 6 Bymakersweb Views10111
    Read More
  16. Qt 응용프로그램에서 PDF 문서 렌더링

    Date2021.09.23 CategoryGeneral and Desktop Bymakersweb Views5627
    Read More
  17. QML에서 Websocket 서버와 통신

    Date2021.09.18 CategoryQML and Qt Quick Bymakersweb Views5381
    Read More
  18. No Image

    QML 코딩 규칙

    Date2021.09.05 CategoryQML and Qt Quick Bymakersweb Views9139
    Read More
  19. QML 에서 QR코드 생성

    Date2021.08.20 CategoryQML and Qt Quick Bymakersweb Views5330
    Read More
  20. No Image

    앱을 종료할 때 QML 바인딩 오류를 피하는 방법

    Date2021.08.08 CategoryQML and Qt Quick Bymakersweb Views9788
    Read More
  21. Qt 응용프로그램에서 Lottie Animation사용

    Date2021.05.30 CategoryQML and Qt Quick Bymakersweb Views5561
    Read More
Board Pagination Prev 1 2 3 4 5 9 Next
/ 9