PDA

View Full Version : [SOLVED] Sending command to USB device



mtangoo
November 7th, 2011, 07:19 PM
Hi I need to send AT Command to Linux device (Modem/Phone) connected via USB. Is there a way? I'm reading about libudev right now. Is it good solution?
Thanks!

haqking
November 7th, 2011, 07:22 PM
Hi I need to send AT Command to Linux device (Modem/Phone) connected via USB. Is there a way? I'm reading about libudev right now. Is it good solution?
Thanks!

minicom

https://help.ubuntu.com/community/Minicom

where your device is likely to be ttyusbx or similar

Edit: My bad just realised this isnt what you were after

mtangoo
November 7th, 2011, 07:42 PM
minicom

https://help.ubuntu.com/community/Minicom

where your device is likely to be ttyusbx or similar

Edit: My bad just realised this isnt what you were after

No problem! Do you have any idea how I can go about? I just asked also on SO

ofnuts
November 7th, 2011, 08:06 PM
Hi I need to send AT Command to Linux device (Modem/Phone) connected via USB. Is there a way? I'm reading about libudev right now. Is it good solution?
Thanks!

See http://tldp.org/HOWTO/Serial-HOWTO-10.html
If configured properly you only need to write the bytes (or even just copy a file or issue "echo {bytes} > /dev/ttySx") to the right device.

matt_symes
November 7th, 2011, 08:09 PM
Hi


Hi I need to send AT Command to Linux device (Modem/Phone) connected via USB. Is there a way? I'm reading about libudev right now. Is it good solution?
Thanks!

I'm pretty sure that libudev is only used to discover device nodes; it enumerates sysfs. I don't think it can be used to send and receive commands to the device but it will give you the node (i believe). Can't you write to that ?

You are writing this in C ?

Kind regards

mtangoo
November 7th, 2011, 08:12 PM
Hi
Hello!


I'm pretty sure that libudev is only used to discover device nodes; it enumerates sysfs. I don't think it can be used to send and receive commands to the device but it will give you the node (i believe).
After reading and reading you are right!


Can't you write to that ?
I'm very new to this arena!


You are writing this in C ?

Kind regardsYes, C or C++
Thanks for comment!

matt_symes
November 8th, 2011, 09:56 AM
Hi

Try writing to it as you would any device node.

Best of luck. It sounds like an interesting project.

Kind Regards

mtangoo
November 8th, 2011, 03:05 PM
Hi

Try writing to it as you would any device node.

Do you mean using ifstream/ofstream or what?
Should I treat it as file?

Best of luck. It sounds like an interesting project.

Kind Regards
Quiet interesting

matt_symes
November 8th, 2011, 07:12 PM
Hi


Should I treat it as file?Yes. Just treat it like a normal file. Be aware of permissions on the node.


Do you mean using ifstream/ofstream or what?

I have never tried it in C++. Can't see it being different though as you are still writing to a file.

In C you fopen, fread, fputs, fwrite, fclose.

Have a look at this C example. It may give you some ideas. I don't know how sophisticated your program needs to be.

http://www.comptechdoc.org/os/linux/programming/c/linux_pgcserial.html

Kind regards

mtangoo
November 8th, 2011, 07:23 PM
Hi

Yes. Just treat it like a normal file. Be aware of permissions on the node.



I have never tried it in C++. Can't see it being different though as you are still writing to a file.

In C you fopen, fread, fputs, fwrite, fclose.

Have a look at this C example. It may give you some ideas. I don't know how sophisticated your program needs to be.

http://www.comptechdoc.org/os/linux/programming/c/linux_pgcserial.html

Kind regards
I appreciate your help and link!

takobaba
May 5th, 2013, 03:47 PM
Hi I need to send AT Command to Linux device (Modem/Phone) connected via USB. Is there a way? I'm reading about libudev right now. Is it good solution?
Thanks!



hi
recently i was searching for this and i got the solution with pyserial which is really simple to use as i found.

here is my little script for you if you wanna take a look



#!/usr/bin/env python

import serial
import time

tarik = " "
ser = serial.Serial("/dev/ttyUSB0",115200, 8, 'N', 1, timeout=None)


this is a code that opens connection to device

/dev/ttyUSB0
with baud rate of 115200
data bits of 8
parity of none
stop bit of 1
timeout set to None

cheers