Amiga.org
Operating System Specific Discussions => Amiga OS => Amiga OS -- Development => Topic started by: motorollin on May 23, 2006, 04:26:21 PM
-
I have a parallel port relay board which I want to control with my Amiga. I have seen applications on Aminet for controlling these, but I want something I can run from the CLI. The application itself (I think) just sends a single byte of data to the port, with each bit representing one of the 8 relays. So I need a way to send a single byte to the Amiga's parallel port.
I have the source code of the Linux version of the relay board control software, and have found what I believe to be the portion of the code which sends the actual data to the port:
void out_byte(int port, unsigned char byte)
{
off_t s;
int r;
s = lseek(dev_port_fd, port, 0);
if (s < 0) perror("lseek");
else if (s != port)
fprintf(stderr, "hmmm: seeking to %d, went to %ld.\n", port, (long)s);
r = write(dev_port_fd, &byte, 1);
if (r != 1)
{
fprintf(stderr, "hmmm: write returned %d\n", r);
if (r < 0) perror("write");
}
}
What I don't know is how to adapt this for the Amiga. Hopefully someone can point me in the right direction.
--
moto
-
Ok I found pario on Aminet, and have cobbled together the following from the example code:
#include "pardemo.h"
void main(void)
{
UBYTE data; /* Port I/O data */
LONG error = 0; /* Error code on exit */
#ifdef AZTEC_C
#endif
getport();
portdir(1);
datatype = HEX; /* Only write if at least one bit */
data = GetData(choice); /* dir set to output */
wrport(data);
freeport();
}
I have no idea if this would work. Can anybody who is familiar with the pario routines let me know if this looks ok?
If this does work, I need to replace the getdata() command with something which will read the data variable from an argument. I'll cross that bridge once I've got port routines working :-)
--
moto
-
Want something reeeeeaaaaaally simple ?
Create a file only containing 1 byte (you may need a hex-editor to manipulate that byte), and then type:
copy myfile to par:
*clack* *clack* :-D
Or if in C (untested but should work, and if with every compiler):
char c = 0xf3;
FILE *file;
file = fopen("PAR:","w");
putc(file,c);
fclose(file);
Done from memory, typos or under international copyright
-
Kronos wrote:
Create a file only containing 1 byte (you may need a hex-editor to manipulate that byte), and then type:
copy myfile to par:
That's much easier - but I would need a way of creating the file from the command line, rather than from a hex editor. Any thoughts?
Kronos wrote:
Or if in C (untested but should work, and if with every compiler):
char c = 0xf3;
FILE *file;
file = fopen("PAR:","w");
putc(file,c);
fclose(file);
Looks like a C version of the same thing? Much simpler than what I wrote! Do I need to #include anything for this to work, or can I just put it in my main void? Also, are there any free C compilers for the Amiga?
Thanks!
--
moto
-
You'll need to atleast include stdio.h.
GCC is available for Amiga, you may need to google a bit.
-
Oh, and about that other idea:
"echo "blabla" >par:" would also work (you may need to replace "blabla" with some escape-sequence in order to send unprintable bit-combination (and no I don't know the next best thing about escape-sequences).
-
I tried your idea of creating a file and copying it to PAR:. I created a file in a hex editor containing just the byte "00" and saved it. I then copied it to PAR:, and all the relays turned off. Unfortunately, the copy command never returned and I couldn't break it, which locked the parallel port. This happened every time I tried it. The only way to allow further access to the parallel port was to reboot. I'm guessing the C programme would cause the same problem as it is doing the same thing by copying a byte to PAR:.
Do I perhaps need to pad the data I send to the port, so the first byte controls the relays and the rest is padding? If so, then how much data does the port read at a time?
--
moto
-
CRTL-C should do the trick.
You may also try a bigger file, if it just switches once the HW is missing some sort of handshake, if it goes to the end it's copy which doesn't return cleanly.
In that case you could try other commands (echo,type etc) which can also be used to send files to par:
BUT in I personaly send several times files to ser: that way without copy getting blocked (unless the receiving computer wasn't listening, in which case CTRL-C worked just fine).
-
I tried CTRL-C but it didn't break the command. I'll try echo instead and let you know if it works.
Thanks
--
moto
-
Echo did the same thing :-( The command failed to return, which locked PAR:. CTRL-C didn't work, neither did opening a new shell and using break to end the process.
I think I need to write an app in C (or ASM???) with proper routines to open the port, send a byte, and then close the port. Unfortunately I have no experience in C or ASM, though I learn languages quickly. Guess I'll have to give it a try :-)
--
moto
-
i started working up some schematics for a parallel port relay setup but i was setting up partial 8bit decoding for more relays.
where can you get an 8 relay one or schematics for one. i was using relays for 12volt motor control mostly for robotics and tinkering.
-
Not sure I can get to a working Amiga to make this for you, but the RKMs have a demo of talking to the parallel port that should help you out. For what you are trying to do, I would use a command variable input which would allow you to put 00 through FF as the input, convert it to binary and sent the byte out the port. The advantage of that is you can use it from a script or from Arexx with the tool itself being pretty simple.
-Tig
-
@motorollin
Have yout tried this (http://uk.aminet.net/hard/misc/ParPortTst.readme) ?
Mom and Dad, I love you, please sell me to Paris Hilton.
-Kronos ;-)
-
Hi, just had a look at it. It appears to be a Workbench app rather than CLI. I need a CLI app so I can use it in a script.
--
moto
-
motorollin wrote:
Unfortunately I have no experience in C or ASM, though I learn languages quickly. Guess I'll have to give it a try :-)
AmiBlitz to the rescue ;-)
;-- Parallel port Blitz example..
;-- No more stupid Poking/peeking...
;-- remember to use all.res !
NEWTYPE .byte
b.b
End NEWTYPE
*PPort_Dir.byte = $BFE301
*PPort_Bits.byte = $BFE101
If AllocMiscResource_(#MR_PARALLELPORT,"MyAppName") = 0
*PPort_Dir\b= %11111111 ; set all bits direction to output
;-- Ready to rock and roll..
*PPort_Bits\b=%01010101 ; set the little buggers
FreeMiscResource_ #MR_PARALLELPORT
Else
NPrint "Crap, somethings already got the port :("
EndIf
End
-
Now that's more like it - Basic should be much easier :-) I assume I can compile with this (http://www.aminet.net/package.php?package=dev/basic/amiblitz_ful.lha)?
--
moto
-
AFAIK, the latest complete archives are at amiforce.de (http://www.amiforce.de/amiblitz/ab_downloads.php)
-
Cool, gonna try it tomorrow :-) Can I just paste the code you gave me in to Blitz and execute it, or do I have to include stuff?
--
moto