<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[USB Gerät (Master Pipe) auslesen]]></title><description><![CDATA[<p>hi,</p>
<p>ich versuche seit Tagen vergebens ein USB Gerät mit streams auszulesen.</p>
<p>Über die Winapi bekomme ich die filesystem adresse des USB Devices:<br />
std::string path = &quot;\?\usb#vid_04cc&amp;pid_1a64&amp;mi_01#6&amp;31d4e9aa&amp;0&amp;0001#{28d78fad-5a12-11d1-ae5b-0000f803a8c2}&quot;</p>
<p>Mit den Windowsfunktionen ReadFile und WriteFile habe ich auch schon Transfers hinbekommen.</p>
<pre><code class="language-cpp">HANDLE m_hFile;
			m_hFile = CreateFile(path.c_str(),
				GENERIC_READ | GENERIC_WRITE,
				FILE_SHARE_READ | FILE_SHARE_WRITE, 
				NULL, // no SECURITY_ATTRIBUTES structure
				OPEN_EXISTING, 
				NULL, // special attributes
				NULL // No template file
				);

				COMMTIMEOUTS ct;
		ct.ReadIntervalTimeout = 100; //The maximum time allowed to elapse between the arrival of two bytes on the communications line, in milliseconds.
		ct.ReadTotalTimeoutMultiplier = 0; //The multiplier used to calculate the total time-out period for read operations, in milliseconds. For each read operation, this value is multiplied by the requested number of bytes to be read.
		ct.ReadTotalTimeoutConstant = 100; // A constant used to calculate the total time-out period for read operations, in milliseconds.
		ct.WriteTotalTimeoutMultiplier = 0; //The multiplier used to calculate the total time-out period for write operations, in milliseconds.
		ct.WriteTotalTimeoutConstant = 100; //A constant used to calculate the total time-out period for write operations, in milliseconds.
		SetCommTimeouts(m_hFile, &amp;ct);

			U32 err = GetLastError();
			//send read command
			U32 bufHeader[2];
			U32 bytesWritten;
			bufHeader[0] = 0x00000006; // next command: read 4 bytes from
			bufHeader[1] = 0x00e00000; //this addr
			WriteFile(m_hFile, bufHeader, 8, &amp;bytesWritten, NULL);

			U32 readvalue;
			U32 _bytesRead;
			ReadFile(m_hFile, &amp;readvalue, 4, &amp;_bytesRead, NULL);
</code></pre>
<p>Wenn ich aber mit den Windowsfunktionen eine leere Pipe gelesen habe, blockierte der Aufruf obwohl die COMMTIMEOUTs passend gesetzt waren.</p>
<p>Deshalb möchte ich mit iostreams arbeiten (möchte später eh auch Linux benutzen).<br />
Das Problem ist, dass ich mit den streams den Pfad nicht öffnen kann. hier 3 Wege, auf denen ich es probiert habe.</p>
<pre><code class="language-cpp">bool streamOpened;

std::ifstream is;
std::filebuf * fb;
fb = is.rdbuf();
fb-&gt;open (path.c_str() , std::ios::binary | std::ios::in);
streamOpened = fb-&gt;is_open();  // FALSE

std::ifstream infile;
infile.open (path.c_str(), std::ifstream::in);
streamOpened  = infile.is_open();  //FALSE

std::ifstream * inputStream;
inputStream = new std::ifstream();
inputStream-&gt;open(path.c_str(), std::ifstream::binary);
streamOpened = *inputStream;//FALSE
</code></pre>
<p>Was mache ich bloß falsch?</p>
<p>Gruß</p>
<p>Martin</p>
]]></description><link>https://www.c-plusplus.net/forum/topic/247207/usb-gerät-master-pipe-auslesen</link><generator>RSS for Node</generator><lastBuildDate>Thu, 17 Sep 2026 13:17:09 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/247207.rss" rel="self" type="application/rss+xml"/><pubDate>Fri, 07 Aug 2009 15:29:39 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to USB Gerät (Master Pipe) auslesen on Fri, 07 Aug 2009 15:29:39 GMT]]></title><description><![CDATA[<p>hi,</p>
<p>ich versuche seit Tagen vergebens ein USB Gerät mit streams auszulesen.</p>
<p>Über die Winapi bekomme ich die filesystem adresse des USB Devices:<br />
std::string path = &quot;\?\usb#vid_04cc&amp;pid_1a64&amp;mi_01#6&amp;31d4e9aa&amp;0&amp;0001#{28d78fad-5a12-11d1-ae5b-0000f803a8c2}&quot;</p>
<p>Mit den Windowsfunktionen ReadFile und WriteFile habe ich auch schon Transfers hinbekommen.</p>
<pre><code class="language-cpp">HANDLE m_hFile;
			m_hFile = CreateFile(path.c_str(),
				GENERIC_READ | GENERIC_WRITE,
				FILE_SHARE_READ | FILE_SHARE_WRITE, 
				NULL, // no SECURITY_ATTRIBUTES structure
				OPEN_EXISTING, 
				NULL, // special attributes
				NULL // No template file
				);

				COMMTIMEOUTS ct;
		ct.ReadIntervalTimeout = 100; //The maximum time allowed to elapse between the arrival of two bytes on the communications line, in milliseconds.
		ct.ReadTotalTimeoutMultiplier = 0; //The multiplier used to calculate the total time-out period for read operations, in milliseconds. For each read operation, this value is multiplied by the requested number of bytes to be read.
		ct.ReadTotalTimeoutConstant = 100; // A constant used to calculate the total time-out period for read operations, in milliseconds.
		ct.WriteTotalTimeoutMultiplier = 0; //The multiplier used to calculate the total time-out period for write operations, in milliseconds.
		ct.WriteTotalTimeoutConstant = 100; //A constant used to calculate the total time-out period for write operations, in milliseconds.
		SetCommTimeouts(m_hFile, &amp;ct);

			U32 err = GetLastError();
			//send read command
			U32 bufHeader[2];
			U32 bytesWritten;
			bufHeader[0] = 0x00000006; // next command: read 4 bytes from
			bufHeader[1] = 0x00e00000; //this addr
			WriteFile(m_hFile, bufHeader, 8, &amp;bytesWritten, NULL);

			U32 readvalue;
			U32 _bytesRead;
			ReadFile(m_hFile, &amp;readvalue, 4, &amp;_bytesRead, NULL);
</code></pre>
<p>Wenn ich aber mit den Windowsfunktionen eine leere Pipe gelesen habe, blockierte der Aufruf obwohl die COMMTIMEOUTs passend gesetzt waren.</p>
<p>Deshalb möchte ich mit iostreams arbeiten (möchte später eh auch Linux benutzen).<br />
Das Problem ist, dass ich mit den streams den Pfad nicht öffnen kann. hier 3 Wege, auf denen ich es probiert habe.</p>
<pre><code class="language-cpp">bool streamOpened;

std::ifstream is;
std::filebuf * fb;
fb = is.rdbuf();
fb-&gt;open (path.c_str() , std::ios::binary | std::ios::in);
streamOpened = fb-&gt;is_open();  // FALSE

std::ifstream infile;
infile.open (path.c_str(), std::ifstream::in);
streamOpened  = infile.is_open();  //FALSE

std::ifstream * inputStream;
inputStream = new std::ifstream();
inputStream-&gt;open(path.c_str(), std::ifstream::binary);
streamOpened = *inputStream;//FALSE
</code></pre>
<p>Was mache ich bloß falsch?</p>
<p>Gruß</p>
<p>Martin</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1757004</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1757004</guid><dc:creator><![CDATA[Martin321]]></dc:creator><pubDate>Fri, 07 Aug 2009 15:29:39 GMT</pubDate></item><item><title><![CDATA[Reply to USB Gerät (Master Pipe) auslesen on Fri, 07 Aug 2009 19:12:46 GMT]]></title><description><![CDATA[<p>Mit den C++ Streams wird das wohl nicht gehen. Du könntest aber vermutlich die Boost Iostreams Wrapper für FILE* bzw. HANDLE verwenden (FILE* bin ich jetzt nicht sicher ob's das gibt, HANDLE 99% sicher).<br />
Dann wäre nurmehr der Code zum Öffnen der Datei und anlegen des Wrappers für Windows und Linux unterschiedlich.</p>
<p>Was das Blockieren angeht: wieso denkst du, dass du da mit iostreams mehr Glück hättest?</p>
<p>Dass die COMM Timeouts nicht berücksichtigt werden wundert mich auch nicht weiter, da USB kein COMM Interface ist. Vermutlich wird es eigene IOCTLs geben mittels derer du eine Timeout-Zeit festlegen kannst.<br />
Vielleicht könntest du auch OVERLAPPED IO + CancelIo(HANDLE) verwenden - ist aber natürlich komplizierter, und funktioniert auch nicht mit iostreams Wrappern.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1757078</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1757078</guid><dc:creator><![CDATA[hustbaer]]></dc:creator><pubDate>Fri, 07 Aug 2009 19:12:46 GMT</pubDate></item><item><title><![CDATA[Reply to USB Gerät (Master Pipe) auslesen on Tue, 11 Aug 2009 07:28:26 GMT]]></title><description><![CDATA[<p>danke für deine Antwort Hustbaer.</p>
<p>Habe nach langem googlen beschlossen auf die LibUSB umzusteigen. Die benutzt intern IOCTLs und bietet Funktionen wie usb_bulk_read(device, endpoint, Buffer, size, timeout);</p>
<p>Gruß</p>
<p>Martin</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1758619</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1758619</guid><dc:creator><![CDATA[Martin321]]></dc:creator><pubDate>Tue, 11 Aug 2009 07:28:26 GMT</pubDate></item></channel></rss>