Engee documentation

COM software management

This page contains all the available CAN software control functions in Engee.

To work with COM software control functions in Engee, install the hardware support package as specified in article. After that, perform:

using Main.EngeeDeviceManager.Devices.COM

Step-by-step example of working with COM (virtual ports)

For testing without a physical device, it is convenient to use virtual COM ports via socat. Set up a pair of related pseudo terminals:

socat -d -d PTY,link=/tmp/ttyV0,b9600 PTY,link=/tmp/ttyV1,b9600 &

Now /tmp/ttyV0 and /tmp/ttyV1 — virtual «The jumper»: everything that is written to one port is read from the other.

Creating a COM object

com = COM.Com()

_ Getting a list of ports_

ports = COM.get_devices(com)
println("Доступные порты: $ports")

initialization and opening of ports

port_send = "/tmp/ttyV0"
port_recv = "/tmp/ttyV1"

# Инициализация с идентичными параметрами
COM.init(com, port_send, 9600, "EIGHT_BITS", "PARITY_NONE", "STOPBITS_ONE")
COM.init(com, port_recv, 9600, "EIGHT_BITS", "PARITY_NONE", "STOPBITS_ONE")

# Открытие портов
COM.open(com, port_send)
COM.open(com, port_recv)

_ Data exchange_

data = UInt8[]

for i in 1:20
    push!(data, i)

    # Отправка накопленных байт
    sent = COM.transmit(com, port_send, data)
    println("Отправлено $sent байт: $data")

    # Прием такого же количества байт
    received = COM.receive(com, port_recv, length(data))
    println("Получено байт: $received")

    @assert data == received
end

working with non-standard parameters

Example of speed connection 19200, 6 data bit, parity even, 2 stop bits:

COM.init(com, "/tmp/ttyV2", 19200, "SIX_BITS", "PARITY_EVEN", "STOPBITS_TWO")
COM.open(com, "/tmp/ttyV2")

data = UInt8[0x01, 0x02, 0x03]
COM.transmit(com, "/tmp/ttyV2", data)
received = COM.receive(com, "/tmp/ttyV3", length(data))

The completion of the work

COM.close(com, port_send)
COM.close(com, port_recv)
println("Порты закрыты")

Features

  • Operating procedure: initopentransmit/receiveclose. init it only saves the configuration, the real opening takes place in open.

  • COM.receive — blocking call: the method waits until the port buffer has accumulated bytes_to_read bytes or the internal timeout will not expire.

  • A single COM object can manage multiple ports: initialize, open and close them by name.

  • COM.transmit returns the number of bytes actually sent. In normal operation, it is equal to the length message.