본문으로 건너뛰기

Port Learning Guide

Table of Contents

  1. Overview
  2. Creating Port Projects
  3. Entry System
  4. Enum Definitions
  5. Rule System

Overview

Port operates by reflecting messages in the most recently updated repository. This quick start guide will help you understand how to create, configure, and manage Port projects effectively.

Port provides a comprehensive ecosystem for:

FeatureDescription
Entry-based CommunicationStructured data exchange between components
Package IntegrationModular architecture with reusable components
Real-time MonitoringLive project status and logging capabilities
Remote ManagementSSH and web-based administration
IoT IntegrationMQTT protocol support for device communication

Creating Port Projects

Project Structure Overview

Port projects are organized hierarchically with a clear folder structure:

ComponentDescription
Root FolderContains project configuration and *.enum files
Category FoldersOrganize messages by functional areas
Page FilesIndividual *.page files defining entry

Repository Setup

The Port project structure is simple and straightforward. Follow these steps to create your first project:

  1. Create Project Directory: Start with a dedicated project folder
  2. Initialize Project: Use port new [project-name] to generate project files
  3. Add Category: Create sub-folders for message organization
  4. Define Messages: Add *.page files to group folders
  5. Configure Types: Specify text, num, and enum data types
  6. Deploy: Use port push to store project configuration

!!! tip "Repository Naming Rules" Repository names cannot contain special characters and must follow operating system directory naming conventions.

Creating a New Project

Create Project

Command:

port new [project-name]

Category Management

Categorys serve as logical containers for related messages. Each group can contain multiple message files, enabling organized and abstracted message management.

Adding Categorys

Add Category

Benefits of Categorys:

BenefitDescription
OrganizationLogical separation of message types
MaintainabilityEasier to locate and edit related messages
ScalabilitySupport for large projects with many messages
AbstractionSimplified management of complex message relationships

Sample Project Structure

Project Structure

Download Sample: Download Sample Project

Entry System

Entry Definition Syntax

Messages are the core communication units in Port. Each message is defined using a specific syntax:

[key] [datatype] [option...]

Components:

ComponentDescription
[key]Unique identifier within the message group
[datatype]Data type specification (text, num, enum)
[option...]Additional attributes and configurations

Data Types

Port supports three primary data types for message definitions:

NameRangeDescription
char0~255Fixed-length string type with maximum 255 characters for text storage
num-1.7e+308 ~ +1.7e+308Floating-point type supporting wide range of decimal values
enum0 ~ 65535User-defined fixed list from .enum files with efficient storage

Entry Attributes

Attributes provide additional functionality and behavior for messages:

AttributeDescription
pkgReal-time synchronization with external libraries (see package documentation)
backupAutomatic database backup with restore on application restart
propertyCustom property specifications for message configuration
ruleValue validation and management rules
loggingAutomatic logging support for message operations

!!! warning "Special Characters" Message documents should not use special characters in identifiers.

Entry Examples

BulbOnOff enum.OffOn pkg:Bulb1.OffOn
RoomTemp1 num pkg:Heater1.Temp property:{"MIN":0,"MAX":300,"Arguments":"C"}
RoomTemp2 num pkg:Heater1.Temp property:{"MIN":0,"MAX":300,"Arguments":"F"}

Explanation:

VariableTypeDescription
BulbOnOffEnumEnum-based control linked to Bulb1 package
RoomTemp1NumericNumeric temperature in Celsius with validation range
RoomTemp2NumericNumeric temperature in Fahrenheit with validation range

Enum Definitions

Enum Syntax

Enums provide a way to define fixed sets of named values, improving code readability and reducing errors.

Format:

[key] [item-name:number_key] [item-name:number_key] ...

Components:

ComponentDescription
[key]Unique enum identifier
[item-name]Descriptive name for enum value
[number_key]Numeric value associated with the item

Enum Benefits

Enums are particularly useful for:

Use CaseDescription
Fixed Value SetsDays of the week, months, status codes
Code ClaritySelf-documenting code with named constants
Error PreventionType safety instead of raw numeric values
MaintenanceCentralized value management

Enum Examples

TFalse True:0 False:1
FTrue False:0 True:1
OffOn Off:0 On:1
OnOff On:0 Off:1

Use Cases:

Use CaseDescription
Boolean StatesTrue/False, On/Off toggles
Status IndicatorsActive/Inactive, Enabled/Disabled
Mode SelectionManual/Automatic, Local/Remote

Rule System

Rule Definition

Rules provide conditional logic for message validation and automatic actions. They are defined in *.rule files within group folders.

SetTrigger Rules

SetTrigger rules control user modification permissions through conditional validation.

Syntax

set("<Input Condition>", "<Validation Condition>");

Components:

ComponentDescription
Input ConditionLogical expression specifying the input to validate
Validation ConditionExpression that must evaluate to true for acceptance

SetTrigger Examples

set("room1.BulbOnOff==Off", "(room1.RoomTemp1>=20)&&(room2.RoomTemp2>=20)")
set("room1.RoomTemp2>=30", "room2.RoomTemp2>=5")

GetTrigger Rules

GetTrigger rules execute automatic actions when specified conditions are met.

Syntax

get("<Trigger Condition>", "<Action Script>");

Components:

ComponentDescription
Trigger ConditionBoolean expression for condition evaluation
Action ScriptInstructions executed when condition is true

GetTrigger Examples

get("(room1.RoomTemp1>=0)&&(room2.RoomTemp2>=0)", "room1.BulbOnOff=Off;room2.BulbOnOff=Off;")

Rule Benefits

BenefitDescription
ValidationEnforce business logic and data integrity
AutomationTrigger actions based on system state
SafetyPrevent invalid configurations
EfficiencyReduce manual intervention needs