You are not logged in.

#1 2013-01-18 13:05:21

kometonja
Member
Registered: 2012-12-28
Posts: 10

[SOLVED] debugging LED badge on pl2303 interface

hello.
i found this led badge which is programmable via usb <-> rs232 cable (pl2303 driver). it looks like this (but its probably not the same particular model):
led bagde example

i have a windows program for programming it and can run using WINE, but would like to implement some kind of driver (either user space or kernel module)  so i can output current song, temperature, etc. on it.
i am aware that similar projects/drivers exist but none of them worked for me and i would like to learn from doing it.

can please someone point me in a right direction because i'm kinda stuck.

for an example; sending string "AAA" from wine ./LED.exe
1) when sniffing /dev/ttyUSB0 i recieve no data.

2)then i found this: http://www.kernel.org/doc/Documentation/usb/usbmon.txt and i can capture data with command # cat /sys/kernel/debug/usb/usbmon/2t (or even with wireshark...) (it has pretty much data)
3) when sniffing serial port under ms windows, packet looked something like this: 0xFB 0x02 (..add up to 10 numbers here, dont have them right now..) 0x01 0x01 0x01 0xFB

after a bit of experimenting everything had sense: 0xFB would be packet start, 0x02 message number, 0x01 = "A" and so on.
packets are sent one by one, not whole buffer.

made a test python program for that matter which sends exactly same data but with no luck.
i'm sure serial port /dev/ttyUSB0 is opened in right manner (parity, baudrate..)

i compared /sys/kernel/debug/usb/usbmon/2t for both python and wine ./LED.exe and it seems that second one (program that works) sent some additional data between opening device and first byte of packet ('0xFB')
i cannot understand what that might be, and how to transform that numbers into function call.
i plan to implement it using C language if that matters.

can somebody please point me what to do? i can send both test python program and usbmon log when come home..
the thing that got me confused is that "additional data" doesn't look like tcsetattr, read or write. is there some ioctl i am not aware of..?

huh, pretty long post, thanks in advance

Last edited by kometonja (2013-01-25 11:12:59)

Offline

#2 2013-01-18 19:41:42

moetunes
Member
From: A comfortable couch
Registered: 2010-10-09
Posts: 1,012

Re: [SOLVED] debugging LED badge on pl2303 interface

It would help to know the brand and model of the device.
I found this python example
http://stackoverflow.com/questions/1196 … z-in-linux
but don't know if it is relevant 'cause I don't know what device you have but it might give you a clue.

Edit:
    http://www.linuxjournal.com/article/7353 is a nice read and might have clues too.

Last edited by moetunes (2013-01-18 19:43:52)


You're just jealous because the voices only talk to me.

Offline

#3 2013-01-19 00:36:44

nomorewindows
Member
Registered: 2010-04-03
Posts: 2,943

Re: [SOLVED] debugging LED badge on pl2303 interface

Pl2303 is just your usb-serial bridge. 
Windows NT had portmon which was good for sniffing serial connections.
If you have a bone-fide serial port available, you won't have to work around the sometimes buggy pl2303 chip.
Or you could use a serial to ethernet program on your win machine, and do whatever to your device from linux connecting to it with socat.


I may have to CONSOLE you about your usage of ridiculously easy graphical interfaces...
Look ma, no mouse.

Offline

#4 2013-01-19 02:55:29

kometonja
Member
Registered: 2012-12-28
Posts: 10

Re: [SOLVED] debugging LED badge on pl2303 interface

thanks for replay and links but i need serial, not usb communication.

it turns out my port settings were wrong after all.
when i run it under wine, and then run my program with removed port setting (leaving parameters as they are) it works fine.
so, after wine program port setting are:

$ stty -a -F /dev/ttyUSB0
speed 1200 baud; rows 0; columns 0; line = 0;
intr = ^C; quit = ^\; erase = ^?; kill = ^U; eof = ^D; eol = <undef>; eol2 = <undef>; swtch = <undef>; start = ^Q;
stop = ^S; susp = ^Z; rprnt = ^R; werase = ^W; lnext = ^V; flush = ^O; min = 0; time = 0;
-parenb -parodd cs8 -hupcl -cstopb cread clocal -crtscts
ignbrk -brkint -ignpar -parmrk -inpck -istrip -inlcr -igncr -icrnl -ixon -ixoff -iuclc -ixany -imaxbel -iutf8
-opost -olcuc -ocrnl onlcr -onocr -onlret -ofill -ofdel nl0 cr0 tab0 bs0 vt0 ff0
-isig -icanon -iexten -echo -echoe -echok -echonl noflsh -xcase -tostop -echoprt -echoctl -echoke

my port initialization in program is following:

   tcgetattr(fd, &options);

    cfsetispeed(&options, B9600);
    cfsetospeed(&options, B9600);
    options.c_cflag |= (CLOCAL | CREAD);
    options.c_cflag &= ~PARENB;
    options.c_cflag &= ~CSTOPB;
    options.c_cflag &= ~CSIZE;
    options.c_cflag |= CS8;
    options.c_cflag &= ~( ICANON | ECHO | ECHOE |ISIG );
    options.c_iflag &= ~(IXON | IXOFF | IXANY );
    options.c_iflag |= IGNBRK;
    options.c_oflag |= ONLCR;

    options.c_oflag &= ~(OCRNL|ONLRET|NLDLY|CRDLY|TABDLY|BSDLY|VTDLY|FFDLY);

    tcsetattr(fd, TCSANOW, &options);

i've tried setting speed on B1200 but didn't work.
What is wrong in this options?

Offline

#5 2013-01-25 11:13:54

kometonja
Member
Registered: 2012-12-28
Posts: 10

Re: [SOLVED] debugging LED badge on pl2303 interface

Device had to be set to RAW mode.
cfmakeraw() did the trick

Offline

Board footer

Powered by FluxBB