Resource manager and driver to plc AB SLC-504

I mean…

if I read a /dev/plc/0-20… N40:0 to N40:19 for example

with read(fd,buffer, sizeof(buffer)) I’m reading the entire block for 20 registers…

how do i do to read only the fifth or only the last register directly? with readblock should I?

lseek()? readblock would be ok but not portable.

But if I was a user of your driver I would read all the input at once. Here is why. As you might know, PLC operate on scan time basis. That means that before applying the logic it will read all the inputs, taking a snap shot of it. Then it will do the logic on an image of the input. I’m over simplifying…

The idea is that if you say read N40:0 do some process and then read N40:1, it is possible that N40:1 might have changed between the last time N40:0 was access breaking the relation ship the two might have (say a 32 bit value is made up of N40:0 and N40:1). That is why typically you’d want your read and write operation to be “atomic”. To kind of match how the PLC works.

you right, thanks a lot Mario.

Only for curiosity

How many device names can i attach?

I was doing a few ejercices. And I’m confused because I registered in an example 996 names and another one I registered 200.

If I try (first ejercice) to register 997 (one more) the resmgr_attach(number997) return -1. Ok?

Conclusion: I can´t have more than 996… BUT

if a run the second example with the 200 names, the names were registered. (I think that the result would be -1 since the first name)

Second Conclusion: Exist a attribute to limit the device names that are registered. So… where do i set this data?

am I right?

Yeah it’ss probably limited by the number of connection/fd per process. Check value of errno when resmgr_attach fails. I think you can increase it with option to proc*. That being said you really don’t want to do that. Too many will slow down every open operation because Proc will have to scan in a list of all possible path entires. What you want to do is attach /dev/plc and then deal with any “sub-directories” yourself. That doesn’t really add to much work, just have do deal with the special case of a read/open done on a subdirectories, which means someone is for example doing an ls on a subdirectories and want to know its content.

Check out aei.mpg.de/~peekas/tree/. It’s a lovely C++ class/template allowing for building of trees, perfect for something like sub-directories ;-)