Home
JAQForum Ver 24.01
Log In or Join  
Active Topics
Local Time 11:20 01 Aug 2025 Privacy Policy
Jump to

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 : MMbasic v4.5 - output byte to serial

Author Message
flasherror
Senior Member

Joined: 07/01/2019
Location: United States
Posts: 159
Posted: 06:42am 07 Jan 2019
Copy link to clipboard 
Print this post

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: Australia
Posts: 1642
Posted: 07:15am 07 Jan 2019
Copy link to clipboard 
Print this post

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: Australia
Posts: 6283
Posted: 07:30am 07 Jan 2019
Copy link to clipboard 
Print this post

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: Australia
Posts: 1642
Posted: 07:45am 07 Jan 2019
Copy link to clipboard 
Print this post

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 Zealand
Posts: 9610
Posted: 09:21pm 07 Jan 2019
Copy link to clipboard 
Print this post

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: Australia
Posts: 1642
Posted: 10:35pm 07 Jan 2019
Copy link to clipboard 
Print this post

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 States
Posts: 159
Posted: 12:42am 08 Jan 2019
Copy link to clipboard 
Print this post

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?



 
Print this page


To reply to this topic, you need to log in.

The Back Shed's forum code is written, and hosted, in Australia.
© JAQ Software 2025