?
Solved

Digital I/O

Posted on 1998-12-04
7
Medium Priority
?
281 Views
Last Modified: 2008-02-01
I'm writing an application using Borland's C++ Builder.  I've used the DCB structure in the past for serial communications, but how do I handle hardware devices such as digital/analog cards?  I'm using a CIO-DIO48 which has 48 digital inputs and a CIO-DAS16 which has 16 digital outputs.  I can easily write a DOS appl using outportb and inportb to send and receive bytes, but these aren't compatable with Builder.
What resources are there that will allow me to read the digital inputs and write to the digital outputs?
0
Comment
Question by:schmim04
  • 2
  • 2
  • 2
  • +1
7 Comments
 
LVL 14

Expert Comment

by:AlexVirochovsky
ID: 1179222
Can you use Windows API: OpenComm, WriteComm, ReadComm ? If can , this is solution. I not, you can tray
OpenFile/_lopen to "COM1"/"LPT1" and standart
read/write functions.
0
 
LVL 86

Expert Comment

by:jkr
ID: 1179223
Specialized I/O boards usually come with a device driver that makes the hardware accessible through a defined interface...
As you mentioned C++ Builder, i assume your target platform is Win32. There, the device is usually exposed through a driver which is accessible via 'CreateFile()'. After obtaining a file handle through this function call, you'll have to use 'DeviceIoControl()' using special control codes (see the boards' documentation) to read/write data from/to the device.
0
 
LVL 1

Author Comment

by:schmim04
ID: 1179224
Thank you for the function you mentioned.  I never saw it before.  However your response doesn't get me anywhere.  The one card has 48 digital inputs and a base address of 300h.  There are 6 8-bit ports on this card which exist at this base address plus some number.  I need to be able to read these ports on an individual basis (if possible), (or does the function just read them all each time?) and I don't see any functions that would allow this.  What if the boards documentation doesn't say which control code to use off the list?  If there is a way, please tell.    
0
The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

 
LVL 1

Author Comment

by:schmim04
ID: 1179225
Adjusted points to 300
0
 
LVL 86

Expert Comment

by:jkr
ID: 1179226
Well, is there _no_ driver plus documentation shipped with the board???
0
 
LVL 14

Expert Comment

by:AlexVirochovsky
ID: 1179227
Hi. Thid part of My programm test COM1/COM2 and
 read/write in case, that connectionb exists.
 Programm works with Kass(Kupa) and Weight(Mishkal).
 This is only my case, and can be
  szInitCupa or szInitMishkal you must set other,
  by Doc of you controller.
 Alex

static int idComDev[2] ={ -1,-1};      //no!
static DCB  dcb;
static int nPortMishkal = -1;
static int nPortCupa = -1;
#define MAX_LEN_INPUT    81
/*=========================================================================*/
/*  Name       : DefineController                                 */
/*  Parameters : None                                                        */
/*  Return     : None                                             */
/*=========================================================================*/
void DefineController(void)
{
  int err;
  char
    *szInitCupa    = "COM%d:9600, N, 8, 1",
    *szInitMishkal = "COM%d:1200, E, 8, 1";
 char buff[MAX_LEN_INPUT];            //Com Command

  for (int i = 0; i < 2;i++)
    if (idComDev[i] >= 0)            //Post opened?
      {
      CloseComm(idComDev[i]);      //close
      idComDev[i] = -1;            //no!
      }
      //read from ini File port of Weight(default 1)
  UINT bMishkal  = ReadSpsModeInt("Main", "PortMishkal",1);
      //read from ini File port of CASS(default 2)
  UINT bCupa  = ReadSpsModeInt("Main", "PortCupa",2);
  if (bMishkal >= 1 && bMishkal <= 4)
    nPortMishkal = bMishkal;
  if (bCupa >= 1 && bCupa <= 4)
    nPortCupa = bCupa;
  if (nPortCupa == nPortMishkal && nPortMishkal != -1)
    nPortMishkal = -1;                  //error
                              //mishkal
  if ( nPortMishkal > 0)
    {
      wsprintf(buff, "COM%d", nPortMishkal);
      idComDev[0] = OpenComm(buff,MAX_LEN_INPUT , MAX_LEN_OUTPUT);
      if (idComDev[0] >= 0)  //open?
      {
        wsprintf(buff, szInitMishkal,nPortMishkal);
        err = BuildCommDCB(buff, &dcb);
        if (err >= 0)
          err = SetCommState(&dcb);
        if (err < 0)                        //Error?
          {
            CloseComm(idComDev[0]);
            idComDev[0]  = -1;
          }
       }
      if (idComDev[0] >= 0)            //OK?
      TestMishkal(idComDev[0]);
    }
                              //Cupa
  if (nPortCupa > 0)
    {
      wsprintf(buff, "COM%d", nPortCupa);
      idComDev[1] = OpenComm(buff,MAX_LEN_INPUT , MAX_LEN_OUTPUT);
      if (idComDev[1] >= 0)  //open?
      {
        wsprintf(buff, szInitCupa,nPortCupa);
        err = BuildCommDCB(buff, &dcb);
        if (err >= 0)
          err = SetCommState(&dcb);
        if (err < 0)                        //Error?
          {
            CloseComm(idComDev[1]);
            idComDev[1]  = -1;
          }
       }
    }
} // end DefineController
void TestMishkal(int &idComDev)
{                              //send acknoledge
  char buff[MAX_LEN_INPUT];            //Com Command
  memset(buff, 0, sizeof(buff));
  buff[0] = buff[19] = 7;
  int err = WriteComm(idComDev,buff,20);
  if (err >= 0)                  //OK!
    {
      long lTime0,lTime1;

      time(&lTime0); lTime1 = lTime0; // delay
      while(lTime1 < lTime0+2) time(&lTime1);

      memset(buff, 0, sizeof(buff));
                                    //read reaction
      err = ReadComm (idComDev,buff,20);
      if (*buff == 0)
      err = -1;
      else if (err >= 0 && !TestCheckSum(buff))//test: must be from R
      err = -1;
      if (err < 0)             //close Bennet
      {
        CloseComm(idComDev);
        idComDev = -1;      //no!
      }
      if (err >= 0)                  //for next weight
      WriteComm(idComDev,buff,20);
    }
}

0
 
LVL 2

Accepted Solution

by:
ivi earned 600 total points
ID: 1179228
It is a standard answer:

1. Use a software shipped with your board
2. Write your own device driver
3. Use a commercial tools named WinRT from Blue Water Systems
4. Use shareware TVicHW32 for Delphi/BCBuilder/VB/C++
0

Featured Post

The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Templates For Beginners Or How To Encourage The Compiler To Work For You Introduction This tutorial is targeted at the reader who is, perhaps, familiar with the basics of C++ but would prefer a little slower introduction to the more ad…
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
The viewer will learn how to pass data into a function in C++. This is one step further in using functions. Instead of only printing text onto the console, the function will be able to perform calculations with argumentents given by the user.
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.

589 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question