Giter VIP home page Giter VIP logo

apcups-serial-test's People

Stargazers

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

Watchers

 avatar  avatar  avatar  avatar  avatar

Forkers

klada

apcups-serial-test's Issues

'Set' commands

First of all, thank you for your amazing work, this really helps me.
I've got a bunch of smc1500-2u's in remote locations, where it's impossible to use usb communications.
So my solution is to use Moxa IA5150 and IA5450AI's for UPS monitoring and control.
First i've checked communications with powershute, seemd ok. And, this unit was produced 9-2014.
However, 'ups_status' string was strange, with nearly all possible statuses. 'Set' commands wasn't working - just nothing.
So my next step was to update ups firmware, this is what i ended up with:

fw_version_1 = UPS 12.0
fw_version_2 = MCU 06.0
fw_version_3 = UBL 01.4
fw_version_4 = MBL 06.0

Now statuses and such are ok, but SET's still silent.
The problem seems to be with thread and cli not synced - so when i set next_apc_msg, before it's executed, it's replaced with APC_CMD_NEXT, so nothing happens.
I have to mention my test rig is relatively beefy, maybe this is the problem.
So my hack is following:

  1. introduce new msg_q = set() variable
def __init__(self, serial_port,mode='serial'):
        super(ApcComm, self).__init__()
        self.s = serial_port
        self.state = CommState.INIT
        self.prev_state = CommState.INIT
        self.next_apc_msg = APC_CMD_NEXT#Next message to be sent to the UPS, for internal use
        self.msg_q = set()
        self.running = True
        self.daemon = True
        self.ups_state = {"comm_state": "offline"}
        self.mode = mode
  1. sleep while it's set
    def send_apc_msg(self, raw_msg):
        '''
        Schedule the next message to be sent.
        Blocks until the message is succesfully sent.
        '''
        if self.state is not CommState.MODE1:
            return False
        self.next_apc_msg = raw_msg
        self.msg_q.add(raw_msg.hex())
        while self.msg_q:
            time.sleep(APC_RCV_TIMEOUT)
        return True
  1. Write pending cli commands on next run, and unset q
            elif self.state == CommState.MODE1:
                '''
                Normal communication flow with UPS according to MODE1
                '''
                self.next_apc_msg = bytearray.fromhex(self.msg_q.pop()) if self.msg_q else self.next_apc_msg
                # if self.mode == 'serial':
                self.s.write(self.next_apc_msg)
                # else:
                #     pl = self.next_apc_msg
                #     if not isinstance(pl,bytes):
                #         pl=bytearray(pl)
                #     self.s.send(pl)
                rcv_data = self.receive_msg()

                if not self.msg_q:
                    self.next_apc_msg = APC_CMD_NEXT

Hope this helps.
p.s One more thing, in my case i need to change battery replacedates, so here's the code:

    def convert_from_datetime(self,value):
        ''' Convert days from 1 Jan. 2000 to bytearray'''
        return (datetime.datetime(*value) - datetime.datetime(2000,1,1)).days.to_bytes(length=2, byteorder='big', signed=False)
...
        elif args[0] == 'battery_replace_date':
                try:
                    if len(args) == 3:
                        args = [int(args[idx]) if idx in (1, 2) else i for idx,i in enumerate(args)]
                        if 1 <= args[1] <= 12 and 2000 <= args[2] <= 9999:
                            data = apccomm.convert_from_datetime([args[2], args[1], 1])
                        else:
                            raise
                    else:
                        raise
                except:
                    print("Bad data")
                    return
                else:
                    raw_msg = apccomm.create_msg_data(msg_id=0x47, offset=0, msg_data=data)
                    self.send_msg(raw_msg)

Request for Hex Dump

Hello!
I've done some more reverse engineering into the MicroLink protocol.
It seems like the first pages that are recieved from the UPS are a description of the data types and the data available for a specific UPS model.
I'm wondering if you have a hex dump of the pages from your UPS so I could look at it to try to figure out which types are what.
Thanks!
Max

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.