C :: Program To Read Data From USB Device Connected To System

Sep 26, 2013

I am trying to fetch data from the USB device(say pendrive) connected to the USB port of a system. I have attached code.c file which I have wriiten for the same purpose, please find it. Here I am able to open the device file and read some random raw data which is in the log.txt file (also attached to this mail). But I want it to fetch data like minicom/teraterm does.

What methods and libraries I can use to do it successfully and how can it be done.

View 2 Replies


ADVERTISEMENT

C++ :: Modelling Device In Embedded System?

Oct 13, 2013

What I want to do is abstract and model a device (more specifically in this case, an IMU) in an embedded system.

Now, there are a couple of gotchas:

- It is basically a framework, which means that it should work with any device, any platform and any bus.

- It is an embedded system, so power consumption and memory consumption must be reduced. It is not a PC.

- It cannot be too complex, because I fear that will just make people scrap it and rewrite it from scratch :P

- It should aim for as little code as possible to write the whole model, of course. Adding 100 lines of code for each register would be a bummer.

That said, I must also model the current system, which means that the current platform, the current bus (which is I2C) and the specific IMU model (I have a datasheet).
So the model I am thinking of currently is this:

First, I have a platform. It will know what bus a device is connected on and contains the buses (or specifically, the instances of the buses). It consists of a specific class for each platform and a base. Here are the two I have now:

Code:
namespace Sensors
{
template<typename Platform_t> class GPS;
}
namespace Platforms
{
class RaspberryPi: public PlatformBase

[Code]....

Currently I am making the assumption that all platforms will have an I2c bus and UART bus, but I'm not sure about that. We have only one platform ATM, though, so for now this holds. I'm guessing I might have to move it to the specific platforms later and get rid of PlatformBase.GetI2CBus is a problematic one related to registers, but I'll get back to that.

UART is simple to model since it's just a block read and write, so:

Code:
namespace Buses
{
class UART
{
public:
UART(const std::string& UARTPath): m_Open(false), m_PathToUART(UARTPath) {}

[Code]....

I'm probably going to handle all errors through exceptions. So if I can't open the UART bus, I'll throw an exception.

The I2C bus is a problem. I have a model which deals with it on a register-based level, but ideally I'd like to be able to model and use the devices on the I2C bus on a flag-based level (ie, I have names for each individual flag in the registers which I can read or write to directly instead of writing a hexadecimal value directly to each register).

Here is code:

Code:
namespace Buses {
template<unsigned int Id>
class I2CDevice {
public:
I2CDevice(I2C& Bus): m_Bus(Bus) {}
template<typename T>

[Code]....

So I2CDevice does some checks to see that the data to write to a register is either 8 or 16 bits. It does not check that the size to write matches the register's size, but another class does not.

The idea is also that it checks which device is currently active on the bus, and if it's not the current I2CDevice, then it simply selects that before attempting to read or write (the Open call).

This is not meant for multi-threaded environments. Yet, anyway.

The Impl2::Read/Write just dispatches the call so it calls the correct function for writing and reading the correct size, depending on the size of the data.

This is all well and good, but I2C works with registers, so of course I want a class to model a register which I can read and write to directly. It must tie into the bus class since the bus class is the one that abstracts reads and writes on the bus.

The register class looks like:

Code:
template<unsigned int Bits, unsigned int RegisterId, typename Bus_t>
class Register {
public:
typedef typename Impl::RegisterBase<Bits>::Storage_t Storage_t;
static_assert(!std::is_same<Bus_t, Buses::UART>::value, "Cannot read and write registers on the UART bus.");
static_assert(Bits == 8 || Bits == 16 || Bits == 32 || Bits == 64, "Number of bits must be 8, 16, 32 or 64.");
auto Write(Storage_t Data) -> void

[Code]....

I think this explains itself, except for the Regs struct, which is an experiment by me to enable myself to access registers via Regs.Config, etc.

What is missing is the ability to access and read/write the individual bits inside the registers. I am thinking a two-way access, where you can write to individual bits, but must call .Write() to commit the write to the register for efficiency.

I haven't actually written this. I don't know a good way ATM. I don't want to add a lot of variables and a write function because that would use 1 byte for every bit which is unacceptable.

I don't want to add a lot of code to make it work, either. A good get/set class would be nice, but I can't see that working. The register must store all state and any subsequent classes must not store any state or overhead will increase.

Finally, yes, I know a lot is incomplete and untested. It probably won't even compile. But that is for later. First is finishing the model.

It would be nice if things such as the platform and buses could be made static because there will only be one instance at any time, and that would save overhead if I don't have to store objects or references to them, but I haven't figured out how to achieve this.

View 13 Replies View Related

C/C++ :: Retrieve Data From USB Device

Jun 16, 2014

I am looking to retrieve data from a USB device, this device is a fingerprint scanner. Because I bought it online and wasn't reading carefully enough, drivers and other installation programs weren't included. Send it back? Nah . . .

I want to see if it is possible to retrieve data from this device. To be honest, I don't even know if it's possible, but I would love to give it a whack.

I looked into making INF files and things Microsoft has put out, but I honestly don't know where to start simply because I have absolutely no experience doing this. I have a program set up to organize the data and such, I just need to find a way to actually get it.

What should I research and look into? Are drivers necessary?

Here is a little more information :-)

I want to save data from a fingerprint scanner.I bought a fingerprint scanner, but nothing came with it (drivers, software, etc.). I decided to not return it and see what fun I could have.

I have no code written up yet (mainly because I don't know where to start). But I looked into the device a little...Microsoft recognizes it as a "Fingerprint Scanner" but is still considered unrecognized.I have the USB identifier (at work right now, don't have it on hand)...

Is it even possible to communicate with the device without the initial drivers.Do I really need drivers for the device, or can I communicate with it as it is now.If I do need drivers, where should I start?What should I look into to get communicating with the device?

View 6 Replies View Related

C++ :: Read 100 Elements From Standard Input Device And Store Them In Array

Feb 19, 2014

Write code to do the following:

1) declare a variable ptr as a pointer to int and initialize it to NULL
2) dynamically allocate memory for an array of 100 elements
3) read 100 elements from the standard input device and store them in the array.

This is what I have so far, I'd like to know if its ok or if something is wrong.

int *ptr = NULL;
ptr = new int[100];
cin >> dataPtr [arr];

View 2 Replies View Related

Visual C++ :: TCP/IP Program - Display All IP Addresses That Are Connected To Client

Mar 12, 2013

I need to create a TCP/IP program using visual studios MFC that displays all client's IP addresses that are connected to the client.

The MFC application just has a list box and a button. The client can be a simple console application. When the button is clicked, the list box gets populated with all ip addresses of connected clients.

View 14 Replies View Related

C :: Program To Read Binary Data And Print It - File I/O Error

Mar 14, 2013

Objective of this program is to read binary data from a file and print it.

Code:
#include <stdio.h>
void readFile(void);
int main(){
readFile();
return 0;

[Code] .....

But When I Run This Code First It Print "Error." Then Rest Of The File.Say In My File I Have "I AM HUMAN", It Prints "Error. HUMAN"!!

I Cant Figure Out Whats Wrong In The readFile() Function.It seems right to me.

View 4 Replies View Related

C++ :: Login System Which Load Data From Dat

Apr 20, 2014

I am trying to make a log in system which load data from a .dat .... So I have a part of code below

if(radioButton1->Checked)//Login {
String ^ userAC = textBox1->Text;
String ^ userPW = textBox2->Text;
char ACc[300];
char PWc[300];

[Code] ....

I built it and it is a success but when i run it, it have error: Debug Assertion Failed!

Program:....
File:....Microsoft Visual Studio 10.0VCincludexstring
Line: 930

Expression: invalid null pointer
.......

What is going wrong so i try to comment some part to debug. I found that it come form the code

string AC(ACc);
string PW(PWc);
String ^ ACstr;
String ^ PWstr;
MarshalString(ACstr,AC);
MarshalString(PWstr,PW);

I tried to use std::string and System::string when getting data from .dat but it failed so i tried char array.

View 2 Replies View Related

Visual C++ :: System Access Violation Exception / Attempted To Read Or Write Protected Memory

Mar 17, 2013

I have CAN Dll program for my application,which was separately used.Now I have included the Drivers program into my application Program and I am having this error System Access Violation Exception:Attempted to read or write protected memory.i am attaching the Dll code and Application code which is throwing this error.

[CODE]

The CAN Dll Code

int receive_data(unsigned char *data_output, int *MsgId, XLportHandle g_xlPortHandle){
XLstatusxlStatus, xlStatus_new;
XLevent xlEvent;
unsigned intmsgsrx=RECEIVE_EVENT_SIZE;
char *local_data ="11111111";
DWORD status;
xlStatus_new = xlSetNotification(g_xlPortHandle, &h, 1);

[code]...

My Application Code which is the receiver thread for accessing the messages got onto the CAN bus.

DWORD WINAPI Rcv_Msg(LPVOID param){
int*MsgId = new int;//msg id from CAN
intRcvVal;//0 = there is data in the queue; 1 = there is no data
unsigned int uMsgId;
*MsgId = 0;
unsigned char CanData[8];

[code]...

View 1 Replies View Related

Visual C++ :: Stream Data From System Windows Controls

Dec 19, 2012

I need make a CBitmap or a streamdata from a System.Windows.Controls::Image(rendered out put)in a SDI mfc application (supporting clr). Here is my codes:

Code:
using namespace System;
using namespace System::IO;
using namespace System::Collections::Generic;
using namespace System::Windows;
using namespace System::Windows::Controls;

[Code] .....

By this codes i can read datastream from bitmapSource but in this way somthing goes wrong in most of GIF animations. After debug i found out i need 3 more things too decode a gif animation - (x,y) position and size of each frame and disposal method for each one - finally i just found a way to draw tru images on a form window by this codes:

Code:
System::Windows::Window^ mainWindow;
mainWindow = gcnew System::Windows::Window();
mainWindow->Title = "GIF Imaging Sample";
//ScrollViewer^ mySV = gcnew ScrollViewer();
array<System::Byte>^ pixels = gcnew array<System::Byte>(bitmapSource->PixelHeight * Stride);

[Code] ...

When i change

Code: bitmapSource = decoder->Frames[0];
to
Code: bitmapSource = decoder->Frames[01];

frame[1] has drawn perfectly on window(i think some how Image class takes care about - (x,y) position and size of each frame and disposal method for each one ),so im wonder if how can i make a CBitmap or a data stream from System.Windows.Controls::Image class to use in mfc app.

View 2 Replies View Related

C++ :: Read Byte Of Char Data And Convert It Into Text String Of Binary Data That Represents Hex Value

Dec 26, 2013

I am writing a program where I need to read a byte of char data and convert it into a text string of binary data that represents the hex value...

i.e. The char byte is 0x42 so I need a string that has 01000010 in it. I've written the following subroutine....

------------- My Subroutine ----------------------------------------------------------------------
void charbytetostring(char input, char *output){
int i, remainder;
char BASE=0x2;
int DIGITS=8;
char digitsArray[3] = "01";

[Code] ....

When I submitted the byte 0x42 to the subroutine, the subroutine returned to the output variable 01000010... Life is good.

The next byte that came in was 0x91. When I submit this to the subroutine I get garbage out.

I am using a debugger and stepped through the subroutine a line at a time. When I feed it 0x42 I get what I expect for all variables at all points in the execution.

When I submit 0x91 When the line remainder = input % BASE; gets executed the remainder variable gets set to 0xFFFF (I expected 1). Also, when the next line gets executed..

input = input / BASE; I get C9 where I expected to get 48.

My question is, are there data limits on what can be used with the mod (%) operator? Or am I doing something more fundamentally incorrect?

View 6 Replies View Related

C Sharp :: Physically Connected Printers Detection?

Oct 24, 2012

How do I get the printer connected with my computer physically using cables?

View 2 Replies View Related

Visual C++ :: USB Node View - What Devices Connected To Hub

Jan 29, 2014

Is it possible to see what usb devices are connected to a hub?

An example would be:

Onboard usb hub:
usb mass storage device
webcam imaging device

superspeed hub:
Mass storage device
Printer
MTD device

I am currently able to get a list of all connected devices with ManagementobjectCollection in C# but that doesn't give me any hierarchy (as far as I am aware).

I am not dead set on C#, I assumed that would be fastest way to get this up and running.

View 2 Replies View Related

C++ :: Create A Class That Detect Cellphone Connected To Computer

Apr 30, 2014

I need to know if it is possible to create a class that will detect if a cellphone is connect to my computer via a usb cable without knowing what the make and model of that computer is. If you think it is possible, how would you go about implementing it.

View 2 Replies View Related

C Sharp :: How To Send SMS From Desktop Application Through IPhone (USB Connected)

Sep 26, 2014

i want to send SMS from APP Using Iphone. i can send SMS from andriod but when i connect Iphone so COM PORT can't be detected.

View 1 Replies View Related

C :: Banking System - ATM Program

Mar 27, 2014

I am working on a project that is like a banking system and needs to include making a withdrawal, transaction, deposit, query, and transaction.

Code:
#include <stdio.h>
//#define true
//#define false
//assume there is money in the account. $10,000
void deposit(){

[Code] ....

View 1 Replies View Related

C :: Program For Ordering System

Mar 1, 2013

I just started my task with Ordering system. what should I use if I'm going to ask the user if he wants to exit the system, he will press(zero)0 to exit the program and press Y(uppercase or lowercase) to continue?

View 1 Replies View Related

C++ :: Call A Program By System

Apr 17, 2013

So I know that I can call a program by system("prog.exe"), but what do I add in when I want to pass a parameter?

View 2 Replies View Related

C++ :: Loop To Read In Data And Check Data

Oct 8, 2013

struct receivers
{string fname, lname, team,;
int receptions, yards, TDs, longest,rec20, fumbles, yac, firstdown;
double, averagepergain, averageperrec
}

View 2 Replies View Related

C :: Finding Number Of Connected Components From Undirected Disconnected Graph

Feb 17, 2013

How to find the number of connected components from an undirected disconnected graph.

the input I'm getting is like this:

7
1 2
4 5
3 6
2 7

the top number is the number of vertices and the rest of the numbers are the edges, eg. 1--2 is an edge.

Is there a way that you can implement DFS algorithm to find the number of connected components? like increment a variable every time DFS is called or something?

View 1 Replies View Related

C :: Program Stalled At System Command?

Dec 22, 2014

I am trying to recreate this bash command in c code:

Code: bash-4.2$ exec 3<<<teststring
bash-4.2$ cat <&3
teststring
bash-4.2$

I've written a small program to do this as shown below:

Code: bash-4.2$ cat test.c
#include <stdio.h>
#include <string.h>
#include <fcntl.h>

[Code].....

View 3 Replies View Related

C/C++ :: System Call A Command From Within A Program?

Sep 17, 2014

how to invoke a UNIX command within a program

I found this:

dd if=/dev/urandom of=myrandom bs=100 count=1

and I found this:

dd if=/dev/zero of=mytestfile.out bs=1 count=0 seek=1G

I want to call this command, by using the command line and typing Generate or something to that effect.

Basically, I want to be able to build random size files, content isn't important to me at this time.

View 8 Replies View Related

C :: System Call To Pause Execution Of Program For Few Seconds

Feb 2, 2014

I know there has to be a system call to pause (not system("pause") execution of a program for a few seconds. I would like to give the illusion that my program is 'thinking' rather than just spit out the result as soon as the user has hit the enter key.

View 5 Replies View Related

C++ :: Program And Simulate 2 Floor Lift Control System?

Apr 28, 2014

I need to program and simulate a 2 floor lift control system. How to do that ? I need to design its program only.

View 1 Replies View Related

C++ :: How To Program A Hash Map System Where Each Key Have Multiple Values Under Indexes

Nov 13, 2013

How difficult would it be to program a hash-map system where each "key" can have multiple values under indexes?

For example: "Word" -> 45(index 0) , 67(index 1) , 12(index 2). What could I start with to program this or where could I find a pre-made system that does this?

View 14 Replies View Related

C++ :: Program For Billing System - Regular Package Function

Jan 5, 2015

I have programmed a program for billing system. I have used parameters and arrays. All the functions are working except a one function. (Regular package function).

#include <iostream>
#include <fstream>
#include <string>
#include <ctime>
using namespace std;
void main(int &minutes, int &minutesd,int &minutesn) {

[Code] .....

View 3 Replies View Related

C++ :: Look-up Mounting Point Of USB Device

Apr 15, 2013

I'm developing a short c++ program to scan all devices connected to the system through the USB connections.

I have used libusb to scan them and it really works but this library does not provide me with the mounting point, so I get a list of devices including manufacturer, serial number, etc but not the mounting point.

I have also used libudev library but it seems to happen something similar...

I need to get the mounting point for all USB devices connected to the board, you know: /dev/ttyUSB0 ....

View 1 Replies View Related







Copyrights 2005-15 www.BigResource.com, All rights reserved