source: hvcontrol/src/HV.h@ 63

Last change on this file since 63 was 14, checked in by lstark, 16 years ago
first version of hvcontrol added
File size: 2.7 KB
Line 
1
2#include "Types.h"
3#include "Utilities.h"
4
5#include <ftdi.h>
6#include <sys/ioctl.h>
7
8
9#ifndef NULL
10#ifdef __cplusplus
11#define NULL 0
12#else
13#define NULL ((void *)0)
14#endif
15#endif
16
17
18#ifndef HV_H_SEEN
19#define HV_H_SEEN
20
21
22// Have a look at http://www.linux-usb.org/usb.ids
23// Vendor: Future Technology Devices International, Ltd (FTDI)
24#define USB_VENDOR 0X0403
25// Product: FT232 USB-Serial (UART) IC (USB <-> Serial converter, UM245R)
26#define USB_PRODUCT 0X6001
27
28
29#define USB_BAUDRATE 115000
30#define USB_LATENCY_TIMER 1
31
32
33// HV board control registers
34#define REG_VREF0 0X00
35#define REG_VREF1 0X08
36#define REG_VREF2 0X10
37#define REG_VREF3 0X18
38
39#define REG_HV0 0X20
40#define REG_HV1 0X28
41#define REG_HV2 0X30
42#define REG_HV3 0X38
43
44#define REG_RESET 0XF8
45#define REG_STATUS 0X80
46
47#define REG_PD1 0X04
48#define REG_PD2 0X02
49
50
51// HV board status bits
52#define BIT_OC0 (1<<3)
53#define BIT_OC1 (1<<4)
54#define BIT_OC2 (1<<5)
55#define BIT_OC3 (1<<6)
56
57#define BIT_RESET (1<<7)
58
59
60class HVBoard {
61
62 public:
63
64 HVBoard(char* serial, int number, struct ftdi_context* ftdic);
65 ~HVBoard();
66
67 int Init(bool verbose);
68 int Reset(FILE* fptr, unsigned char* rbuf, bool verbose);
69 int GetStatus(FILE* fptr, unsigned char* rbuf, bool verbose);
70 int SetVRef(FILE* fptr, int chain, unsigned int vref, unsigned char* rbuf, bool verbose);
71 int SetHV(FILE* fptr, int chain, unsigned int channel, unsigned int hv, unsigned char* rbuf, bool verbose);
72 struct ftdi_context* GetFTDI_C() {return FTDI_C;}
73 char* GetSerial() {return Serial;}
74 int GetBoardNumber() {return BoardNumber;}
75 int Write(unsigned char* data, int size);
76 int Read(unsigned char* data, int size);
77 int TRead(FILE* fptr, unsigned char* rbuf, bool verbose);
78 void SetTimeOut(float t) {fTimeOut = t;}
79 float GetTimeOut() {return fTimeOut;}
80 void TestIO(); // Warning: NEVER use this function with a real HV board!!!
81 int DecodeWrap(unsigned char* rbuf);
82 void DecodeOC(bool OC[], unsigned char* rbuf);
83 bool DecodeReset(unsigned char* rbuf);
84
85 struct ftdi_context* FTDI_C;
86 char Serial[STR_LENGTH];
87 int BoardNumber;
88 float fTimeOut; // [s] timeout to return from read
89
90};
91
92
93
94class HV {
95
96 public:
97
98 HV(char** usbdevice, int* usbdevicenumber, FILE* f);
99 ~HV();
100
101 int fNumberOfBoards;
102 int fMaxNumberOfBoards;
103
104 HVBoard* fHVBoard[MAX_NUM_HVBOARDS];
105 int GetNumberOfBoards() {return fNumberOfBoards;}
106 void SetNumberOfBoards(int i) {fNumberOfBoards = i;}
107 HVBoard* GetHVBoard(int i) {return fHVBoard[i];}
108
109 protected:
110
111 // For FTDI USB <-> serial converter
112 struct ftdi_context ftdic[MAX_NUM_HVBOARDS];
113 struct ftdi_context ftdic_dummy;
114 struct ftdi_device_list *devlist, *curdev;
115
116 void ArrangeHVBoards(HVBoard** fHVBoard, int size);
117
118};
119
120#endif
Note: See TracBrowser for help on using the repository browser.