[Tutor] serial port, revisited, but closer
A.T.Hofkamp
a.t.hofkamp at tue.nl
Wed Nov 5 17:06:59 CET 2008
shawn bright wrote:
> Hey all,
>
> I am back again with the serial port stuff, i have verified that all
> the baud rate and settings are ok,
> had my unit talk directly to a serial port reader and it is looking
> good, however, i still am not seeming to be able to read this.
>
> I had a question that might make me a clue.
> if i do this:
> j = ser.read(23)
> f = open('filename', 'wb')
> f.write(j)
>
> when i do file from the cli in linux, the file says to contain data.
> however if i do this:
> i = 1
> msg_list = []
> while i < 23:
> msg_list.append(ser.read(1))
> items = ''.join(msg_list)
> f=open('filename', 'wb')
> f.write(items)
> f.close()
One difference at least is that the first program reads 23 bytes, and the
second many more (i is not incremented, so the program loops forever).
The second difference is that the first program does not close the file??
(kind of depends how you run things, and at what moment you ask Linux about
the file).
Also, do 'print repr(j)' in the first program, and 'print repr(items)' in the
second program to see exactly what is written to the file.
> i get that the file is a binary file.
The next question is of course, is there really any difference, and if yes, what?
At the file system, you could
- Check whether both files equally are long (23 bytes, assuming your loop
terminated after 23 iterations).
- Compare the files with 'cmp filename1 filename2' which reports whether or
not files are equal and if not where the first difference is.
- Dump the contents of the file to screen in human-readable hex-dump with eg
'xxd filename' (xxd is part of the vim package I believe).
Sincerely,
Albert
More information about the Tutor
mailing list