int openSerial(const char * name, int baud, int parity, int databits, int stopbits) { // Choose wich type of device to open: /dev/tty, hostname:socket or xuartX if (strchr(name, ';')) return openSerialSocket(name); if (name[0] == '/') return openSerialDevice(name, baud, parity, databits, stopbits); return openXuart(name, baud, parity, databits, stopbits); }
/* * Init ControlBoard. Returns false on failure */ bool ControlBoard::init(void) { // Enable Control Board connection if (!openSerialDevice()) { qCritical("Failed to open and setup serial port"); return false; } enabled = true; return true; }
void ControlBoard::writeSerialData(QString &cmd) { if (serialFD < 0) { // Try not to write if the serial port is not (yet) open return; } cmd += "\r"; if (serialPort.write(cmd.toUtf8()) == -1) { qWarning("Failed to write command to ControlBoard"); closeSerialDevice(); openSerialDevice(); } serialPort.flush(); }
/* * Timeout callback to try open the device again */ void ControlBoard::reopenSerialDevice(void) { openSerialDevice(); }
int main (int argc, char* argv[]) { printf("DeckControl Test Application\n\n"); IDeckLinkIterator* deckLinkIterator; IDeckLink* deckLink; int numDevices = 0; HRESULT result; fdSerial = -1; // Create an IDeckLinkIterator object to enumerate all DeckLink cards in the system deckLinkIterator = CreateDeckLinkIteratorInstance(); if (deckLinkIterator == NULL) { fprintf(stderr, "A DeckLink iterator could not be created. The DeckLink drivers may not be installed.\n"); return 1; } // Enumerate all cards in this system while (deckLinkIterator->Next(&deckLink) == S_OK) { CFStringRef deviceNameCFString = NULL; // Increment the total number of DeckLink cards found numDevices++; if (numDevices > 1) printf("\n\n"); // *** Print the model name of the DeckLink card result = deckLink->GetModelName(&deviceNameCFString); if (result == S_OK) { IDeckLinkAttributes* deckLinkAttributes; char deviceName[64]; HRESULT attributeResult; CFStringRef serialName; bool serialSupported; CFStringGetCString(deviceNameCFString, deviceName, sizeof(deviceName), kCFStringEncodingMacRoman); printf("Found Blackmagic device: %s\n", deviceName); attributeResult = deckLink->QueryInterface(IID_IDeckLinkAttributes, (void**)&deckLinkAttributes); if (attributeResult != S_OK) { fprintf(stderr, "Could not obtain the IDeckLinkAttributes interface"); } else { attributeResult = deckLinkAttributes->GetFlag(BMDDeckLinkHasSerialPort, &serialSupported); // are serial ports supported on device? if (attributeResult == S_OK && serialSupported) { attributeResult = deckLinkAttributes->GetString(BMDDeckLinkSerialPortDeviceName, &serialName); // get serial port name if (attributeResult == S_OK) { char portName[64]; CFStringGetCString(serialName, portName, sizeof(portName), kCFStringEncodingMacRoman); printf("Serial port name: %s\n",portName); if (openSerialDevice((char*)&portName)== true) // open serial port { printf("Device opened\n"); playCommand(); // Play deck, printf("Delay 3 seconds\n"); sleep(3); timeCodeCommand(); // DisplayTC printf("Delay 3 seconds\n"); sleep(3); stopCommand(); // Stop deck closeSerialDevice(); // close serial port } else printf("Device open fail\n"); CFRelease(serialName); } else printf("Unable to get serial port device name\n"); } else printf("Serial port not supported\n"); } CFRelease(deviceNameCFString); // Release the IDeckLink instance when we've finished with it to prevent leaks } deckLink->Release(); } if (deckLinkIterator) deckLinkIterator->Release(); // If no DeckLink cards were found in the system, inform the user if (numDevices == 0) printf("No Blackmagic Design devices were found.\n"); printf("\n"); return 0; }