I'm having troubles sending the null byte (0x00) to the serial port in
Windows using PySerial on ActivePython 2.2.1 build 222. Currently I'm
doing something like this:
com = serial.Serial("COM1", 9600, timeout=1)
-- <some data transfer on the port> --
com.write(chr(0))
The device should reply a single byte upon receiving this byte, but I
never got anything in reply.
I looked at PySerial's code, which calls win32file.WriteFile() to
write to the serial port. I also checked out USPP, which
unfortunately threw an exception when I called read(). I suppose it
wouldn't make a huge difference anyway, since USPP uses win32file for
the underlying communication as well.
Have I missed anything? Should I use some other method to write the
null byte to the serial port?
Thank you very much for you help!
sidenote: i sugest to use numbers i.e. 0 <-> "COM1" that makes it easier if
you want to run the prog on other platforms or with jython.
> com.write(chr(0))
well i'm reading and writing null characters en masse. so no problem. the
port is configured for binary data transmition on all platforms.
> The device should reply a single byte upon receiving this byte, but I
> never got anything in reply.
well i suspect that something is wrong with your setup. you're sure your
device is connected to the right port and listening with the same baudrate?
you're reading from the port as you expect, you use a timeout. does the
read function return before your device answers?
chris
--
Chris <clie...@gmx.net>
Portability isn't a big concern for this application (yet), with the
ActiveX I'm using, but I'll take your advice.
> > com.write(chr(0))
>
> well i'm reading and writing null characters en masse. so no problem. the
> port is configured for binary data transmition on all platforms.
So that *is* the way to send a null byte? I was wondering if I
screwed up there (and/or that WriteFile() doesn't support null byte).
> > The device should reply a single byte upon receiving this byte, but I
> > never got anything in reply.
>
> well i suspect that something is wrong with your setup. you're sure your
> device is connected to the right port and listening with the same baudrate?
> you're reading from the port as you expect, you use a timeout. does the
> read function return before your device answers?
Hm.. then either a) the protocol (including baudrate, etc) is not the
same as the manufacturer's specification states; or b) the port
timeout before I read... the device is "supposed to be working" in the
"other-apps-can-access-it" sense.
Since it's easier to test case (b), my question is, would inWaiting()
detect a byte even if the timeout is too fast?
Thank you again!
yes if you have a longer string with other data you can also insert a null
byte with "\0" or "\x00" etc. it's all the same.
> Since it's easier to test case (b), my question is, would inWaiting()
> detect a byte even if the timeout is too fast?
inWaiting() return the number of characters in the buffer that the OS has.
characters disapear from the buffer if you read them or if you flush the
buffer. so yes, if your read() call would return too fast and characters
arrived after that and then you did a inWaiting() it should return a
nonzero value.
chris
--
Chris <clie...@gmx.net>