Serial Coms in (GW)BASIC


New Member
Mar 13, 2020
Hi Everybody,

i joined this forum because i am working on a project and i think some of you here might be able to help me out with it.

I have attached a SIM800L GPRS module to a microcontroller (ESP32 in my case) and subsequently to my very vintage IBM5140 convertable.
The idea of being able to pull out this vintage machine and send an email through the mobile network from anywhere is quite pleasing to me.
Also it would be great at some exhibitions : send yourself a mail from this IBM5140 🙃
and the inevitable subtext --sent from my IBM5140-- in all emails just makes me giggle.

So i got to work, i still had some GPRS cards and microntrollers here that i didnt use yet, from M5Stack, if you don't know them check it out, it's quite cool.
First i got the interactions between GPRS module and microntroller figured out, they communicate over serial line with AT Commands.
That all works fine now.
Then i started working on how i would interface the microcontroller and the IBM, i have an RS232 port on my IBM so that's perfect.

I wrote a small GWBASIC program that does the communication with the microcontroller, however the micro does all the heavy lifiting, i'm a cheat i know... haha
All works fine except for one thing:
When i start up my microcontroller the first time, open the serial communications, from some reason the program produces an error in certain cases...
The error is a device I/O error and it occurs when i try to read from the comport.

Device I/O error means that
A "Device I/O" error occurs if any of the following line conditions are detected on receive: overrun error (OE), framing error (FE), or break interrupt (BI). The error is reset by subsequent inputs, but the character causing the error is lost.
according to source : HERE

My GWBASIC code, the part where it fails, i opened com1 on stream #1
IF EOF(1) THEN 210
the first line checks if anything is there, if not, it returns to the code before, where i transmit the keyboard input to the serial port
The second line causes the DEVICE I/O error...

The funny thing is :
This only occurs the very first time when i run this program, when the microcontroller has booted up while the IBM is in DOS.
If i reset the microcontroller while running GWBASIC, the error is gone.
I think it is because i'm already sending something out of that serial port while my basic program is not running yet.

Anybody an idea how i could reset those device error flags and clearing the RX buffer before commencing my program?
I tried turning COM(1) OFF and ON again (hehe) but that didn't help.
I tried closing #1 at the beginning of the code to make sure nothing was there, but halas.

I know this was a lot to read, but if you made it to here, Congrats!
You are maybe the nerd i'm looking for :LOL:

Thanks all and stay cool!

Wim from Belgium

time for a beer now after typing all that stuff haha, cheers!
May 22, 2019
This sounds interesting. I haven't seen that particular problem before. Have you tried using ON ERROR GOTO to trap and clear the error, then continuing your program?
May 22, 2019
Also, you can play with this on a modern PC, too.... check out PC BASIC, here:

It would be interesting to see if you have the same problems running on a modern PC.

Also, are you running in DOS or in ROM BASIC? If you are using DOS, you might look at compiling it with Quick BASIC. Quick BASIC's communication code might not have the same problems as the 5140 ROM BASIC or GWBASIC.


New Member
Mar 13, 2020
Hi Tom,

thanks for getting back to me!
I've tried running code with PC Basic, but not with the serial comms yet

I am using the DOS verion of GWBASIC indeed, it really sucks to use the ROM version on my IBM cause i have an AZERTY keyboard and the ROM expects QWERTY
Also i'd rather use LOAD and SAVE :p, I never was good at typing fast.

As for QBASIC, i am currently running DOS 3.3 because the IBM suite for the IBM5140 runs on that version natively.
Also take in mind that this computer does not have a hard drive so anything that i can run has to fit on a 720k Floppy....
That's why i started out with GWBASIC.
It's the first time ever i use basic actually, so i have absolutely NO idea on the error handling yet 😅

I did find a work-around with my micro controller now!
I was using Hardware Serial, but the bootloader of my board puts some log on there in another baudrate (115200)
WAY to fast for my IBM.
So i implemented a software serial now on some spare pins at 1200bps and that worked well now!

Unfortunately my RS232 - TTL converter burnt up now, haha, it didn't really work well actually on 3.3V
So i'm going to put a Logic Level converter in between to pump up the signal to 5V and all should be well.

Another delay on the project, waiting for the stuff :-D
Should be able to send emails from the 5140 by the summer though 😆

If i finally manage to get it to work, i'll drop you a line 😉




New Member
Mar 13, 2020
PS : I managed to get the FTDI adapter working from PC-Basic, which is great, now i can optimize the BASIC software without the RS232 converter!
  • Like
Reactions: TomXP411