/* functions that call the universal protocol commands */ /* <%Z%%M% %Q% sccs %I%> */ /**************************************************************************** io.c: Date Written: 11/3/95 Written by: John LaBatt Project: COMDEMO.MAK Purpose: These functions perform the interface with the universal protocol messages for the demo. ****************************************************************************/ #include #include #include #include /* for bios_keybrd() calls */ #include #include "comdemo.h" #include "udrive.c" /* Include the universal driver functions */ /* This function is called when the user wants to write one of the outputs */ /* It will make the appropriate UDriver call, depending on the active window */ void WriteVal(UD_CONT *ct) { int addr; char mask = 0x01; int value; float flt; char charfloat[4]; switch(activewindow) { case DO_WINDOW: /* find byte boundary and mask the offset from it for appropriate bit */ addr = curraddr[activewindow] - (curraddr[activewindow] % 8); mask = mask << (curraddr[activewindow] % 8); if (!strcmp(editstr,"1")) /* Turn the bit on */ set_d(ct,DEF_OUT,addr,8,&mask); else if (!strcmp(editstr,"0")) /* Turn the bit off */ clr_d(ct,DEF_OUT,curraddr[activewindow],8,&mask); break; case AO_WINDOW: /* convert string to a value and write it */ value = atoi(editstr); put_a(ct,DEF_OUT,curraddr[activewindow],1,&value); break; case FO_WINDOW: flt = (float)atof(editstr); /* convert string to a float */ /* convert float to 4 bytes */ memcpy(charfloat,&flt,4); put_b(ct,FLT_OUT,curraddr[activewindow],4,charfloat); break; } /* Reset the editstr to NULL */ strcpy(editstr,"\0"); } /* This function is called as often as possible to update the data on the */ /* screen. It reads the values for all six types displayed in the demo. */ /* The function also checks if a key was pressed after each driver */ /* message to help speed the response. */ void ReadVals(UD_CONT *ct) { int udr_good; /* For return values of udr commands */ int j; char flts[MAX_FLOAT * 4]; float *pfloat; /* Read all of the discrete values */ udr_good = get_d(ct,DEF_IN,0,MAX_DISCRETE,discrete_in); if(_bios_keybrd(_KEYBRD_READY)) ProcessKey(ct); udr_good = get_d(ct,DEF_OUT,0,MAX_DISCRETE,discrete_out); if(_bios_keybrd(_KEYBRD_READY)) ProcessKey(ct); /* Read all of the analog values */ udr_good = get_a(ct,DEF_IN,0,MAX_ANALOG,analog_in); if(_bios_keybrd(_KEYBRD_READY)) ProcessKey(ct); udr_good = get_a(ct,DEF_OUT,0,MAX_ANALOG,analog_out); if(_bios_keybrd(_KEYBRD_READY)) ProcessKey(ct); /* Read all of the float values */ udr_good = get_b(ct,FLT_IN,0,MAX_FLOAT * 4,flts); if (udr_good == TRUE) { for (j=0;j