![]() |
Forum Index : Microcontroller and PC projects : MMbasic v4.5 - output byte to serial
Author | Message | ||||
flasherror Senior Member ![]() Joined: 07/01/2019 Location: United StatesPosts: 159 |
Hello, I'm using MMBasic v4.5 on a Duinomite board and have a problem that I am stuck with, so posting here. I need to send a specific sequence of bytes (some non ASCII) to serial port. All I want is to send a byte (or array of bytes) without MMBasic's "helpful" formatting features. I want to do something like print #3, data; to send the actual value of the byte, not the ASCII representation. Furthermore, some of the bytes are non-printable ASCII values (for example byte = 0)I understand that I can suppress CR/LF with using PRINT with semicolon at the end. I can't use WRITE (with a string) because of the " automatic start/end quote prefixes. The only thing I can think of is creating a string$ and storing values in it and then sending but I believe PRINT will not print non-printable values and would convert to ASCII chars anyway? This is likely to be something simple that I am missing - but what? I have read the MMBasic manual multiple times and nothing stands out. |
||||
Turbo46![]() Guru ![]() Joined: 24/12/2017 Location: AustraliaPosts: 1642 |
Welcome flasherror, Do you mean something like this? TXD$ = CHR$(RxAdd%)+CHR$(Fn%)+CHR$(BCnt%)+CHR$(In%) PRINT #1, TXD$; Bill Keep safe. Live long and prosper. |
||||
TassyJim![]() Guru ![]() Joined: 07/08/2011 Location: AustraliaPosts: 6283 |
MMBasic strings can contain all 256 values ( 0 to 255) It is one of the advantages when trying to send 'data' not just printable text. Turbo64's code is all you need but for V4.5, ignore the % suffix TXD$ = CHR$(RxAdd)+CHR$(Fn)+CHR$(BCnt)+CHR$(In) PRINT #1, TXD$; Jim VK7JH MMedit |
||||
Turbo46![]() Guru ![]() Joined: 24/12/2017 Location: AustraliaPosts: 1642 |
Thanks Jim, Too many Mites. I forgot the Duinomite is a Maximite beast. Bill Keep safe. Live long and prosper. |
||||
Grogster![]() Admin Group ![]() Joined: 31/12/2012 Location: New ZealandPosts: 9610 |
I agree. I use this exact same method to send strings of non-printable bytes to various things. An example is the SMS module I use for cell-phone texting. You need to send a command that consists of the double-quote mark, and CTRL-Z to end the instruction. CTRL-Z is non-printable, and the double-quote is used by MMBASIC to define text, so you can't use that inside double-quotes! ![]() MSG$="Hello. This is a test." T$="AT+CMGS="+CHR$(34)+"012345678"+CHR$(34)+MSG$+CHR$(26) Print #1,T$; In this example, MSG$ is a plain old text message, and T$ builds the string to send to the SMS module, so it will text it to the cellphone. CHR$(34) is a double-quote("), and CHR$(26) is CTRL-Z. MMBASIC has powerful string manipulation commands once you get stuck into the language. ![]() Smoke makes things work. When the smoke gets out, it stops! |
||||
Turbo46![]() Guru ![]() Joined: 24/12/2017 Location: AustraliaPosts: 1642 |
Handy for escape codes too: ' Escape codes to clear the VT100 screen SUB CLS2 PRINT #2, CHR$(27) "[2J" CHR$(27) "[H" END SUB And yes, as you can see from the above. Print will print non-printing characters. Bill Keep safe. Live long and prosper. |
||||
flasherror Senior Member ![]() Joined: 07/01/2019 Location: United StatesPosts: 159 |
Thanks everyone. Use of string tested and working. I was on the right track with the use of a string$ but didn't realize that print # would actually send the bytes (since printing to screen didn't). I remember 80s basic programming and concatenation and the chr$(xx) tricks (still remember chr$(34) is " from memory) However, in the event that MMBasic docs are updated it would be good idea to mention this use of string to send data directly. I was looking for an alternate PRINT command. Is there a Wiki for MMbasic/the different *mite boards? Something that shows what language differences between MMbasic version (e.g. no SELECT CASE in v4.5). I'm thinking a wiki might complement digging through forum posts? |
||||
![]() |
![]() |
The Back Shed's forum code is written, and hosted, in Australia. | © JAQ Software 2025 |