Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

Digital I/O

Posted on 1998-12-04
7
275 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
Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

 
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 300 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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

Suggested Solutions

Often, when implementing a feature, you won't know how certain events should be handled at the point where they occur and you'd rather defer to the user of your function or class. For example, a XML parser will extract a tag from the source code, wh…
Introduction This article is a continuation of the C/C++ Visual Studio Express debugger series. Part 1 provided a quick start guide in using the debugger. Part 2 focused on additional topics in breakpoints. As your assignments become a little more …
The goal of the tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…
The viewer will learn how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.

790 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