Posts: 5
Threads: 1
Joined: Mar 2025
Reputation:
0
Hi,
I'm a recent (re)convert to QB, having used it many years ago, so I'm learning all over again.
Can anyone point me towards any information about using the serial ports (actually the USB ports) under Linux (Mint) please?. I had a browse through this forum, looking at various things which might help, but not had much success, and my very old recollections don't stir any memories.
Posts: 2,574
Threads: 264
Joined: Apr 2022
Reputation:
140
Hi Keith,
I'm not a Linux user, but we do have a fair amount here who are. Anyway, I just wanted to welcome you to the forum and since it may take a while for the right user to find this post and respond, I want to encourage you to post a bit more on what access to using the usb ports will do in your program. That might help someone to better help you. If you already have some code, posting it would help even more.
Pete
Posts: 5
Threads: 1
Joined: Mar 2025
Reputation:
0
Hi, Pete - thanks for the message.
I'm working on developing an Eprom Programmer to read and program the older series 27XXX type Eproms - basically so I can support some old computers (ORIC, SINCLAIR ZX81 and similar).
It consists of a Controller, running on a PC (in my case under Linux Mint - sorry, I'm not a lover of Windows in any form), with a serial connection (USB) to the Programmer itself.
The programmer is an Arduino Nano, used to present and accept data to the Eprom, set up the required programming voltage, and generate programming pulses. This is programmed in Arduino CPP, and is working fine.
The Controller (currently) is partly written in Gambas3, (for those who don't know, this is similar to Visual Basic). It is used to pass control and program data to the Arduino Programmer.
I chose to write the Controller in something 'Basic' - like, because maybe eventually I will make the programmer/system public, and since the Programmer only requires control bytes and data passed by a 'standard' serial port, it could be controlled from virtually any computer. For this reason, I wanted to keep the Controller software simple (I.e avoid compiling, etc), then if anyone wants to write their own controller (in any language) they are free to do so.
I mentioned I started with Gambas3, but as I have worked on it, I have found the handling of the serial port under Gambas3 is not as straightforward as it could be, and despite subscribing to various forums, I cannot find some of the information I need. Currently, it is working 'up to a point', but I'm not happy.
I decided to push it to one side for the moment, and try another Basic, and since I had read about QB64-PE, and had used QB many (many, many......) years ago, decided it would be interesting to revisit it, and see how it has developed. I have seen somewhere there is a serial library available for it, and it also offers the use of InForm to generate graphic UI's, so it seemed a possibility - which is where I am now, and is the reason for my question about Serial Port handling. I only need to be able to read/write single bytes, and ideally I need some program indication that data is available at the port for reading. Gambas3 has this, but is event-driven. The port will accept data into the receive buffer, but it is the program responsibility to read this data, and so far, I have found no way of getting an indication (in Gambas) that data is waiting. As a consequence of this, sometimes data gets overwritten - bummer!. I am sure that eventually I will find a way round this, but in the interests of getting a working Programmer/Controller, which is simple to understand, I want to investigate alternatives.
I want to program 'old' devices, but the same principle could be used for more modern devices, or for serially programmed devices - so I need to know about QB64 serial port handling.
Regards, Keith
Posts: 14
Threads: 4
Joined: Jun 2024
Reputation:
2
I will be watching this to see if theres anything I missed.
I used qb64pe on my desktop, with a serial USB adapter and had to open it like this:
open "/dev/ttyUSB0" for binary as #1.
Also, I needed to open the port in a com program first, or use 'stty' command line in a 'shell' command.
but after that it seemed to work fine.
Posts: 5
Threads: 1
Joined: Mar 2025
Reputation:
0
Thanks for your input, Parkland.
What you is describe is similar (partly) to the method in Gambas3 - except I am opening it for read or write. Somewhere in my searches I came across something about opening the port using a com program first - think it was 'CuteCom' under Windows. If this is the case, its bit cumbersome - I rather hope I can find something that can be set up in QB64PE..
Anything I can find I will post here, so it can maybe used by someone else.
I guess you are working under Windows - ttyUSB?, and as yet I don't know if there is any difference in Linux - partly my reason for asking if anyone knew of any documentation. I'll try and give your suggestion a try under Linux, and see what happens. I assume that if you don't open the port with a separate com program, then it remains closed to QB64PE?
I'm beginning to think that I might have to write my own Serial Port Library. Since most computers nowadays offer USB ports, it may not be a big problem. There will be no need to handle the Serial handshake lines for USB use, The only setting will be Baud Rate, number of bits, and number of stopbits, so it might be worth a go.
Regards - Keith
Posts: 476
Threads: 90
Joined: Jul 2022
Reputation:
20
You could try:
https://qb64phoenix.com/qb64wiki/index.php/OPEN_COM
although I don't think you can get any USB device opened..
This code accesses COM1: then input/output functions are available.
Code: (Select All) On Error GoTo Handler
FF = FreeFile
comPort$ = "COM1:" 'try a COM port number that does not exist
Const comMode$ = "9600,N,8,1,CS0,DS0" 'Use 0 to avoid timeouts
Open comPort$ + comMode$ For Random As FF
If errnum = 0 Then Print "COM exists!"
K$ = Input$(1)
End
Handler:
errnum = Err
Print "Error:"; errnum
Resume Next
Posts: 5
Threads: 1
Joined: Mar 2025
Reputation:
0
04-04-2025, 08:34 AM
(This post was last modified: 04-04-2025, 08:38 AM by Keith.)
Thanks - EORedson - I'll take a look at this. I think you are probably right about using the USB ports, but it might lead somewhere. I haven't had a lot of time for the last few days, but I'll get there eventually. I have been looking more at accessing the actual port registers, since there doesn't seem to be much 'higher level' information, with the idea of creating a simple USB library. I'm a bit surprised that nothing already exists for USB, since they are so ubiquitous these days.
Reading through the QB64PE documentation from the link you provided about the COM command, there is a line which notes (paraphrase) 'This command is not available in Linux and Mac" - another bummer!.
Posts: 476
Threads: 90
Joined: Jul 2022
Reputation:
20
Quote:This command is not available in Linux and Mac
Oops! Did not see that.. Maybe you should run QB45 in Dosemu. I don't know much about Linux but I have used it before.
Also think about installing a Win10 machine or (if interested) try a multi-OS boot partition with both Linux and Win10..
Erik.
Posts: 83
Threads: 8
Joined: May 2024
Reputation:
9
04-05-2025, 07:03 AM
(This post was last modified: 04-07-2025, 09:07 AM by hsiangch_ong.
Edit Reason: forgot user home directory in path
)
edit: i am sorry for misleading enough people with this post. before it was changed. the name of the user's home directory has to be included right after "/media/". without double-quotation marks. it was not in this post before it was edited.
probably you already know this. but if all you want to do is access files from an usb flash drive or external ssd. you need to have the path beginning as follows.
on debian/ubuntu (including linux mint) it is:
Code: (Select All) /media/(user)/(volume-label)/
on most other linux (arch/fedora/slackware etc.) it is:
Code: (Select All) /run/media/(user)/(volume-label)/
the user (without parenthesis) is the name of your home directory. this is the name you use to log into linux desktop.
the volume-label of the usb disk is actually the name of the root directory. it would be a matter of using _direxists function to check for existence of /run/media/(volume-label)/. if that doesn't exist then try /media/(volume-label)/. then work your way from there to access other files on the usb device.
(actually write the volume label of the disk, not the thing starting with parenthesis as shown above. i wrote it like that because disks should have different names as volume labels. some don't have original names such as "lexar" or "sandisk" or a hexadecimal mumbo-jumbo.)
low-level usb access is hard. as one could probably tell from windows device manager and other places.
Posts: 5
Threads: 1
Joined: Mar 2025
Reputation:
0
Hello, All.
I think we are getting away from the original premise of this thread. As I noted I do not (and will never) use Windows - it is insecure and obscure, and is proprietary code (not freely accessible) - I'm sorry if this offends anyone, but it is based on long experience.
Because of this, I have used Linux for well over 20 years now.
My original request was for information on using the serial (specifically USB) ports under QB64PE, on a Linux based machine - not how to access the ports from Linux - thats easy. The reason is that I am working on an Eprom Programmer to support legacy systems, and for various reasons have been looking at using QB or its derivatives to generate the PC Controller application for this programmer. In the course of this, I found that using these ports via QB doesn't seem to be well supported, so I began to look into this. I found somewhere that there is a Serial library for QB, but couldn't find any details. so I thought I'd investigate the possibilities of producing a simple USB port library for QB, time permitting.
I appreciate the replies I have received, and everything is useful - I just think that given that USB ports are widely and universally used by almost all devices these days, it would be a useful asset to have.
|