Changeset 10049


Ignore:
Timestamp:
Nov 9, 2010, 8:36:18 AM (10 years ago)
Author:
ogrimm
Message:
Large number of changes
Location:
fact/BIASctrl
Files:
2 added
2 deleted
5 edited

Legend:

Unmodified
Added
Removed
  • fact/BIASctrl

    • Property svn:ignore set to
      BIASctrl
      Dep.d
  • fact/BIASctrl/BIASctrl.cc

    r9917 r10049  
    1111#include <stdio.h>
    1212
    13 #include "ProcessIO.h"
     13#include "User.h"
    1414
    1515#include <readline/readline.h>
     
    8484 
    8585  // Construct main instance
    86   static ProcessIO M;
     86  static User M;
    8787 
    8888  // These signals were set during construction of EvidenceServer
  • fact/BIASctrl/Crate.cc

    r9917 r10049  
    66
    77#include "Crate.h"
    8 #include "ProcessIO.h" // Must be not in HV.h to avoid problem with declaring class ProcessIO
     8#include "User.h" // Must not be in header file to avoid problem with declaring class User
    99
    1010using namespace std;
     
    1313// Constructor
    1414//
    15 Crate::Crate(string CrateName, int Number, class ProcessIO *PIO) {
     15Crate::Crate(string CrateName, int Number, class User *PIO) {
    1616   
    1717  struct termios tio;
     
    7878  if(fDescriptor != -1) {
    7979    SystemReset();
    80     close(fDescriptor);
     80    if (close(fDescriptor) == -1) m->PrintMessage("Error closing device %s (%s)\n", Name, strerror(errno));;
    8181  }
    8282
     
    9292int Crate::Communicate(unsigned char* wbuf, int Bytes) {
    9393
    94   unsigned char rbuf[3];
    9594  int N, Ret = 0;
    9695  fd_set SelectDescriptor;
     
    117116        goto ExitCommunicate;
    118117  }
     118
    119119  // Time-out expired?
    120120  if (!FD_ISSET(fDescriptor, &SelectDescriptor)) {
     
    124124
    125125  // Read data   
    126   if ((N = read(fDescriptor, &rbuf, 1)) == -1) {
     126  if ((N = read(fDescriptor, ReadBuffer, sizeof(ReadBuffer))) == -1) {
    127127    m->Message(m->ERROR, "Read error (%s)", strerror(errno));
    128128    ErrorCount++;
     
    130130  }
    131131
    132   // === Update status information if three bytes were returned ===
     132  // === Check wrap counter if three bytes were returned ===
    133133  if (N == 3) {
    134     // This data only valid for channel set or channel read
    135         LastCurrent = rbuf[1] + (rbuf[0]&15)*256;
    136         LastOC = rbuf[0] & 128;
    137         ResetHit = rbuf[2] & 128;
    138 
    139         // Check wrap counter
    140134        if (WrapCount != -1) {
    141           if ((WrapCount+1)%8 == ((rbuf[0]>>4) & 7)) WrapOK = true;
     135          if ((WrapCount+1)%8 == ((ReadBuffer[0]>>4) & 7)) WrapOK = true;
    142136          else WrapOK = false;
    143137        }
    144         WrapCount = (rbuf[0]>>4) & 7;
     138        WrapCount = (ReadBuffer[0]>>4) & 7;
    145139        Ret = 1;
    146140  }
     
    148142  // === UnLock file descriptor ===
    149143  ExitCommunicate:
    150   if (lockf(fDescriptor, F_LOCK, 0) == -1) {
    151         m->Message(m->ERROR, "Failed to lock file descriptor (%s)", strerror(errno));
     144  if (lockf(fDescriptor, F_ULOCK, 0) == -1) {
     145        m->Message(m->ERROR, "Failed to unlock file descriptor (%s)", strerror(errno));
    152146        return 0;
    153147  }
     
    191185   
    192186  if ((ret = Communicate(wbuf, 3)) == 1) {
    193         Current[Board][Channel] = LastCurrent;
    194         OC[Board][Channel] = LastOC;
     187        Current[Board][Channel] = ReadBuffer[1] + (ReadBuffer[0]&15)*256;
     188        OC[Board][Channel] = ReadBuffer[0] & 128;
     189        ResetHit = ReadBuffer[2] & 128;
    195190  }
    196191  return ret;
     
    213208  if ((ret = Communicate(wbuf, 3)) == 1) {
    214209        for (int i=0; i<MAX_NUM_BOARDS; i++) {
    215       for (int j=0; j<NUM_CHANNELS; j++) DAC[i][j] = SetPoint;
     210      for (int j=0; j<NUM_CHANNELS; j++) {
     211            DAC[i][j] = SetPoint;
     212                Volt[i][j] = (double) SetPoint / 0xfff * 90;
     213          }
    216214        }
    217215  }
     
    243241  if ((ret = Communicate(wbuf, 3)) == 1) {
    244242    DAC[Board][Channel] = SetPoint;
    245         Current[Board][Channel] = LastCurrent;
    246         OC[Board][Channel] = LastOC;
     243        Volt[Board][Channel] = (double) SetPoint / 0xfff * 90;
    247244  }
    248245  return ret;
     
    270267    for (int j=0; j<NUM_CHANNELS; j++){
    271268      DAC[i][j] = 0;
    272       //Volt[i][j] = 0.0;     
     269      Volt[i][j] = 0.0;     
    273270    }
    274271  }
  • fact/BIASctrl/Crate.h

    r9917 r10049  
    1616#define BAUDRATE B115200
    1717
    18 class ProcessIO;
     18class User;
    1919
    2020class Crate {
    2121 
    22     class ProcessIO *m;
     22    class User *m;
    2323        int CrateNumber;
    2424        int fDescriptor;
    2525        DimService *NameService;
    26         bool LastOC;
    27         int LastCurrent;
     26        char ReadBuffer[3];
    2827
    2928        int Communicate(unsigned char*, int);
     
    3130   
    3231  public:
    33     Crate(std::string, int, class ProcessIO *);
     32    Crate(std::string, int, class User *);
    3433    ~Crate();
    3534
  • fact/BIASctrl/Makefile

    r9917 r10049  
    11#  Makefile for BIASctrl
    22
    3 SOURCES = BIASctrl.cc Crate.cc ProcessIO.cc ../pixelmap/Pixel.cc ../pixelmap/PixelMap.cc ../Evidence/Evidence.cc
     3SOURCES = BIASctrl.cc Crate.cc User.cc ../pixelmap/Pixel.cc ../pixelmap/PixelMap.cc ../Evidence/Evidence.cc
    44OBJECTS = $(addsuffix .o, $(basename $(SOURCES)))
    55INCDIRS   = -I. -I../Evidence -I./src -I$(DIMDIR)/dim
Note: See TracChangeset for help on using the changeset viewer.