By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
425,710 Members | 1,626 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 425,710 IT Pros & Developers. It's quick & easy.

pyserial to read from DS1615 temperature recorder chip

P: n/a
Hi there,

I am trying to use pyserial to read data from a temperature logger
device (T-logger). T-logger is based on the DS1615 temperature recorder
chip (Dallas Semiconductor). According to the DS1615 docs, writing to
the chip is performed one byte at a time. To read from the chip, one
must issue the "read page" command (33h), followed by the two-byte
address of the requested page (pages are 32 bytes long). After
receiving this, the DS1615 will send the data in a burst of (up to) 32
bytes. I can send data to the device, e.g. I can make the device's LED
blink with the test command (44h), but I am unable to read from it.
Connection parameters below are according to DS1615 docs.
>import serial
s = serial.Serial(0, baudrate=9600, bytesize=8, parity='N', stopbits=1, timeout=None)
s.write("\x33")
s.write("\x00")
s.write("\x00")
s.read() # "\x00" is returned here. This byte was already in the receive buffer before issueing the write commands.
s.read() # The interpreter is blocked here as there is nothing to read from the serial port.
I'm completely clueless and would really appreciate your comments. If
it helps, I can post a log from a serial port monitor captured when the
provided T-logger program pulls data from the device, as well as a log
when pyserial is used. And finally, this is a snippet of some basic
code found on the web, that is suppose to do what I want (untested by
me):

open "COM1:9600,N,8,1,CS0,DS0,CD0,ME,FE" as 1
print #1, chr$(&H33);chr$(&H00);chr$(&H00)
result$ = input$(34, #1)

Many thanks,

alex

Jul 24 '06 #1
Share this Question
Share on Google+
7 Replies


P: n/a
On 2006-07-24 14:03:30, al***************@yahoo.com wrote:
To read from the chip, one must issue the "read page" command (33h),
followed by the two-byte address of the requested page (pages are 32
bytes long). After receiving this, the DS1615 will send the data in a
burst of (up to) 32 bytes.
I'm not sure what you mean when you say it will send "up to" 32 bytes. If
you mean that it sends bytes until all existing values have been sent --
did you make sure you have any values in the buffer?

(Just asking the obvious... :)

Gerhard

Jul 24 '06 #2

P: n/a
On 2006-07-24, Gerhard Fiedler <ge*****@gmail.comwrote:
On 2006-07-24 14:03:30, al***************@yahoo.com wrote:
>To read from the chip, one must issue the "read page" command (33h),
followed by the two-byte address of the requested page (pages are 32
bytes long). After receiving this, the DS1615 will send the data in a
burst of (up to) 32 bytes.

I'm not sure what you mean when you say it will send "up to" 32 bytes.
Registers are in 32-byte pages. If you request register N, the
device sends register N followed by the remainder of the
32-byte page that contains address N. If you request the first
register on a page, you'll get 32 bytes back. If you request
the last register on a page, you'll get one 1 back.

--
Grant Edwards grante Yow! If I pull this SWITCH
at I'll be RITA HAYWORTH!! Or
visi.com a SCIENTOLOGIST!
Jul 24 '06 #3

P: n/a
On 2006-07-24, al***************@yahoo.com <al***************@yahoo.comwrote:
>>import serial
s = serial.Serial(0, baudrate=9600, bytesize=8, parity='N', stopbits=1, timeout=None)
s.write("\x33")
s.write("\x00")
s.write("\x00")
s.read() # "\x00" is returned here. This byte was already in the receive buffer before issueing the write commands.
s.read() # The interpreter is blocked here as there is nothing to read from the serial port.
Can you verify that the device is actually responding by
watching the data line with an oscilloscope?
I'm completely clueless and would really appreciate your
comments. If it helps, I can post a log from a serial port
monitor captured when the provided T-logger program pulls data
from the device,
I take it that means that other programs are able to read from
the device?
as well as a log when pyserial is used.
Logs of the serial traffic would be helpful.

--
Grant Edwards grante Yow! It's the land of
at DONNY AND MARIE as promised
visi.com in TV GUIDE!
Jul 24 '06 #4

P: n/a
Gerhard Fiedler wrote:
On 2006-07-24 14:03:30, al***************@yahoo.com wrote:
To read from the chip, one must issue the "read page" command (33h),
followed by the two-byte address of the requested page (pages are 32
bytes long). After receiving this, the DS1615 will send the data in a
burst of (up to) 32 bytes.

I'm not sure what you mean when you say it will send "up to" 32 bytes. If
you mean that it sends bytes until all existing values have been sent --
did you make sure you have any values in the buffer?

(Just asking the obvious... :)

Gerhard
Thanks Gerhard,

Up to 32 bytes means that the chip sends the bytes from the address you
give up to the end of the memory page that contains this address. Thus
if you give the address of the beginning of a memory page (e.g. like
here 0000H for the beginning of the first page, which contains control
registers and the current temperature register), you get 32 bytes.

alex

Jul 24 '06 #5

P: n/a
Thanks Grant,
Can you verify that the device is actually responding by
watching the data line with an oscilloscope?
I don't have an oscilloscope but the device does respond (LED blinks)
when I send it a test command (44H).
I take it that means that other programs are able to read from
the device?
Yes, the device comes with a little GUI program to read the logged
temperatures, calibrate, etc... Works fine, but I would like to read
distributed loggers over the network with python and sockets.
Logs of the serial traffic would be helpful.
Here they are. First a log of the traffic generated by the T-logger GUI
program, abtained with Portmon.

### TRAFFIC WHEN THE PROGRAM IS LAUNCHED:

0 0.00000000 TLogger.exe IRP_MJ_CREATE Serial0 Options: Open
0 0.00006174 SUCCESS
1 0.00000000 TLogger.exe IOCTL_SERIAL_SET_WAIT_MASK Serial0 Mask:
RXCHAR TXEMPTY CTS DSR RLSD BRK ERR RING
1 0.00000726 SUCCESS
2 0.00000000 TLogger.exe IOCTL_SERIAL_PURGE Serial0 Purge: TXABORT
RXABORT TXCLEAR RXCLEAR
2 0.00000698 SUCCESS
3 0.00000000 TLogger.exe IOCTL_SERIAL_SET_TIMEOUTS Serial0 RI:-1
RM:0 RC:0 WM:0 WC:5000
3 0.00000168 SUCCESS
4 0.00000000 TLogger.exe IOCTL_SERIAL_GET_BAUD_RATE Serial0
4 0.00000279 SUCCESS
5 0.00000000 TLogger.exe IOCTL_SERIAL_GET_LINE_CONTROL Serial0
5 0.00000196 SUCCESS
6 0.00000000 TLogger.exe IOCTL_SERIAL_GET_CHARS Serial0
6 0.00000223 SUCCESS
7 0.00000000 TLogger.exe IOCTL_SERIAL_GET_HANDFLOW Serial0
7 0.00000196 SUCCESS
8 0.00000000 TLogger.exe IOCTL_SERIAL_GET_BAUD_RATE Serial0
8 0.00000196 SUCCESS
9 0.00000000 TLogger.exe IOCTL_SERIAL_GET_LINE_CONTROL Serial0
9 0.00000168 SUCCESS
10 0.00000000 TLogger.exe IOCTL_SERIAL_GET_CHARS Serial0
10 0.00000168 SUCCESS
11 0.00000000 TLogger.exe IOCTL_SERIAL_GET_HANDFLOW Serial0
11 0.00000168 SUCCESS
12 0.00000000 TLogger.exe IOCTL_SERIAL_SET_BAUD_RATE Serial0 Rate:
9600
12 0.00001285 SUCCESS
13 0.00000000 TLogger.exe IOCTL_SERIAL_CLR_RTS Serial0
13 0.00000782 SUCCESS
14 0.00000000 TLogger.exe IOCTL_SERIAL_SET_DTR Serial0
14 0.00000810 SUCCESS
15 0.00000000 TLogger.exe IOCTL_SERIAL_SET_LINE_CONTROL Serial0
StopBits: ERROR Parity: NONE WordLength: 8
15 0.00000698 SUCCESS
16 0.00000000 TLogger.exe IOCTL_SERIAL_SET_CHAR Serial0 EOF:1a
ERR:0 BRK:0 EVT:0 XON:11 XOFF:13
16 0.00000531 SUCCESS
17 0.00000000 TLogger.exe IOCTL_SERIAL_SET_HANDFLOW Serial0
Shake:1 Replace:0 XonLimit:8 XoffLimit:8
17 0.00000754 SUCCESS
18 0.00000000 TLogger.exe IOCTL_SERIAL_SET_WAIT_MASK Serial0 Mask:
RXCHAR TXEMPTY CTS DSR RLSD BRK ERR RING
18 0.00001145 SUCCESS
19 0.00000000 TLogger.exe IOCTL_SERIAL_SET_WAIT_MASK Serial0 Mask:
RXCHAR TXEMPTY CTS DSR RLSD BRK ERR RING
19 0.00000531 SUCCESS
20 0.00000000 TLogger.exe IOCTL_SERIAL_WAIT_ON_MASK Serial0

### TRAFFIC WHEN THE PROGRAM READS CURRENT TEMP FROM DEVICE:

21 0.00000000 TLogger.exe IOCTL_SERIAL_GET_COMMSTATUS Serial0
21 0.00001034 SUCCESS
22 0.00000000 TLogger.exe IRP_MJ_WRITE Serial0 Length 1: 33
22 0.00003269 SUCCESS
20 9.28649032 SUCCESS
23 0.00000000 TLogger.exe IOCTL_SERIAL_GET_COMMSTATUS Serial0
23 0.00000587 SUCCESS
24 0.00000000 TLogger.exe IOCTL_SERIAL_GET_COMMSTATUS Serial0
24 0.00000559 SUCCESS
25 0.00000000 TLogger.exe IOCTL_SERIAL_GET_PROPERTIES Serial0
25 0.00000168 SUCCESS
26 0.00000000 TLogger.exe IRP_MJ_WRITE Serial0 Length 1: 00
27 0.00000000 TLogger.exe IOCTL_SERIAL_SET_WAIT_MASK Serial0 Mask:
RXCHAR TXEMPTY CTS DSR RLSD BRK ERR RING
27 0.00000726 SUCCESS
28 0.00000000 TLogger.exe IOCTL_SERIAL_WAIT_ON_MASK Serial0
26 0.00107611 SUCCESS
28 0.00097666 SUCCESS
29 0.00000000 TLogger.exe IOCTL_SERIAL_GET_COMMSTATUS Serial0
29 0.00000587 SUCCESS
30 0.00000000 TLogger.exe IOCTL_SERIAL_GET_COMMSTATUS Serial0
30 0.00000503 SUCCESS
31 0.00000000 TLogger.exe IOCTL_SERIAL_GET_PROPERTIES Serial0
31 0.00000196 SUCCESS
32 0.00000000 TLogger.exe IRP_MJ_WRITE Serial0 Length 1: 00
33 0.00000000 TLogger.exe IOCTL_SERIAL_SET_WAIT_MASK Serial0 Mask:
RXCHAR TXEMPTY CTS DSR RLSD BRK ERR RING
33 0.00000531 SUCCESS
34 0.00000000 TLogger.exe IOCTL_SERIAL_WAIT_ON_MASK Serial0
32 0.00102583 SUCCESS
34 0.00098811 SUCCESS
35 0.00000000 TLogger.exe IOCTL_SERIAL_GET_COMMSTATUS Serial0
35 0.00000559 SUCCESS
36 0.00000000 TLogger.exe IOCTL_SERIAL_GET_COMMSTATUS Serial0
36 0.00000726 SUCCESS
37 0.00000000 TLogger.exe IOCTL_SERIAL_GET_COMMSTATUS Serial0
37 0.00000559 SUCCESS
38 0.00000000 TLogger.exe IOCTL_SERIAL_SET_WAIT_MASK Serial0 Mask:
RXCHAR TXEMPTY CTS DSR RLSD BRK ERR RING
38 0.00001173 SUCCESS
39 0.00000000 TLogger.exe IOCTL_SERIAL_WAIT_ON_MASK Serial0
39 0.00934281 SUCCESS
40 0.00000000 TLogger.exe IOCTL_SERIAL_SET_WAIT_MASK Serial0 Mask:
RXCHAR TXEMPTY CTS DSR RLSD BRK ERR RING
40 0.00000922 SUCCESS
41 0.00000000 TLogger.exe IOCTL_SERIAL_WAIT_ON_MASK Serial0
41 0.00001034 SUCCESS
42 0.00000000 TLogger.exe IOCTL_SERIAL_SET_WAIT_MASK Serial0 Mask:
RXCHAR TXEMPTY CTS DSR RLSD BRK ERR RING
42 0.00000531 SUCCESS
43 0.00000000 TLogger.exe IOCTL_SERIAL_WAIT_ON_MASK Serial0
43 0.00905059 SUCCESS
44 0.00000000 TLogger.exe IOCTL_SERIAL_SET_WAIT_MASK Serial0 Mask:
RXCHAR TXEMPTY CTS DSR RLSD BRK ERR RING
44 0.00000782 SUCCESS
45 0.00000000 TLogger.exe IOCTL_SERIAL_WAIT_ON_MASK Serial0
45 0.00000978 SUCCESS
46 0.00000000 TLogger.exe IOCTL_SERIAL_SET_WAIT_MASK Serial0 Mask:
RXCHAR TXEMPTY CTS DSR RLSD BRK ERR RING
46 0.00000531 SUCCESS
47 0.00000000 TLogger.exe IOCTL_SERIAL_WAIT_ON_MASK Serial0
47 0.00906735 SUCCESS
48 0.00000000 TLogger.exe IOCTL_SERIAL_SET_WAIT_MASK Serial0 Mask:
RXCHAR TXEMPTY CTS DSR RLSD BRK ERR RING
48 0.00000838 SUCCESS
49 0.00000000 TLogger.exe IOCTL_SERIAL_WAIT_ON_MASK Serial0
49 0.00001006 SUCCESS
50 0.00000000 TLogger.exe IOCTL_SERIAL_SET_WAIT_MASK Serial0 Mask:
RXCHAR TXEMPTY CTS DSR RLSD BRK ERR RING
50 0.00000531 SUCCESS
51 0.00000000 TLogger.exe IOCTL_SERIAL_WAIT_ON_MASK Serial0
51 0.00907238 SUCCESS
52 0.00000000 TLogger.exe IOCTL_SERIAL_SET_WAIT_MASK Serial0 Mask:
RXCHAR TXEMPTY CTS DSR RLSD BRK ERR RING
52 0.00000978 SUCCESS
53 0.00000000 TLogger.exe IOCTL_SERIAL_WAIT_ON_MASK Serial0
53 0.00000950 SUCCESS
54 0.00000000 TLogger.exe IOCTL_SERIAL_SET_WAIT_MASK Serial0 Mask:
RXCHAR TXEMPTY CTS DSR RLSD BRK ERR RING
54 0.00000531 SUCCESS
55 0.00000000 TLogger.exe IOCTL_SERIAL_WAIT_ON_MASK Serial0
55 0.00676706 SUCCESS
56 0.00000000 TLogger.exe IOCTL_SERIAL_SET_WAIT_MASK Serial0 Mask:
RXCHAR TXEMPTY CTS DSR RLSD BRK ERR RING
56 0.00001006 SUCCESS
57 0.00000000 TLogger.exe IOCTL_SERIAL_WAIT_ON_MASK Serial0
57 0.00001006 SUCCESS
58 0.00000000 TLogger.exe IOCTL_SERIAL_SET_WAIT_MASK Serial0 Mask:
RXCHAR TXEMPTY CTS DSR RLSD BRK ERR RING
58 0.00000531 SUCCESS
59 0.00000000 TLogger.exe IOCTL_SERIAL_WAIT_ON_MASK Serial0
60 0.00000000 TLogger.exe IOCTL_SERIAL_GET_COMMSTATUS Serial0
60 0.00000978 SUCCESS
61 0.00000000 TLogger.exe IRP_MJ_READ Serial0 Length 1
61 0.00000978 SUCCESS Length 1: 26
62 0.00000000 TLogger.exe IOCTL_SERIAL_GET_COMMSTATUS Serial0
62 0.00000587 SUCCESS
63 0.00000000 TLogger.exe IRP_MJ_READ Serial0 Length 1
63 0.00000615 SUCCESS Length 1: 35
64 0.00000000 TLogger.exe IOCTL_SERIAL_GET_COMMSTATUS Serial0
64 0.00000531 SUCCESS
65 0.00000000 TLogger.exe IRP_MJ_READ Serial0 Length 1
65 0.00000559 SUCCESS Length 1: 14
66 0.00000000 TLogger.exe IOCTL_SERIAL_GET_COMMSTATUS Serial0
66 0.00000503 SUCCESS
67 0.00000000 TLogger.exe IRP_MJ_READ Serial0 Length 1
67 0.00000587 SUCCESS Length 1: 02

I'm cutting here but 32 bytes of data are acquired.

And here is the traffic when I'm using pyserial:
>s = serial.Serial(0, baudrate=9600, bytesize=8, parity='N', stopbits=1, timeout=None)
0 0.00006230 python.exe IRP_MJ_CREATE Serial0 SUCCESS Options: Open
1 0.00000363 python.exe IOCTL_SERIAL_SET_QUEUE_SIZE Serial0 SUCCESS InSize:
4096 OutSize: 4096
2 0.00000223 python.exe IOCTL_SERIAL_GET_TIMEOUTS Serial0 SUCCESS
3 0.00000251 python.exe IOCTL_SERIAL_SET_TIMEOUTS Serial0 SUCCESS RI:0
RM:0 RC:0 WM:0 WC:0
4 0.00000698 python.exe IOCTL_SERIAL_SET_WAIT_MASK Serial0 SUCCESS Mask:
ERR
5 0.00000223 python.exe IOCTL_SERIAL_GET_BAUD_RATE Serial0 SUCCESS
6 0.00000196 python.exe IOCTL_SERIAL_GET_LINE_CONTROL Serial0 SUCCESS
7 0.00000196 python.exe IOCTL_SERIAL_GET_CHARS Serial0 SUCCESS
8 0.00000168 python.exe IOCTL_SERIAL_GET_HANDFLOW Serial0 SUCCESS
9 0.00000196 python.exe IOCTL_SERIAL_GET_BAUD_RATE Serial0 SUCCESS
10 0.00000196 python.exe IOCTL_SERIAL_GET_LINE_CONTROL Serial0 SUCCESS
11 0.00000196 python.exe IOCTL_SERIAL_GET_CHARS Serial0 SUCCESS
12 0.00000168 python.exe IOCTL_SERIAL_GET_HANDFLOW Serial0 SUCCESS
13 0.00001285 python.exe IOCTL_SERIAL_SET_BAUD_RATE Serial0 SUCCESS Rate:
9600
14 0.00000810 python.exe IOCTL_SERIAL_SET_RTS Serial0 SUCCESS
15 0.00000810 python.exe IOCTL_SERIAL_SET_DTR Serial0 SUCCESS
16 0.00000698 python.exe IOCTL_SERIAL_SET_LINE_CONTROL Serial0 SUCCESS StopBits:
1 Parity: NONE WordLength: 8
17 0.00000559 python.exe IOCTL_SERIAL_SET_CHAR Serial0 SUCCESS EOF:1a
ERR:0 BRK:0 EVT:0 XON:11 XOFF:13
18 0.00001062 python.exe IOCTL_SERIAL_SET_HANDFLOW Serial0 SUCCESS Shake:1
Replace:40 XonLimit:2048 XoffLimit:512
19 0.00000698 python.exe IOCTL_SERIAL_PURGE Serial0 SUCCESS Purge:
TXABORT RXABORT TXCLEAR RXCLEAR
>s.write("\x33")
20 0.00003716 python.exe IRP_MJ_WRITE Serial0 SUCCESS Length 1: 33
>s.write("\x00")
21 0.00003632 python.exe IRP_MJ_WRITE Serial0 SUCCESS Length 1: 00
>s.write("\x00")
22 0.00003632 python.exe IRP_MJ_WRITE Serial0 SUCCESS Length 1: 00
>s.read() # "\x00" is returned here. This byte was already in the receive buffer before issueing the write commands.
23 0.00001145 python.exe IOCTL_SERIAL_GET_COMMSTATUS Serial0 SUCCESS
24 0.00000978 python.exe IRP_MJ_READ Serial0 SUCCESS Length 1: 00
>s.read() # I've had to kill interpreter here (nothing to read and I had timeout=None)
25 0.00001062 python.exe IOCTL_SERIAL_GET_COMMSTATUS Serial0 SUCCESS
26 32.01253595 python.exe IRP_MJ_READ Serial0 CANCELLED Length 1

alex

Jul 24 '06 #6

P: n/a
On 2006-07-24, al***************@yahoo.com <al***************@yahoo.comwrote:
>Logs of the serial traffic would be helpful.

Here they are. First a log of the traffic generated by the
T-logger GUI program, abtained with Portmon.
I try to avoid Windows as much as humanly possible, but one
thing that appears to be different is that Tlogger clears RTS
and your program sets it. Try clearing RTS in your program
when you set up the serial port.

If clearing RTS doesn't help, I guess I'd try different flow
control settings (try enabling and disabling RTS/CTS flow
control).

Since you're dealing with binary data, make sure that Xon/Xoff
flow control is disabled.

--
Grant Edwards grante Yow! What's the MATTER
at Sid?... Is your BEVERAGE
visi.com unsatisfactory?
Jul 24 '06 #7

P: n/a
Grant Edwards wrote:
On 2006-07-24, al***************@yahoo.com <al***************@yahoo.comwrote:

>>>Logs of the serial traffic would be helpful.

Here they are. First a log of the traffic generated by the
T-logger GUI program, abtained with Portmon.


I try to avoid Windows as much as humanly possible, but one
thing that appears to be different is that Tlogger clears RTS
and your program sets it. Try clearing RTS in your program
when you set up the serial port.

If clearing RTS doesn't help, I guess I'd try different flow
control settings (try enabling and disabling RTS/CTS flow
control).

Since you're dealing with binary data, make sure that Xon/Xoff
flow control is disabled.
It could also be a timing issue or handshaking problem.
Having to write to the chip "a byte at a time" implies
that it could take it a little while to digest each byte;
longer than the natural character time for the baud rate,
that is. I'm not sure if I'm reading the portmon output
correctly, but it looks like the "T-logger" program
is waiting for CTS (or possibly some other condition)
before sending each byte. The Python program does not
appear to be doing so, it's just sending the three bytes,
bang bang bang.

-- JK
Jul 24 '06 #8

This discussion thread is closed

Replies have been disabled for this discussion.