Welcome, Guest. Please login or register.

Author Topic: Amigas as dataloggers and controllers  (Read 1932 times)

Description:

0 Members and 1 Guest are viewing this topic.

Offline Heinz

  • Full Member
  • ***
  • Join Date: Nov 2005
  • Posts: 154
    • Show all replies
    • http://amidevcpp.amiga-world.de
Re: Amigas as dataloggers and controllers
« on: March 29, 2008, 12:28:13 AM »
Quote

Tenacious wrote:

Does anyone have experience accessing the parallel, serial, and game ports from within a basic program?  I want to move data into and out of these ports.

Thanks Again


You will probably not find much information of accessing Hardware from Basic programs.
It is possible as long as the basic can access the system API.

But using C as programming language is a lot better when it comes to Hardware access.

Here is a simple Example Program that opens the parallel.device and send a string of data to it.

Code: [Select]

#include <stdio.h>
#include <stdlib.h>
#include <proto/exec.h>
#include <devices/parallel.h>

int main(int argc, char *argv[])
{
 
  struct IOExtPar * Parallelport;
  struct MsgPort * ParallelMsgPort;
  BYTE Returnvalue;
 
  if(ParallelMsgPort = CreateMsgPort())
  {
    if(Parallelport = (struct IOExtPar *) CreateIORequest(ParallelMsgPort, sizeof(struct IOExtPar)))
         {
            Parallelport->io_ParFlags = PARF_SHARED;
         }
    else
    {printf(&quot;CreateIORequest failed\n&quot;);}
  }
  else
  {printf(&quot;CreateMsgPort failed\n&quot;);}
 
  printf(&quot;Open Parallelport...\n&quot;);
 
 
  Returnvalue = OpenDevice(&quot;parallel.device&quot;,0L,(struct IORequest *)Parallelport,0);
   
  if(Returnvalue == 0)
  {
          printf(&quot;Opening Parallel Port successful\n&quot;);
  }
  else
  {
           printf(&quot;An Error accured.\n&quot;);
  }
   printf(&quot;Press any key to send Data...\n&quot;);
   
   Parallelport->IOPar.io_Length   = -1;
   Parallelport->IOPar.io_Data     = (APTR)&quot;Parallel lines cross 7 times...&quot;;
   Parallelport->IOPar.io_Command  = CMD_WRITE;
   DoIO((struct IORequest *)Parallelport);        
   
    printf(&quot;Any key to quit...\n&quot;);
    getchar();
 
  CloseDevice((struct IORequest *)Parallelport);
 
  DeleteMsgPort(ParallelMsgPort);
  DeleteIORequest((struct IORequest *)Parallelport);
 
  printf(&quot;Any key to quit...\n&quot;);
  getchar();
  return Returnvalue;
}