Git Product home page Git Product logo

pysemisecs's People

Contributors

kenta-shimizu avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

pysemisecs's Issues

active.open_and_wait_until_communicating return False

 active.open()
r = active.open_and_wait_until_communicating(5)
active.add_recv_all_msg_listener(self._recv_all_msg_listener)
# self._send_hand_shake(active)
if not r:
    get_logger().warn('connect open_and_wait_until_communicating return false')

The method open_and_wait_until_communicating returns false. What is the general reason for this

CallbackQueuing invalid syntax

This is my first time entering an issue on GitHub, so please excuse my lack of experience. I tried to use the secs.py code in the simple directory. On line 2362 I get an invalid syntax for CallbackQueuing(self._rpm_cb) as pmq. PyCharm is suggesting that CallbackQueuing doesn't specify the return value of the CallbackQueuing init method?

trying to create simulator using this package, which should run in two different window

Hi, @kenta-shimizu

First of all thank you for creating this project. I am trying to create a very simple simulator using tkinter and your package. I have written this code, but I want to know what should be change so that it should be send and reply message?

I know it should reply to the message but I am not figure out in the code how should it would reply.

raise HsmsSsTimeoutT3Error("HsmsSs-Timeout-T3", msg)
secs.hsmssscommunicator.HsmsSsTimeoutT3Error: HsmsSsTimeoutT3Error('HsmsSs-Timeout-T3',[00 0A|85 01|00 00|00 00 00 02])
import tkinter as tk
from tkinter import ttk
import threading
import secs

class CommunicationApp:
    def __init__(self, root):
        self.root = root
        root.title("Communication App")

        self.active_mode = tk.IntVar()
        self.active_mode.set(1)  # Default to Active mode

        self.device_active = None
        self.device_passive = None

        self.connect_button = ttk.Button(root, text="Connect", command=self.connect)
        self.disconnect_button = ttk.Button(root, text="Disconnect", command=self.disconnect)
        self.action_button = ttk.Button(root, text="Send/Reply", command=self.send_or_reply)

        self.connect_button.grid(row=0, column=0, padx=10, pady=10)
        self.disconnect_button.grid(row=0, column=1, padx=10, pady=10)
        self.action_button.grid(row=0, column=2, padx=10, pady=10)

        self.active_radio = ttk.Radiobutton(root, text="Active", variable=self.active_mode, value=1)
        self.passive_radio = ttk.Radiobutton(root, text="Passive", variable=self.active_mode, value=0)

        self.active_radio.grid(row=1, column=0, padx=10, pady=10)
        self.passive_radio.grid(row=1, column=1, padx=10, pady=10)

        self.output_text = tk.Text(root, height=10, width=40)
        self.output_text.grid(row=2, columnspan=3, padx=10, pady=10)

        self.receive_text = tk.Text(root, height=10, width=40)
        self.receive_text.grid(row=3, columnspan=3, padx=10, pady=10)

        # Create variables to store the received Primary-Message and active device
        self.received_primary_msg = None
        self.active_device = None

    def connect(self):
        if self.active_mode.get() == 1:
            self.device_active = secs.HsmsSsActiveCommunicator(
                ip_address="127.0.0.1",
                port=5000,
                session_id=10,
                is_equip=False,
                timeout_t3=45,
                timeout_t6=5,
                timeout_t7=10,
                timeout_t8=5,
                gem_mdln="MDLN-A",
                gem_softrev="000001",
                gem_clock_type=secs.ClockType.A16,
                name="hsms-active",
            )
            self.device_active.open()
            self.active_device = self.device_active
            self.active_device.add_recv_primary_msg_listener(self.recv_primary_msg)
        else:
            self.device_passive = secs.HsmsSsPassiveCommunicator(
                ip_address="127.0.0.1",
                port=5000,
                session_id=10,
                is_equip=True,
                timeout_t3=45,
                timeout_t6=5,
                timeout_t7=10,
                timeout_t8=5,
                gem_mdln="MDLN-A",
                gem_softrev="000001",
                gem_clock_type=secs.ClockType.A16,
                name="hsms-passive",
            )
            self.device_passive.open()
            self.active_device = self.device_passive
            self.active_device.add_communicate_listener(self._comm_listener)

        self.output_text.insert(tk.END, "Connected\n")

    def disconnect(self):
        if self.active_device:
            self.active_device.close()
            self.active_device = None

        self.output_text.insert(tk.END, "Disconnected\n")

    def send_or_reply(self):
        if self.active_mode.get() == 1:
            # Active mode: Send
            threading.Thread(target=self.send_primary_message).start()
        else:
            # Passive mode: Reply
            threading.Thread(target=self.send_reply_message).start()

    def send_primary_message(self):
        if self.active_device:
            # Send a Primary-Message
            primary_msg = self.active_device.send(
                strm=5,
                func=1,
                wbit=True,
                secs2body=("L", [("B", [0x81]), ("U2", [1001]), ("A", "ON FIRE")]),
            )

            # Store the Primary-Message
            self.received_primary_msg = primary_msg

            # Display the sent message in the output_text widget
            self.output_text.insert(tk.END, "Sent Primary-Message\n")

    def send_reply_message(self):
        if self.active_device and self.received_primary_msg:
            # Send a Reply-Message
            reply_msg = self.active_device.reply(
                primary=self.received_primary_msg,
                strm=5,
                func=2,
                wbit=False,
                secs2body=("B", [0x0]),
            )

            # Display the sent Reply-Message in the output_text widget
            self.output_text.insert(tk.END, "Sent Reply-Message\n")

    def recv_primary_msg(self, primary_msg, comm):
        # Handle received Primary-Message
        self.receive_text.insert(tk.END, f"Received Primary-Message: {primary_msg}\n")

    def _comm_listener(self, communicatable, comm):
        if communicatable:
            self.output_text.insert(tk.END, "Communicated\n")
        else:
            self.output_text.insert(tk.END, "Discommunicated\n")

if __name__ == "__main__":
    root = tk.Tk()
    app = CommunicationApp(root)
    root.mainloop()

Host/Tool Serial Communication Issue

I have been trying to figure out why my S1F3 polling class/function that runs every 1second was breaking while communicating with a tool that is running and sending events/alarms while it is running.
 
I discovered that while using the Secs1OnPySerialCommunicator that if the timing is just right and the tool and host both attempt to initiate a handshake with b'\x05'  at the same time the program doesn't handle it well.
 
Basically if tool has attempted to initiate a handshake by sending b'\x05' and that byte is in the buffer to be read, but the host around the same time tries to initiate its own handshake at the same time by sending b''x05' it breaks.
 
I am working on a solution by checking if there is anything to read in the buffer prior to trying to send anything.  If there is, then buffer that message and attempt to send it again after the host sends the b'\x06' after handling a message from the tool.
 
Maybe you have a more elegant or better solution idea? You can see some logs I recorded below. Near the end you can see where it broke.
 
s1f3Polling().s1f3_polling(db, tool_id)
send bytes:  b'\x05'
read bytes:  b'\x04'
b == self.__EOT:
send bytes:  b'4\x00\n\x81\x03\x80\x01\x00\x00\x00C\x01\ni\x02\x00\x14i\x02\x00\x15i\x02\x00!i\x02\x00#i\x02\x00$i\x02\x00%i\x02\x00&i\x02\x00)i\x02\x00i\x02\x00,\x06\xe6'
read bytes:  b'\x06\x05'
b == self.__ACK
b is not None
b == self.__ENQ
send bytes:  b'\x04'
read bytes:  b"6\x80\n\x01\x04\x80\x01\x00\x00\x00C\x01\ni\x02\x00\x0ei\x02\x00@i\x02\x00pi\x02'\xf8i\x02'\xf8i\x02 \x16i\x02 2i\x02\x00ei\x02&]q\x04\x00\x00\x00\xb5\n\xb7"
Send bytes ACK
send bytes:  b'\x06'
Polling function complete
 
 
s1f3Polling().s1f3_polling(db, tool_id)
send bytes:  b'\x05'
read bytes:  b'\x04'
b == self.__EOT:
send bytes:  b'4\x00\n\x81\x03\x80\x01\x00\x00\x00D\x01\ni\x02\x00\x14i\x02\x00\x15i\x02\x00!i\x02\x00#i\x02\x00$i\x02\x00%i\x02\x00&i\x02\x00)i\x02\x00
i\x02\x00,\x06\xe7'
read bytes:  b'\x06\x05'
b == self.__ACK
b is not None
b == self.__ENQ
send bytes:  b'\x04'
read bytes:  b"6\x80\n\x01\x04\x80\x01\x00\x00\x00D\x01\ni\x02\x00\x0ei\x02\x00@i\x02\x00pi\x02'\xf9i\x02'\xf9i\x02 %i\x02 Di\x02\x00li\x02&_q\x04\x00\x00\x00\xc3\n\xf2"
Send bytes ACK
send bytes:  b'\x06'
Polling function complete
 
read bytes:  b'\x05'
b is not None
b == self.__ENQ
send bytes:  b'\x04'
read bytes:  b'\xa1\x80\n\x06\t\x80\x01!\x006\xe5\x01\x04!\x01\x01A\x01 q\x04\x00\x01?\xf1\x01\x02\x01\x02A\x04EMES\x01\x01A(Chamb'
read bytes:  b'er Z process has started.   '
read bytes:  b'       \x01\x02A\rEVENT'
read bytes:  b' CONTEXT\x01\x05A\x10    '
read bytes:  b'            i\x02\x00\x06A\x10              '
read bytes:  b'  A\x08seceventA\x0c24'
read bytes:  b'0228093632"\n'
Send bytes ACK
send bytes:  b'\x06'
 
s1f3Polling().s1f3_polling(db, tool_id)
read bytes:  b'\x05'
send bytes:  b'\x05'
read bytes:  b'\x05'
read bytes:  b'\x05'
read bytes:  b'\x05'
read bytes:  b'\x05'
read bytes:  b'\x05'
read bytes:  b'\x05'
read bytes:  b'\x05'

How do I query a single-data body instead of an array

body =  ('U2', [1010])
response = active.send(1, 3, True,   body)

I need to send is single-data body rather than an array. I tried this, but it seemed wrong.

Traceback (most recent call last):
  File xxxxxxxxxxxxx/secs/hsmssscommunicator.py", line xx, in send
    raise HsmsSsTimeoutT3Error("HsmsSs-Timeout-T3", msg)
secs.hsmssscommunicator.HsmsSsTimeoutT3Error: HsmsSsTimeoutT3Error('HsmsSs-Timeout-T3',[00 00|81 03|00 00|00 00 00 04])

Large send_sml() string causes to go into an infinite loop

I am trying to implement a large send_sml() request that sends a large string over a serial connection. If I cut the string length down it works fine. But seems when it needs to split up the message over multiple blocks it breaks.

I do not know why.

example send.
Reply = send_sml(‘ S1F3 W <L<I2 20><I2 21><I2 22><I2 23><I2 24><I2 25><I2 26><I2 31><I2 32><I2 33><I2 35><I2 36><I2 37><I2 38><I2 41><I2 42><I2 44><I2 45><I2 46><I2 71><I2 72><I2 76><I2 79><I2 80><I2 81><I2 82><I2 83><I2 84><I2 85><I2 86><I2 87><I2 88><I2 89><I2 90><I2 91><I2 92><I2 93><I2 94><I2 100><I2 101><I2 102><I2 103><I2 150><I2 156><I2 160><I2 161><I2 162><I2 163><I2 164><I2 380><I2 381><I2 382><I2 383><I2 384><I2 385><I2 420><I2 421><I2 422><I2 423><I2 424><I2 425><I2 480>>.’)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.