Ejemplo n.º 1
0
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();
}
Ejemplo n.º 2
0
/*
 * Destructor for the ControlBoard
 */
ControlBoard::~ControlBoard()
{
  closeSerialDevice();
}
Ejemplo n.º 3
0
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;
}
Ejemplo n.º 4
0
bool	openSerialDevice(char* serialName)
{
	struct termios		options;
	long				dataLat;
	bool				serialOpen = false;
	
	if (serialName)	printf("Opening serial port: %s\n",serialName);
	else return false;
	
	if (deviceConnected)
		return true;							// device already connected

	if ((fdSerial = open(serialName, O_RDWR | O_NOCTTY | O_NDELAY)) < 0)
		goto bail;
	printf("Port opened\n");
	// Obtain exclusive access
	if (ioctl(fdSerial, TIOCEXCL, 0) == -1)
	{		
		close(fdSerial);
		fdSerial = -1;
		printf("Port closed\n");		
		goto bail;
	}	
	serialOpen = true;
	if (fcntl(fdSerial, F_SETFL, 0) == -1)
		goto bail;
	
	// Get the current options and save them for later reset
	if (tcgetattr(fdSerial, &originalSerialDeviceAttributes) == -1)
		goto bail;

	// Set raw input
	// These options are documented in the man page for termios
	// (in Terminal enter: man termios)
	
	options.c_cflag = (CS8 | PARENB | PARODD | CSTOPB | CLOCAL | CREAD);
	options.c_iflag = (IGNBRK | IGNPAR);
	options.c_lflag = (originalSerialDeviceAttributes.c_lflag & ~(ICANON | ECHO | ECHOE | ISIG));
	options.c_oflag = (originalSerialDeviceAttributes.c_oflag & ~OPOST);

	// There is no minimum number of bytes to wait for read() to return, nor is
	// there a minimum time that we should wait for a response from the VTR.
	options.c_cc[VMIN] = 0;
	options.c_cc[VTIME] = 1;
	// Set the speed to 38.4 k baud
	options.c_ispeed = B38400;
	options.c_ospeed = B38400;

	// Set the options
	if (tcsetattr(fdSerial, TCSANOW, &options) == -1)
		goto bail;

	// Set the data read latency
	dataLat = 5;
	ioctl(fdSerial, IOSSDATALAT, &dataLat);		
	deviceConnected = true;
bail:
	if (!deviceConnected)
	{
		if (serialOpen)
			closeSerialDevice();
		printf("we've bailed\n");	
	}
	return deviceConnected;
}