PDA

View Full Version : How do I get a file from a serial device



jimpm
16th May 2008, 05:38 PM
good afternoon,
I have a serial barcode scanner which works in standalone mode (not attached to a PC) and accumulates data in a file called data.csv. The manufacturer told me that this is on an 8.3 fat fs but that is all they would tell me because they have a proprietary app for downloading that file to windows. I need to be able to download the file (or data only) to my postgresql db on fedora 9. I have no problem communicating with the device through minicom. I can set parameters baud=38400, parity=none, data=8, stop=1 and see everything the device does while it is connected to my computer. Data in the file is a coupon number (scanned) a transaction amount and a date and probably a \n\r since it is a windows file although I havent checked that yet. Data looks like: 0000624997,12.80,04-23-2008
0000624998,15.00,04-23-2008
0000624996,22.95,04-23-2008
I don't know windows well enough to see what the proprietary app does to get the file. Any thoughts on how to access this. All help or ideas will be greatly appreciated.
Jim

PabloTwo
16th May 2008, 06:22 PM
Sounds like a tough nut to crack. You would need to know precisely what that Windows based proprietary software is sending to the barcode scanner device that would cause it to send the data.csv file (or the contents of that file) to the computer. Then you would need to send that same command string to the device from minicom (or some other serial port capable application) while in Linux. The command string could contain non-standard ASCII characters, making it difficult (or impossible) to input them at the keyboard.

Probably the only way to sniff out what command string you need would be to use a serial port monitor program while in Windows, preferably one that will log everything to a log file, and exercise that function in Windows then examine the log file and see if you can determine exactly which string of characters is the "command" you're looking for. I did a google search on serial port monitoring software for Windows and (there is a bunch of it, mostly commercial for a price) but I did spot one freebie... checkout the link below.

http://www.download.com/3001-2218_4-10395968.html?spi=a5b30d2f08c26ca2761f20951ac6231e&part=dl-FreeSeria

jimpm
16th May 2008, 06:38 PM
Thanks PabloTwo, great idea. I have downloaded that software and will try to see what is happening when windows contacts the scanner. The scanner doesn't really send the file, the proprietary software opens a file browser window and you drag and drop the file from the device side to the computer side. To my feeble mind that suggests that I could use a script to get the file since I can connect to the device. My issue is that I am used to reading from stdin/stdout and don't know how to proceed to get or dump this file.

PabloTwo
16th May 2008, 06:47 PM
Hmm... sounds like it's a bit more complicated than just sending code that says: "send me the data". The Windows software is actually seeing the device as a storage device (over the serial port). Maybe the serial monitoring software will provide some clues to you, I don't know.

If there is a way in Linux to 'mount' a vfat storage device over a serial port line, I have no clue as to how that would be done. Maybe someone else does.

manoloko
16th May 2008, 07:51 PM
if the device is realy a storage device shouldn,t it have an entry or something in /dev/serial1 or /dev/com1 or anything like that. Then you can try mounting it and see what happens.

jimpm
16th May 2008, 08:13 PM
The following is the result of running the serial port monitor while opening the port and copying the file using the windows software.

Read requests

Port opened by process "Unitech.MultiEj.exe" (PID: 3412)

02 1B 44 46 4F 52 4D 2E 53 45 54 2C 45 5A 4A 42 ..DFORM.SET,EZJB
2E 45 4A 53 2C 7E 52 55 4E 52 41 4D 2E 45 4A 42 .EJS,~RUNRAM.EJB
2C 44 41 54 41 2E 43 53 56 2C 44 47 03 02 1B 4A ,DATA.CSV,DG...J
00 30 30 30 31 37 38 49 4E 03 02 1B 4A 00 30 30 .000178IN...J.00
30 32 38 32 49 4A 03 02 1B 4A 00 30 30 30 31 35 0282IJ...J.00015
35 49 49 03 02 1B 4A 00 30 30 30 31 34 35 49 48 5II...J.000145IH
03 02 1B 4A 00 30 30 30 31 34 35 49 48 03 02 03 ...J.000145IH...
06 02 1B 59 30 30 30 30 36 32 34 39 39 34 2C 31 ...Y0000624994,1
32 2E 35 30 2C 30 34 2D 32 39 2D 32 30 30 38 5C 2.50,04-29-2008\
8D 5C 8A 30 30 30 30 36 32 35 39 38 33 2C 32 35 \?0000625983,25
2E 33 35 2C 30 34 2D 32 39 2D 32 30 30 38 5C 8D .35,04-29-2008\
5C 8A 30 30 30 30 30 32 35 38 33 36 2C 31 32 2E \?0000025836,12.
35 30 2C 30 34 2D 32 39 2D 32 30 30 38 5C 8D 5C 50,04-29-2008\\
8A 30 30 30 30 36 32 34 39 39 34 2C 31 32 2E 35 ?0000624994,12.5
30 2C 30 35 2D 30 37 2D 32 30 30 38 5C 8D 5C 8A 0,05-07-2008\\?
30 30 30 30 36 32 34 39 39 37 2C 31 35 2E 30 30 0000624997,15.00
2C 30 35 2D 31 34 2D 32 30 30 38 5C 8D 5C 8A 46 ,05-14-2008\\?F
40 03 02 1B 5A 47 47 03 @...ZGG.



write requests

Port opened by process "Unitech.MultiEj.exe" (PID: 3844)

02 1B 44 42 42 C1 06 02 1B 4A 46 4F 52 4D 2E 53 ..DBB...JFORM.S
45 54 47 4E C1 02 1B 4A 45 5A 4A 42 2E 45 4A 53 ETGN..JEZJB.EJS
46 4B C1 02 1B 4A 7E 52 55 4E 52 41 4D 2E 45 4A FK..J~RUNRAM.EJ
42 48 45 C1 02 1B 4A 44 41 54 41 2E 43 53 56 46 BHE..JDATA.CSVF
44 C1 02 1B 4A 44 41 54 41 2E 43 53 56 46 44 C1 D..JDATA.CSVFD
07 C1 02 1B 55 44 41 54 41 2E 43 53 56 46 4F C1 ...UDATA.CSVFO
06 02 1B 59 43 47 C1 06 02 1B 59 43 47 C1 06 ...YCG...YCG.

Unfortunately I don't read hex. Does anyone have an editor that they know how to use?

PabloTwo
16th May 2008, 08:21 PM
The device would be mounted to /dev/ttySx (most likely ttyS0). I'm not sure fdisk would automatically look at ttySx devices for a "filesystem", but you could always do 'fdisk -l' and see what shows up, other than the usual suspects. When you plug in a USB storage device, kudzo finds it in short order and a new icon pops up on your desktop to indicate a new fs has been found and auto mounts it. If that doesn't happen with the Serial port scanner, then the system is not seeing it as a storage device, though it obviously contains one.

manoloko
16th May 2008, 08:37 PM
It isnt that dificult to understand:


02 1B 44 46 4F 52 4D 2E 53 45 54 2C 45 5A 4A 42 ..DFORM.SET,EZJB
2E 45 4A 53 2C 7E 52 55 4E 52 41 4D 2E 45 4A 42 .EJS,~RUNRAM.EJB
2C 44 41 54 41 2E 43 53 56 2C 44 47 03 02 1B 4A ,DATA.CSV,DG...J - Im not sure, but this may be the file name or something related
00 30 30 30 31 37 38 49 4E 03 02 1B 4A 00 30 30 .000178IN...J.00
30 32 38 32 49 4A 03 02 1B 4A 00 30 30 30 31 35 0282IJ...J.00015
35 49 49 03 02 1B 4A 00 30 30 30 31 34 35 49 48 5II...J.000145IH
03 02 1B 4A 00 30 30 30 31 34 35 49 48 03 02 03 ...J.000145IH...
06 02 1B 59 30 30 30 30 36 32 34 39 39 34 2C 31 ...Y0000624994,1 - Here is an code
32 2E 35 30 2C 30 34 2D 32 39 2D 32 30 30 38 5C 2.50,04-29-2008\ - Folowed by a ',' and the price, then an another ',' and a date
8D 5C 8A 30 30 30 30 36 32 35 39 38 33 2C 32 35 \?0000625983,25 - an another code
2E 33 35 2C 30 34 2D 32 39 2D 32 30 30 38 5C 8D .35,04-29-2008\
5C 8A 30 30 30 30 30 32 35 38 33 36 2C 31 32 2E \?0000025836,12. - more one code
35 30 2C 30 34 2D 32 39 2D 32 30 30 38 5C 8D 5C 50,04-29-2008\\
8A 30 30 30 30 36 32 34 39 39 34 2C 31 32 2E 35 ?0000624994,12.5 - an next code
30 2C 30 35 2D 30 37 2D 32 30 30 38 5C 8D 5C 8A 0,05-07-2008\\?
30 30 30 30 36 32 34 39 39 37 2C 31 35 2E 30 30 0000624997,15.00 - and the last code
2C 30 35 2D 31 34 2D 32 30 30 38 5C 8D 5C 8A 46 ,05-14-2008\\?F
40 03 02 1B 5A 47 47 03 @...ZGG. - Dont know what this last line means

This may be the string the program sends to receive the file, I could read only one line of it

02 1B 44 42 42 C1 06 02 1B 4A 46 4F 52 4D 2E 53 ..DBB...JFORM.S
45 54 47 4E C1 02 1B 4A 45 5A 4A 42 2E 45 4A 53 ETGN..JEZJB.EJS
46 4B C1 02 1B 4A 7E 52 55 4E 52 41 4D 2E 45 4A FK..J~RUNRAM.EJ - RUMRAM should mean something important
42 48 45 C1 02 1B 4A 44 41 54 41 2E 43 53 56 46 BHE..JDATA.CSVF
44 C1 02 1B 4A 44 41 54 41 2E 43 53 56 46 44 C1 D..JDATA.CSVFD - you can read DATA.CSV, this may be the file name
07 C1 02 1B 55 44 41 54 41 2E 43 53 56 46 4F C1 ...UDATA.CSVFO - The same again
06 02 1B 59 43 47 C1 06 02 1B 59 43 47 C1 06 ...YCG...YCG.

I wish I could help you more, but its dificult for me, a C# programer who loves linux, to create something in linux to recover the data. But if you can recover the string that the program uses to request the file I may try to create something to be run in mono. See if you can get this string.

jimpm
16th May 2008, 09:05 PM
Thanks for the comments, I really appreciate the help. First PabloTwo is right, in Fedora the scanner is /dev/ttyS2 but if I try to mount it as a vfat fs there is nothing to read at the mount point(/mnt/scanner).
Manaloko, you are on to something but I don't know how to use it. I agree that my data is in the write output and that runram.ejb is probably what windows calls to dump the data. Maybe it isn't a fat fs but a ram type fs with an 8.3 file format. I'll try mounting different fs tonight when I get home. (only windows on desktop at work)

PabloTwo
16th May 2008, 09:06 PM
The pattern I see here is that the hex characters "02 1B", both of which are 'not printable' in ascii, seem to be command control characters akin and equivelent to the more familiar Hayes modem command set "AT". In other words, "02 1B" means 'attention, command(s) and pararmeters follow...'. But other than that, it's pretty hard to decipher the meaning of anything that trails those two leading bits. The next bit or two could be the actual 'command', and there could be a checksum bit, or a bit or two to indicate the total length of the string before the next "02 1B" bits. Code crack'n isn't easy.

jimpm
16th May 2008, 09:12 PM
BTW manoloko any ideas how I could get the string that calls for the file? We probably could do something in mono with this because I had to upgrade .net on my machine to run the windows stuff.

manoloko
16th May 2008, 09:28 PM
BTW manoloko any ideas how I could get the string that calls for the file? We probably could do something in mono with this because I had to upgrade .net on my machine to run the windows stuff.

The string must be something that the program sends in the axact moment that you try to copy the file. Then the file is sent to the program and the program writes the file in directory you specified. In the beginning I thought it was the program that create the file and the device just send us the data, that would be easy. But now Im not so sure, try looking in google for more information and try to fin out if the device uses an fs or just some kind if database. that would help us a lot.

I took an another look at the HexCode and I thing line breaks are represented by '\\?' or something its a begining.

Im not sure if I can make the mono program right now. My computer is having problens so I sent it back to the place where I bought it, some problem with my hardware, so I have no computer. I will see if my sister will alow me to use her computer(my old one) to create the program, but Im not sure. I will do my best.

jimpm
16th May 2008, 09:40 PM
PabloTwo and Manoloko thanks for all your help this afternoon. I'm leaving work now and need to pick my wife up at her job and then we will get some dinner, so I will not be posting again until later tonight or tomorrow. Thanks again.