Talking to a usb device

Hey all,

I'm new here, so be gentle :)

I installed a driver in linux that can talk to the X10 CM19A RF transeiver. All is well installing that.
I can now do echo +A3 > /dev/cm19a0 in konsole and my light will turn on... great.

I am trying to program this action in c++, but i don't know where to start.

Is there a way/command in c++ that can write to a device in linux like echo does in konsole.

Thank you very much for any input, i searched the web and could not find what i needed, i might be looking for the wrong keywords.

Richard
Does this work?

1
2
3
4
5
6
7
8
9
10
11
12
#include <iostream>
#include <cstdlib>
using namespace std;

int main()
{
    system("echo +A3 > /dev/cm19a0");

    cout << "hit enter to quit...";
    cin.get();
    return 0;
}

Info on system -> http://cplusplus.com/reference/clibrary/cstdlib/system/
Assuming you have write permissions to the device and its a character device then you should be able to treat it like a file:
1
2
3
4
5
6
7
8
#include <fstream>

int main()
{
    std::ofstream X10_CM19A_RF("/dev/cm19a0");

    X10_CM19A_RF << "+A3" << std::flush;
}


EDIT: Added std::flush just in case.
Last edited on
Ah, of course. After all, everything in unix is a file ;)
Topic archived. No new replies allowed.