Notice. New forum software under development. It's going to miss a few functions and look a bit ugly for a while, but I'm working on it full time now as the old forum was too unstable. Couple days, all good. If you notice any issues, please contact me.
|
Forum Index : Microcontroller and PC projects : Reading/Writing 8-bit files
Author | Message | ||||
rodent59 Newbie Joined: 02/03/2012 Location: AustraliaPosts: 7 |
This may well be generally known, but just in case it's not... For MMBasic3.1 While all INPUT and PRINT commands deal with ASCII (7-bit) characters, they can handle 'whole' 8-bit bytes as follows: Open any non-text file (say a .pdf or .jpg for example) and read a single byte: a$=input$(1,#1) print ASC(a$) 'returns the 8 bit result (0 to 255) or print HEX$(ASC(a$)) 'returns the hex code for the byte. When writing to a file: print #2,CHR$(250); 'will write a single byte to file with decimal code 250 or print #2,CHR$(&HE8); 'will write a single byte to file with hex code E8. Might be useful if reading/writing non-text files sequentially. Apologies if this is old news! |
||||
Geoffg Guru Joined: 06/06/2011 Location: AustraliaPosts: 3194 |
Good point rodent. In fact ver 2.1 could not do this and it was only in ver 2.3 (I think) that I rewrote the string handling to fix it. Now all string handling is 8 bit "clean". So you can (for example) do a$ = chr$0) and so on. Also, USB is 8 bit clean, so you can print a null character to the host PC by doing PRINT chr$(0) Geoff Geoff Graham - http://geoffg.net |
||||
PeterR Newbie Joined: 28/06/2011 Location: Posts: 2 |
Thanks Rodent, I been trying to work out how to send 8 bit non text data. Geoff, can you use this on a serial port? Eg. open "com1:4800" as #1 print #1,chr$(0) I seem to be having issues. Peter Peter |
||||
Geoffg Guru Joined: 06/06/2011 Location: AustraliaPosts: 3194 |
Yes, that works fine. I have an application that drives a serial LCD using codes like that. Geoff Geoff Graham - http://geoffg.net |
||||
aargee Senior Member Joined: 21/08/2008 Location: AustraliaPosts: 255 |
That's why my cursory go at serial GLCD driving failed! Thanks for the thread everyone. - Rob For crying out loud, all I wanted to do was flash this blasted LED. |
||||
Print this page |