Thank you Jeff, Thanks a ton. Yes also about the flatnner. I am using the library given already. I am asked to use a pack command which i presume is what you try to explain me. I am long way to go, learning at a very slow pace. Maybe i should speed up of this delivery. The pack i am using is very similar to concatenation actually. Like i was explained example: "11100" +"1111" = 111001111 will be sent on serial. Please can you confirm me, python sends the big endian model. I mean MSB first. Thank you again Jeff.
Jeff Rush wrote: > > learningpython wrote: >> Sorry Senthil and all, >> I am sure, it's pretty easy but don't i am not able to catch it. In C, i >> just pass the & of the another structure in the structure element, some >> thing close. > > The equivalent to the & operator in C is just an object reference in > Python. > >> class Send_Msg_req(msg): >> def __init__(self): >> self.usr_mac =< Earlier class defined > >> self.msgtype = <blah> >> self.msgsize = <blah> >> self.order = ['usr_mac', >> 'msgtype ', >> 'msgsize '] > > so the line becomes just: > > self.usr.mac = usr_mac() > > where you declared usr_mac as a class in your prior email. If the > usr_mac() call needs arguments, provide them in the __init__ for > Send_MSG_req and pass them through: > > class Send_Msg_req(msg): > def __init__(self, a, b): > self.usr_mac = usr_mac(a, b) > self.msgtype = BV.Bit24.new() > > You haven't mentioned it but from here you'll need a flattener. From > your code I presume you have the idea for one already, in that: > >> self.msgtype = <blah> >> self.msgsize = <blah> >> self.order = ['usr_mac', >> 'msgtype ', >> 'msgsize '] > > at some point you have a method defined for the base 'msg' class that > uses the self.order list to construct the actual bitstream going out the > serial port from the various object attributes. So your BV.Bit24 class > has some method that gives you back the 24-bits that make it up. The > method that walks self.order and returns the raw bits is a flattener. > > Now with the declaring of self.usr_mac referencing an earlier class, you > just need to extend the idea of a flattener a bit further. So when you > call: > > msg = Send_Msg_req(MSG_A, 34) > serial.output(msg.flatten()) > > that .flatten method, upon encountering the self.usr_mac attribute, > calls the .flatten method of the usr_mac class and merges those bits > into the stream it is building for the Send_Msg_req class. > > This is why it is called a flattener -- it walks a tree of msg fragments > and constructs a flat sequence of bits making up a single message. > > Another example of the use of a flattener is the STAN DOM used in the > Nevow templating module used with the Twisted web framework. > > http://www.kieranholland.com/code/documentation/nevow-stan/ > > It takes an object graph of nested lists and attributes and returns a > flat string of HTML. It goes a bit further in that it has an extensible > registry of adapters for teaching the system to handle new kinds of > object graph nodes. > > -Jeff > _______________________________________________ > BangPypers mailing list > BangPypers@python.org > http://mail.python.org/mailman/listinfo/bangpypers > > -- View this message in context: http://www.nabble.com/calling-instance-of-the-other-class.-tp24145716p24174373.html Sent from the BangPypers - Bangalore Python Users Group mailing list archive at Nabble.com. _______________________________________________ BangPypers mailing list BangPypers@python.org http://mail.python.org/mailman/listinfo/bangpypers