Skip to content

Python submit_command() seemingly fails to send anything #322

Description

@mpfj

Describe the bug
I have modified the cp_app.py code slightly to:

  1. Work under Windows (using a USB-Serial converter on COM3)
  2. Remove the "secure" channel
  3. Send a Text command (rather than an LED command).

My PD has a display onto which I am showing all the raw RX data from the CP.
I get regular Poll messages but never any Text messages.

My Python code is show below.
Any clues as to what I might be doing wrong?

import serial
from osdp import *

class SerialChannel(Channel):
    def __init__(self, device: str, speed: int = 115200):
        self.dev = serial.Serial(device, speed, timeout=0)

    def read(self, max_read: int) -> bytes:
        return self.dev.read(max_read)

    def write(self, data: bytes) -> int:
        return self.dev.write(data)

    def flush(self):
        self.dev.flush()

    def __del__(self):
        self.dev.close()
        
channel = SerialChannel("COM3", 9600)

# Setting scbk=None puts the PD in install mode; KeyStore.gen_key() provisions
# a random Secure Channel Base Key (SCBK) instead.
pd_info = [
    PDInfo(0, channel, scbk=None),
]

cp = ControlPanel(pd_info, log_level=LogLevel.Debug)
cp.start()
cp.sc_wait_all()   # wait until the secure channel is established

text_cmd = {
    'command': Command.Text,
    'reader': 0,
    'control_code': 2,
    'offset_row': 3,
    'offset_col': 2,
    'temp_time': 0,
    'data': "Hello world!",
}

count = 0
while True:
    count += 1
    print(f"sent # {count}")
    cp.submit_command(pd_info[0].address, text_cmd)

    # Pull any event the PD reported
    event = cp.get_event(pd_info[0].address, timeout=1)
    if event:
        print(f"CP: Received event {event}")

Expected behavior
I would expect a Text message to be send every second (or so).

Observed behavior
I only get Poll messages

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions