# SoftwareTrigger just works once during streaming

**URL:** <https://forum.commonvisionblox.com/t/softwaretrigger-just-works-once-during-streaming/1237>\
**Category:** C++ API\
**Created:** [October 12, 2020, 8:02am UTC](https://forum.commonvisionblox.com/t/softwaretrigger-just-works-once-during-streaming/1237 "2020-10-12T08:02:27Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![pip](https://avatars.discourse-cdn.com/v4/letter/p/9f8e36/32.png) [@pip](https://forum.commonvisionblox.com/u/pip)\
**Post date:** [October 12, 2020, 8:02am UTC](https://forum.commonvisionblox.com/t/softwaretrigger-just-works-once-during-streaming/1237/1 "2020-10-12T08:02:27Z")

</div>

Hi,

I’m struggling with the SoftwareTrigger. I configured my cameras to be used with a SoftwareTrigger (TriggerMode “On”, TriggerSource “Software”) and used the following code for testing purpose:

```
// Libraries 
#include <Windows.h> // To change process priority
#include <processthreadsapi.h>
#include <string>
#include <cstdint> //Fixed width integer types
#include <iostream>
#include <thread>
#include <cvb/image.hpp>
#include <cvb/device_factory.hpp> // To discover and open devices 
#include <cvb/async/single_stream_handler.hpp>
#include <cvb/async/async.hpp> // StreamHandlerGuard and singleStreamHandler
#include <cvb/driver/driver.hpp> // Stream, RingBuffer
#include <cvb/genapi/genapi.hpp> 

// Main program
int main()
{

	// Generate a List of all connected devices and get Model Name and Serial Number
	std::vector<Cvb::DiscoveryInformation> deviceList = Cvb::DeviceFactory::Discover();

	// Get device tokens
	std::vector<Cvb::String> devToken;
	for (const auto &device : deviceList)
	{
		devToken.emplace_back(device.AccessToken());
	}
	
	// open first device
	auto device = Cvb::DeviceFactory::Open(devToken.at(0));

	// Create a pointer which points to the NodeMap of the device.
	auto deviceNodeMap = device->NodeMap(CVB_LIT("Device"));
	
	// Get stream and start it
	Cvb::StreamPtr stream = device->Stream();
	stream->Start();

	// Define the softwareTrigger
	auto softwareTrigger = deviceNodeMap->Node<Cvb::CommandNode>(CVB_LIT("TriggerSoftware"));

	for (int i = 0; i < 10; ++i)
	{
		std::this_thread::sleep_for(std::chrono::seconds(2));
		// wait for an image with a timeout of 2 seconds
		softwareTrigger->Execute();
		Cvb::WaitResult<Cvb::StreamImage> waitResult = stream->WaitFor(std::chrono::seconds(5));
		if (waitResult.Status == Cvb::WaitStatus::Timeout)
			throw std::runtime_error("acquisition timeout");
		

		// Save file as bmp
		auto image = waitResult.Image;
		std::wstring s2 = L"image.bmp";
		auto filename = Cvb::String(s2);
		image->Save(filename);

		
		// get the timestamp of the image (usually a large integer number mapped to double - so better use fixed formatting)
		std::cout << "Acquired image... " << std::fixed << waitResult.Image->RawTimestamp() << std::endl;
	}
	// synchronously stop the stream
	stream->Stop();
	
	return 0;
}

```

In the second for loop cycle I always get a acquisition timeout and I can’t figure out why. Any ideas? I guess the SoftwareTrigger settings are correct, because in the first cycle the code saves an image.

Thanks for your Help!

Phil

---

<div class="post-metadata">

**Author:** ![rtp\_derahs](https://yyz1.discourse-cdn.com/flex027/user_avatar/forum.commonvisionblox.com/rtp_derahs/32/79_2.png) [@rtp\_derahs](https://forum.commonvisionblox.com/u/rtp_derahs)\
**Post date:** [October 12, 2020, 9:08am UTC](https://forum.commonvisionblox.com/t/softwaretrigger-just-works-once-during-streaming/1237/2 "2020-10-12T09:08:56Z")

</div>

Hi @pip

Please check if the Acquisition Mode of the camera is set to _Continuous_.  
Maybe it’s on _Single Frame_ mode? 🙂

---

<div class="post-metadata">

**Author:** ![pip](https://avatars.discourse-cdn.com/v4/letter/p/9f8e36/32.png) [@pip](https://forum.commonvisionblox.com/u/pip)\
**Post date:** [October 12, 2020, 1:29pm UTC](https://forum.commonvisionblox.com/t/softwaretrigger-just-works-once-during-streaming/1237/3 "2020-10-12T13:29:02Z")

</div>

Thanks, that solved the problem!
