Serial Comms in RISC OS Pico
Ben Newsam (3089) 13 posts |
I need to access two serial ports from a PI (but let’s start with just one!). There is no data output at all, but signals inwards are received either in a data byte or on certain control lines, namely DCD, DSR, CTS and RI. The reason for two ports is that up to 16 separate inputs might be required, and certain installations with fewer than 16 inputs use only the control lines on two separate ports. Sometimes the hardware may present itself as a single 9-pin serial connector, and sometimes as a USB plug. In either case, it will logically be the same as a serial COM port. I have been using RISC-OS Pico (for sheer speed and lack of overhead) Although not a requirement, I would like to use it on my project for its sheer simplicity and speed of booting. I have a Prolific USB-to-Serial Comm Port (as used in some of the devices I need to talk to) that reports itself on my PC as COM4 (so that’s simple enough), and in RiscOS Pico appears on the *USBDevices list as “Prolific Technology Inc. USB-Serial Controller D”. The trouble is that I have no idea how to use it. |
Rick Murray (539) 13385 posts |
As it is Prolific, as long as it is based upon the PL2303 chip, you can try: Read the spec as well, it explains the ioctl calls that do stuff like reading/setting the control lines. My weather station is unusual in that while it communicates using a slow serial connection on the Tx/Rx lines, it also uses two control lines to define the high and low voltages. Instead of having a real serial interface, it cheats by switching between the high and low as required to fake a serial bitstream. |
Colin Ferris (399) 1738 posts |
Is there a SerialDev driver for this USB_Serial module? |
Ben Newsam (3089) 13 posts |
As far as I can tell so far, if I have understood correctly, I need SerialUSB, which is not a module but a DeviceFS device driver, that needs to be installed using DeviceFS_Register and then accessed through the various DeviceFS SWI calls (using SYS from BASIC I assume). For accessing the control lines I should use OS_Arg IOCtl, but one thing at a time, I still don’t know how to work DeviceFS_Register, there are a number of things I don’t understand. The documentation states that on entry: R0 = global flags for devices: Questions: |
Colin (478) 2433 posts |
You just treat the device as a file. To open the file in BASIC
similarly for OPENIN. Then you use OS_GBPB to read/write the data taking note of the bytes actually written returned by OS_GBPB. Use CLOSE as normal to CLOSE the device. When reading you just have to poll OS_GBPB until data is read. |
Rick Murray (539) 13385 posts |
As Colin says, it is a lot like USB in that you use standard file handles passing some extra junk in the filename to specify the serial format! and then just read and write as appropriate. For my weather station, I use:
Then I use this to send single bytes:
I don’t know if the code developed from sending larger blocks, or whether there is a reason for preferring GBPB of single bytes over BPUT#, say. Can’t think it makes much difference in the long run. For reading data:
As it is noblock the call will return whatever is there, if anything. You will need to use OS_Args ioctl to read/set the control lines.
I have no example reading the control lines, as I don’t need to. I presume setting data%!4 to zero, specifying |
Ben Newsam (3089) 13 posts |
Many thanks to the two above for some great hints that will be useful as the project progresses. But I still need to install SerialUSB as a DeviceFS driver don’t I? That’s the bit I need help with, as I don’t know how to do it (see questions I asked earlier). |
Rick Murray (539) 13385 posts |
Plug in the (physical) serial device. Then load the SerialUSB module. If the (physical) device is recognised, there will be corresponding entry present in DeviceFS upon which you may open file handles. |
Ben Newsam (3089) 13 posts |
How do I load SerialUSB in Pico? It appears to be a device driver rather than a module, so cannot be RMLoaded. I think I need to use DeviceFS_Register, but I do not understand what parameters are required. |
Colin (478) 2433 posts |
You just RMLoad it just like any module. Once it is loaded if you plug in a device
should show a SerialUSB device. |
Ben Newsam (3089) 13 posts |
That doesn’t work, it says something like “This file is not a module”, which is what made me think it needed to be loaded as a device driver. If I try to OPENOUT a file, it creates an actual disk file that I cannot delete because it “contains a wildcard” (#). |
Steve Pampling (1551) 7921 posts |
I think your serialUSB module is not correctly filetyped. If you take a-n-other rubbish file and give it a filetype of “module” it reports “illegal header field in module” *settype serialusb ffa or *settype serialusb module will set the file type. |
Rick Murray (539) 13385 posts |
Um, guys? …surely it is a bug to have the filing system capable of creating a file containing a wildcard in the name? |
ronald-scheckelhoff (2262) 60 posts |
To whomever wrote the SerialUSB module that is downloadable from this link: http://ftpc.iconbar.com/usb/SerialUSB.zip Thanks! I have found that it works very well with RC15 from Apr/2017 on my Pi2, to display NMEA sentences from my BU353 GPS puck. Now I need to find some software to parse the sentences, and I’ll have a nice navigation ticker! |
ronald-scheckelhoff (2262) 60 posts |
Now that serial is working so well, I’m wondering about using it to connect to a Photon, and then use the Photon’s WiFi to connect to the internet. I have a pocket WiFi router, but don’t particularly like it. I know I could use another Pi as a bridge to WiFi, but that seems overkill. So the tiny Photon would add very little battery drain, and still allow internet access, albeit it’d be a bit slower. The photon’s code could be just an elaboration of this: https://docs.particle.io/reference/firmware/photon/#tcpclient Anyone thought about doing this, or something similar, with a photon or same-kind device? Part of the reason I don’t like the pocket router is that I can’t control its source code. I’d have full control over the Photon’s code. The reason I don’t want a bridge Pi is that (1) it adds battery drain, and (2) it’d be running Linux or FreeBSD when I want something closer to a straight RISCOS connection. |
Chris Hall (132) 3499 posts |
The reason I don’t want a bridge Pi is that (1) it adds battery drain, I have a Raspberry Pi plus GPS module and it would be nice to send a file using WiFi to a defined destination – currently only possible by adding a USB to internet dongle and a WiFi bridge. At present the current drain is 220mA: how much would the Photon add please? |
ronald-scheckelhoff (2262) 60 posts |
Hi Chris, Low power is the nice thing about the Photon. It’s anywhere from 30 mA when “full on” but WiFi off, to 80 mA with WiFi on, and 175 uA when sleeping. They’re pretty handy devices when a full blown Pi is not needed, but the lower powered arduino level stuff is insufficient. |
Chris Hall (132) 3499 posts |
Many thanks. The application I have in mind is a GPS unit, tracking its position and only turning the WiFi on when it knows it is near a WiFi receiver for the network concerned (a company one), sends a smallish text file and then turns WiFi off again. I have the GPS unit but am not sure how to send a file from the Pi to the Photon. The serial lines (RXDATA and TXDATA pins) are already in use for the GPS module using the Serial module in ROM but I could use the IIC if the Photon appears as an IIC device (but suspect it is the other way round). Perhaps the best way is if the Photon can appear as a USB pen drive with a spare GPIO line from the Pi to put it into and out of standby mode. |
ronald-scheckelhoff (2262) 60 posts |
Hi Chris: Doesn’t the Pi have 2 UARTS? I thought about the IIC thing myself. I know the serial works very well on RISCOS now, but have not yet tried the recent IIC addition. |
Chris Hall (132) 3499 posts |
Doesn’t the Pi have 2 UARTS? Yes but I don’t think that helps me. I currently use the GPIO RXDATA and TXDATA pins to talk to the GPS module at 9600 baud using the Serial module in ROM. If I can get the Particle Photon working I would want to use the SerialUSB driver to talk to the Photon via a USB to USB cable (which also powers it) to let the Photon upload the data via WiFi. Can I use both serial connections at the same time on the Pi please? |
Rick Murray (539) 13385 posts |
If I understand you correctly, you are asking if you can use the internal serial port (via OS_SerialOp?) and a USB one with the SerialUSB driver at the same time? If so – I don’t see why not. They might both be serial ports, but they are logically different devices… |
Chris Hall (132) 3499 posts |
you are asking if you can use the internal serial port (via OS_SerialOp?) and a USB one with the SerialUSB driver at the same time? Yes. If so – I don’t see why not. Excellent |