<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
</head>
<body dir="auto">
<div>Hi Benjamin,<br /><br /><div><blockquote type="cite">I’m sorry if this is a duplicate? I sent this earlier, but I don’t see it in the archives?<br /><br /></blockquote></div><br />I can see it in the archives along with this reply by glyph: http://twistedmatrix.com/pipermail/twisted-python/2014-October/028841.html<br /><br />—h</div>
<div><br />
Am 10.10.2014 03:33, schrieb Benjamin Schollnick:
<br /><br /></div>
<blockquote type="cite">
<div>
<meta http-equiv="Content-Type" content="text/html charset=windows-1252"/>
<body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;">
<div>I’m sorry if this is a duplicate? I sent this earlier,
but I don’t see it in the archives?</div>
<div><br/></div>
Folks,<br/>
<br/>
I’m writing an client using twisted, and I’m basing it off the
Poetry client from <a href="http://krondo.com/wp-content/uploads/2009/08/twisted-intro.html">http://krondo.com/wp-content/uploads/2009/08/twisted-intro.html</a>.<br/>
I am porting a previous pyserial based client, so I’m running into
new territory here.<br/>
<br/>
And it’s working fine, there are two “issues" that I am running
into.<br/>
<br/>
class WT_Protocol(Protocol):<br/>
<br/>
tag = ''<br/>
<br/>
def to_bytes(self, seq):<br/>
"""convert a sequence to
a bytes type"""<br/>
#<br/>
# from
pyserial.util<br/>
if isinstance(seq,
bytes):<br/>
return
seq<br/>
elif isinstance(seq,
bytearray):<br/>
return
bytes(seq)<br/>
elif isinstance(seq,
memoryview):<br/>
return
seq.tobytes()<br/>
else:<br/>
b
= bytearray()<br/>
for
item in seq:<br/>
b.append(item)
# this one handles int and str for our emulation and ints for
Python 3.x<br/>
return
bytes(b)<br/>
<br/>
def connectionMade(self):<br/>
print "Reseting the
network"<br/>
reset =
self.to_bytes(packets.network_reset() )<br/>
self.transport.write (
reset )<br/>
self.transport.write (
self.to_bytes(packets.Set_SiteCode(NodeID=255, SC1=0, SC2=0, SC3=0)
))<br/>
self.transport.write (
self.to_bytes(packets.Set_Gain_Packet(NodeID=255, Gain=1) ))
# high gain<br/>
self.transport.write (
self.to_bytes(packets.Set_Protocol_No_Nulls (NetworkID=0,
ReceiverID=0, NodeID=1) )) # high gain<br/>
time.sleep (.5)<br/>
<br/>
Now the client works right now, but I’m concerned that I can’t
figure out how to immediately read for a reply packet from the
server.<br/>
<br/>
For example, when I send the Set_SiteCode packet, I may receive a
reply. <br/>
<br/>
But how would that occur in the Twisted framework? In my
testing the dataReceived function is not being called, so I can’t
trap it there, plus I’m not sure how I would figure that
logic.<br/>
<br/>
Can anyone suggest a method to do this?<br/>
<br/>
The second question, as far as I can tell, isn’t very solvable.
I’d like to add a “Press Q to quit” type logic to the code.
But I don’t see a way to do this easily in twisted?
(platform unspecific, but it’s running Mac OS X / Unix right
now).<br/>
<br/>
<span class="Apple-tab-span" style="white-space: pre;"/>
<span class="Apple-tab-span" style="white-space: pre;"/>- Ben
</body>
</div>
</blockquote>
</body>
</html>