Reputation: 665
I am using python's pySerial library to communicate to a machine (lunar photometer if you must know). The machine has built in scenarios that I can call by sending specific hex values corresponding to those scenarios via a com/serial port. For example, the following code works fine for the "Park secnario" in the machine.
s.write('\x11') #s is my serial object, '\x11' is the command for the park senario
s.write('\x12') #'\x12' is the command for the TrackSun scenario
The above code works as intended and the machine responds to these commands. However, there is a bult in Goto scenario which is activated by the command '\x02'. My problem is that the goto command takes horizontal and vertical angles as parameters as well in this format GoTo where xxxx and yyyy are the two angles. How do i pass in those parameters in my s.write() command. I have tried: s.write('\x02 xxxx yyyy') which does not seem to work. Am i doing something wrong with passing the parameters? The command works fine when i use hyperterminal (in hex mode) with the following code:
8/1/2012 11:37:36.048 [TX] - 02 30 34 3B 30 3F 3A 3D 3B 03
8/1/2012 11:37:51.166 [RX] - 01
EDIT: Here is an example of the 'Park Scenario' command sent using hyperterminal, just in case.
8/1/2012 12:14:56.649 [TX] - 11
8/1/2012 12:15:07.962 [RX] - 01
Upvotes: 4
Views: 4791
Reputation: 6177
The following call to s.write()
would be the same as what you're sending on Hyperterminal:
s.write('\x02\x30\x34\x3b\x30\x3f\x3a\x3d\x3b\x03')
The general solution will depend on how your angles are encoded. I can't determine the encoding from your example.
Upvotes: 2