forked from vfp2/MeterFeeder
-
Notifications
You must be signed in to change notification settings - Fork 0
/
generator.cpp
82 lines (65 loc) · 1.79 KB
/
generator.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
/**
* MeterFeeder Library
*
* by fp2.dev
*/
#include "generator.h"
MeterFeeder::Generator::Generator(char* serialNumber, char* description, FT_HANDLE handle) {
serialNumber_ = serialNumber;
description_ = description;
ftHandle_ = handle;
};
std::string MeterFeeder::Generator::GetSerialNumber() {
return serialNumber_;
};
std::string MeterFeeder::Generator::GetDescription() {
return description_;
};
FT_HANDLE MeterFeeder::Generator::GetHandle() {
return ftHandle_;
};
int MeterFeeder::Generator::StartStreaming() {
UCHAR startCommand = FTDI_DEVICE_START_STREAMING_COMMAND;
DWORD bytesTxd = 0;
// Purge before writing
FT_STATUS ftdiStatus = FT_Purge(ftHandle_, FT_PURGE_RX | FT_PURGE_TX);
if (ftdiStatus != FT_OK) {
return ftdiStatus;
}
// WRITE TO DEVICE
ftdiStatus = FT_Write(ftHandle_, &startCommand, 1, &bytesTxd);
if (ftdiStatus != FT_OK || bytesTxd != 1) {
return ftdiStatus;
}
return MF_OK;
}
int MeterFeeder::Generator::StopStreaming() {
UCHAR stopCommand = FTDI_DEVICE_STOP_STREAMING_COMMAND;
DWORD bytesTxd = 0;
// Purge before writing
FT_STATUS ftdiStatus = FT_Purge(ftHandle_, FT_PURGE_RX | FT_PURGE_TX);
if (ftdiStatus != FT_OK) {
return ftdiStatus;
}
// WRITE TO DEVICE
ftdiStatus = FT_Write(ftHandle_, &stopCommand, 1, &bytesTxd);
if (ftdiStatus != FT_OK || bytesTxd != 1) {
return ftdiStatus;
}
return MF_OK;
}
int MeterFeeder::Generator::Read(DWORD length, UCHAR* dxData) {
DWORD bytesRxd = 0;
// READ FROM DEVICE
FT_STATUS ftdiStatus = FT_Read(ftHandle_, dxData, length, &bytesRxd);
if (bytesRxd != length) {
return MF_RXD_BYTES_LENGTH_WRONG;
}
if (ftdiStatus != FT_OK) {
return ftdiStatus;
}
return MF_OK;
}
void MeterFeeder::Generator::Close() {
FT_Close(ftHandle_);
}