Peek and Poke

I’m new to Xojo but I would like to use it to control my brother’s model railway layout. This requires me to talk to some hardware so I need to access ports and memory addresses. In the old Basic there were commands such as Peek and Poke. Has anyone any idea how to simulate these commands in Xojo?

There are no Peek and Poke equivalents which could be used to access hardware - the approach you take rather depends on how you want to control the railway…

If it is not DCC control, but you want to use ADCs, relays etc
or
If it is DCC but you want to do all the hard work yourself…
then you probably would be best using an intelligent control board, such as an Arduino to control the hardware
( Google Arduino DCC for some hints ) and you could interface your XOJO app to that device via Serial coms for the UI /control side.

If it is DCC and you want to use a commercial controller, the simplest / cheapest one I know is the SPROG…
SPROG DCC controller
which also conects to the host computer via Serial ( the USB version simply has a USB to Serial converter built in )

Many other commercial controllers connect via Serial ( or USB->Serial )

I did some tests, a year or so ago, connecting to a SPROG, from XOJO and it works just fine - and I have built and run the program on all 3 platforms.

maybe you can do something by sending USB commands to a little USB device which connects to the controls?

Peek & Poke? Reminds me back in those Commodore 64 times :wink:
I would suggest a Raspberry Pi for those tasks, accessing it via Web SOAP/TCP Sockets by Xojo.

I recall those BASIC commands, but I make a Google quest and do not found an occurence in page 1. I do not go to any other page.

Back to the original question:

where do you want to Peek and Poke ?

In old BASIC, it where in Memory. If I want to guess, I would say you want to do that in a “storage can” in memory. If so, how do you load / deals with that ?

Other part of the answer is:

Create a MemoryBlock with the needed size, and Peek / Poke in that MemoryBlock.

Address of MemoryBlock in docs: MemoryBlock .

BTW: if my memory is correct, Peek and Poke was also used to trigger some logical commands in ROM (or elsewhere). This is so many years that I start to forgot everything from these times (70s / 80s).

WikipediA have an article about AppleSoft BASIC .

I tried to understand the question before trying to give an answer.

The Apple IIc came with an example program called Poker that was no game : one could change the value of any place in memory and then retrieve it through Peek.

The Sinclair Z-8x series made heavy use of pokes to garner REM comments with machine language programs later run at the speed of light, with often unpredictable crashes or strange results.

I can just imagine the hands in the air from antivirus programs if one was to use such techniques today :wink:

Wow. Did I set my TARDIS to the correct time/era when I landed this morning? :slight_smile:

This brings back memories. I bet most young programmers today have no idea of what peek and poke even did. But then again, with today’s far more highly developed language there’s no need to access specific memory locations at such a low level. I remember one of the most common uses for peek and poke was to affect graphics on the screen. Change a bit in memory and you would change a pixel on the screen, etc. Now today we have graphic controls like Canvases and Image wells that do all the hard work for you.

If you need to access the hardware - it’s being done by some sort of interface - right? Likely RS-232 or some I/O card. The I/O card should have an API for using it, RS-232 is simple to use, etc.

No need to access hardware locations in memory on the computer…

I do not recall that one. Maybe in the first Apple //c ?

Could be. I had both, so I may have forgotten.

I remember that Transylvania adventure program, too, and the example menu with “Gloubi-Boulga à la Michel” :wink:

Thanks everyone for your feedback. I’m going to investigate another route.

At best memory block & ptr but trying to write outside your process address space is likely to just the the app killed by the OS

What OS are you planning to do this from? If Windows, you can use some API Declares for this… this example was written in VB, but should be easy to port to Xojo:

http://www.planetsourcecode.com/vb/scripts/ShowCode.asp?txtCodeId=39808&lngWId=1