st599
Posts: 28
Joined: Mon Sep 05, 2011 1:29 pm

Re: Version C?

Mon Nov 14, 2011 9:48 am

Surely it would be a Raspberry Pi Master next. Otherwise your naming convention is screwed.

UberEEE
Posts: 7
Joined: Fri Sep 09, 2011 12:55 pm

Re: Version C?

Mon Nov 14, 2011 10:20 am

Obarthelemy said:
It does, as an example of how Linux doc is lacking, and cannot be relied on for the simplest stuff, which reinforces how important it is for the Pi community to come out with noob-friendly docs and tutorials.

IMHO with Linux the documentation DOES exist. Unfortunately it always feels to be spread out across various sources. If I have an issue with my server (Fedora) I know that the answer is available somewhere the issue is finding it (a recent example being setting it up as a DLNA server - spent couple of nights playing, drinking & resolved it.)

To me as a hobbyist it adds to the fun, disseminating instructions & pulling out what is relevant. I appreciate that when something needs to be done this is not the most efficient way of working.

For the Raspi to be of any use educationally we need to make sure there are bomb proof instructions for what we are aiming to achieve with it. Teacher have not got the time (or potentially inclination) to sit & play ith something for hours before guaranteeing that it will work.

Sorry end of rant

User avatar
Jongoleur
Posts: 1179
Joined: Thu Aug 11, 2011 12:47 pm
Location: O'erlooking the sea, and all those effin windfarms...

Re: Version C?

Mon Nov 14, 2011 12:30 pm

Documentation for Linux is, as has been noted, a can of worms. This is mainly down to the multiplicity of distros, each of which has its own preferred way of doing things and locating system files and scripts. Its won't be easy for the Foundation to cover the bases for all possible distros; its even more difficult to divine what problems people will want to solve.

What we have to remember is that the forthcoming Mk1 release is aimed at hobbyists and those who consider themselves technical experts. I would expect this class of user to be perfectly capable of rooting around in a standard ARM distro and ferreting out the necessary info.

By time we get to the "Education" release, sometime next year, I'd expect a distro to be nailed down and be usable from initial plugin. No setup (apart from perhaps "what is your name" style personalisation) and typical software application icons already set up on the desktop, with more stuff available from the menu system. That's be bombproof, in the sense that no instructions, beyond a slip of paper saying what plugs into where, should be needed.
I'm just a bouncer, splatterers do it with more force.....

hippy
Posts: 9213
Joined: Fri Sep 09, 2011 10:34 pm
Location: UK

Re: Version C?

Mon Nov 14, 2011 12:45 pm

Quote from UberEEE on November 14, 2011, 10:20
For the Raspi to be of any use educationally we need to make sure there are bomb proof instructions for what we are aiming to achieve with it.

Absolutely, and that also applies to many who are simply not familiar with Linux or its tools. The most frequent problem I find is that knowledge is required but that knowledge is hard to gain; it creates a Catch-22 that is difficult to resolve. "Grab the source and recompile" may mean something to a Linux expert but that's not so simple for someone with lack of experience. "RTFM" is often "if you can't figure it out yourself then tough" - That's not the way to win newbie converts to Linux or anything.

I have a Linux-based NAS ( non-X86 CPU ) with USB host ports which can use PL2303 USB serial cables but I wanted to use FTDI serial cables. Those drivers are purportedly part of the kernel but they are not on this NAS. Trying to get installable drivers runs into the brick wall response; "you don't need to, they are included in the kernel". Second best is "grab the source and compile it", which I'd already figured as a solution, but where is the source, where are the tools, how are they setup and used, what other prerequisites are there, where are those found and how are they configured ? And this has to be for non-X86, right.

This was all while trying to find out how to open a serial port, read 8-bit raw data bytes while being able to detect and differentiate a break signal on which I found little useful.

In the end I gave up, used an Atom PC running Windows with a simple VB app and got the whole job done in less than half a day, no more than a dozen lines of code, and using the FTDI cable.

I sincerely hope that using an R-Pi doesn't prove to be as frustrating as it was in that effort to get a really simple project up and running.

AlanCox
Posts: 31
Joined: Thu Nov 10, 2011 7:11 pm

Re: Version C?

Mon Nov 14, 2011 3:42 pm

Well the sources and config for the NAS kernel will have been supplied by the vendor as it's GPL licensed.

The serial port management is not even Linux specific, its documented in the standards documents and is POSIX/SuS standards compliant (ie its the same as most things except Windows)

It's a case of what you know - it would take me a month to do it in VB, but 2 minutes in Linux 8)

hippy
Posts: 9213
Joined: Fri Sep 09, 2011 10:34 pm
Location: UK

Re: Version C?

Mon Nov 14, 2011 7:21 pm

Quote from AlanCox on November 14, 2011, 15:42
Well the sources and config for the NAS kernel will have been supplied by the vendor as it's GPL licensed.

I recall one of the problems there was, because the FTDI drivers were not included in the kernel, the source wasn't included in the release.

Quote from AlanCox on November 14, 2011, 15:42
The serial port management is not even Linux specific, its documented in the standards documents and is POSIX/SuS standards compliant (ie its the same as most things except Windows)

It's a case of what you know -


That is the crux; there's often a divide between all the information being available and being able to find it, use it, having helping hands to explain and guide when necessary.

I'll willingly admit that there was just so much required to do, and so much to have to learn, that it just wasn't realistic compared to the alternative of using something I was more familiar with. I'm also far happier when having a working example which I can both use and expand, and work back from to understand why the code is as it is.

Quote from AlanCox on November 14, 2011, 15:42
it would take me a month to do it in VB, but 2 minutes in Linux 8)


If it is that easy then I'd be very grateful if you ( or any kind soul ) could spare that few minutes because it would help me and I'm also sure it would be very useful for others wanting to do serial comms and would like some concrete working example to build upon.

The spec is blindingly simple - Open a serial port, eg "/dev/ttyUSB0" and that can be hard-wired into the code, for every 8-bit byte received display its value, output to console or a window, whenever a break signal is detected display "BREAK". Anything typed gets sent out the serial port. The only real requirement beyond that is can be compiled to run on an R-Pi !

I don't know if it helps any but in VB6 with MScomm32 and TextBox controls on a form ...

Private Sub Form_Load()
MSComm1.CommPort = 1
MSComm1.Settings = "9600,N,8,1"
MSComm1.RThreshold = 1
MSComm1.PortOpen = True
End Sub

Private Sub Form_Unload(Cancel As Integer)
MSComm1.PortOpen = False
End Sub

Private Sub MSComm1_OnComm()
Dim rxData$
Dim i&
Select Case MSComm1.CommEvent
Case comEvReceive
rxData$ = MSComm1.Input
For i& = 1 To Len(rxData$)
Text1.Text = Text1.Text + Str$(Asc(Mid$(rxData$, i&, 1)))
Next
Case comEventBreak
Text1.Text = Text1.Text + " BREAK"
End Select
End Sub

Private Sub Text1_KeyPress(KeyAscii As Integer)
MSComm1.Output = Chr$(KeyAscii)
End Sub

tufty
Posts: 1456
Joined: Sun Sep 11, 2011 2:32 pm

Re: Version C?

Mon Nov 14, 2011 9:02 pm

Totally untested, but something like this will probably do it. Note that we have to roll our own event loop using select() - it's easy enough, you set up a set of selectors to watch for events (in this case, having input) and then wait for that to happen.

Couldn't be arsed to work out what you mean by "break", but it should put out square bracket pairs for unprintables.

Oh, and it's not unicode-clean. But neither's yours :)

[edit] needed O_NONBLOCK, forgot that.
#include <fcntl.h>
#include <sys/select.h>

#define STDIN 0
#define STDOUT 1
#define STDERR 2

int main(int argc, char ** argv) {
// Take first argument (second, actually, first is program name as invoked) as name of serial port.
// No error checking. Naughty me.
// Open the port. That's the easy bit.
int serial = open(argv[1], O_RDWR | O_NONBLOCK);

// You've been nasty and used a preexisting event loop. We have to roll our own, and it's ugly.
// This is not a beginner exercise, despite you thinking it is.
fd_set fds;
struct timeval tv;

// Set up a set of file descriptors to watch
FD_ZERO(&fds);
FD_SET(STDIN, &fds); // 0 is the standard file desscriptor for stdin
FD_SET(serial, &fds);

// Do this forever
while(1) {
unsigned char buf;
// Set up a wait period (we'll quit after 10 seconds of inactivity)
tv.tv_sec = 10;
tv.tv_usec = 0;
// wait nicely for a descriptor to have data
int v = select (2, &fds, 0, 0, &tv);
switch (v) {
case -1:
exit(-1); // Buggeration, there was an error
case 0:
// timed out.
exit(0);
default:
// We have data.
if (FD_ISSET(STDIN, &fds)) {
// This is not the most efficient way of echoing output, but who cares
read (STDIN, &buf, 1); // read one byte
write(serial, &buf, 1); // and write it out
} else {
read (serial, &buf, 1); // read one byte
if (isprint(buf)) { // Is the character printable?
write(STDOUT, &buf, 1); // write it out
} else {
write(STDOUT, "[]", 2);
}
}
}
}
}

hippy
Posts: 9213
Joined: Fri Sep 09, 2011 10:34 pm
Location: UK

Re: Version C?

Tue Nov 15, 2011 12:42 pm

Many thanks tufty that is very useful. With a bit of tweaking I've got it cross-compiling under Windows using the CodeSourcery G++ Lite compiler, so thanks to yourself and Scribe things are coming together ...

http://blog.quickforge.co.uk/2.....ributions/

Break signal reception ( a sort of deliberately forced framing error ) seems to use SIGINT signalling so will have to investigate that.


// This is not a beginner exercise, despite you thinking it is.


I suppose that really depends on choice of programming language; with VB it's pretty easy and I would classify it as near beginner level with that, but you're right, there is more that needs to be done with C and it was finding all that which had me stumped, and a real newbie would likely stand no chance.

This is an issue I find with teaching programming and choice of language; that it's not so much what the language is, but how easy it is to use a language and components / objects / libraries to get the desired result. It would be interesting to see if the same can be achieved and how easily in Python, Ruby and other proposed teaching languages.

Return to “General discussion”