Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Read data from virtual COM port

2,632 views
Skip to first unread message

te...@testnospam.nl

unread,
Aug 4, 2010, 7:04:33 PM8/4/10
to
Maybe not the best newsgroup to ask this, but I'm giving it a try.

I have a device that sends and receives data via a COM port (actually
this is a serial USB device).

Right now I use Terminal to read and send data to-and-fro.
I want to make this a bit more professional. :-)

The data from the device must be stored in a file that I can use later
to analyse.
The perfect way should be to import the data right in Excel, but this
doesn't seems so simple.

A batch file that stores the data in a file would be great to start
with.

I will make the device so that it listens on it's com port to a
certain command. This command can be a single string like "b".
When the device receives the "g" it waits a few moments and the starts
to send it's data until it is done. Maybe I can make the device to
send an "end" string.

So what I need is a batch that starts to send a string every few
moments. If there is no reply from "the device", it waits and sends
the string again.

If the device is awake and receives the "begin" string, it changes
from listening to sending.
It sends its buffer like three bytes like this:
017 125 205
018 125 127
019 125 011
020 001 017

The batch should just write these lines to a csv-file and at the end
quit.

Anyone an idea??

foxidrive

unread,
Aug 4, 2010, 9:29:25 PM8/4/10
to
On Thu, 05 Aug 2010 01:04:33 +0200, te...@testnospam.nl wrote:

>I have a device that sends and receives data via a COM port (actually
>this is a serial USB device).
>

>So what I need is a batch that starts to send a string every few
>moments. If there is no reply from "the device", it waits and sends
>the string again.
>
>If the device is awake and receives the "begin" string, it changes
>from listening to sending.
>It sends its buffer like three bytes like this:
>017 125 205
>018 125 127
>019 125 011
>020 001 017
>
>The batch should just write these lines to a csv-file and at the end
>quit.
>
>Anyone an idea??

I think Qbasic or maybe WSH or another HLL is the way to go.
Batch can't do it TTBOMK.


--
Regards,
Mic

te...@testnospam.nl

unread,
Aug 5, 2010, 5:17:28 AM8/5/10
to
On Thu, 05 Aug 2010 11:29:25 +1000, foxidrive <got...@woohoo.invalid>
wrote:

>>The batch should just write these lines to a csv-file and at the end
>>quit.
>>
>>Anyone an idea??
>
>I think Qbasic or maybe WSH or another HLL is the way to go.
>Batch can't do it TTBOMK.

Thanks, I'll look into it!

Ted Davis

unread,
Aug 5, 2010, 10:57:54 AM8/5/10
to
On Thu, 05 Aug 2010 11:29:25 +1000, foxidrive wrote:

> I think Qbasic or maybe WSH or another HLL is the way to go. Batch can't
> do it TTBOMK.

ECHO can send strings to COM ports, but ends each line with CRLF. There
are utilities that output just the given string without the CRLF. I have
used PRINTF.exe for that sort of thing. The syntax is

echo string> COM1:

The : seems to be necessary.

--
Ted Davis (tda...@mst.edu)

foxidrive

unread,
Aug 5, 2010, 12:37:47 PM8/5/10
to

It can't read the serial port though, which is what the OP wanted to do.


--
Regards,
Mic

te...@testnospam.nl

unread,
Aug 5, 2010, 5:46:10 PM8/5/10
to
On Fri, 06 Aug 2010 02:37:47 +1000, foxidrive <got...@woohoo.invalid>
wrote:

>It can't read the serial port though, which is what the OP wanted to do.

Thanks both of you, yes my goal is to communicate between the port and
the device.
Still all help is welcome!

Ted Davis

unread,
Aug 5, 2010, 7:54:30 PM8/5/10
to

If the device can be made to send a ^Z when finished, I think you can
redirect the COM port to a file, or perhaps use it in a FOR /f, though
I'm not quite sure what the syntax would be. It's been *many* years
since I had to do this sort of thing, but I used to communicate between
DOS2 and CP/M PCs by reading and writing the com ports from the command
line and/or batch files (I don't remember the details, except that I had
to set up the DOS COM port with MODE).

--
Ted Davis (tda...@mst.edu)

te...@testnospam.nl

unread,
Aug 6, 2010, 12:22:59 PM8/6/10
to
>If the device can be made to send a ^Z when finished, I think you can
>redirect the COM port to a file, or perhaps use it in a FOR /f, though
>I'm not quite sure what the syntax would be. It's been *many* years
>since I had to do this sort of thing, but I used to communicate between
>DOS2 and CP/M PCs by reading and writing the com ports from the command
>line and/or batch files (I don't remember the details, except that I had
>to set up the DOS COM port with MODE).

I can "see" the COM port with the MODE command, but I don't see how I
can read/write with it...

Tom Lavedas

unread,
Aug 6, 2010, 2:15:55 PM8/6/10
to

Redirection to write to it (say named as com4) ...

echo Data sent to com port> com4

To read from it, try (as suggested by Ted) ...

for /f "tokens=* delims=" %%a in (COM4) do call :Sub "%%a"
goto :EOF

:SUB
:: For example ...
echo FROM COM4: %~1

I don't 'know' that the latter approach will work. It's just the
first thing to try. Note that the last character sent through the
COM4 port might well need to be Ctrl-Z to indicate the end of the
file, but I have no easy way of testing that assertion.
_____________________
Tom Lavedas

Ted Davis

unread,
Aug 6, 2010, 8:25:24 PM8/6/10
to

The colon may be necessary (COM4: instead of COM4).
I can't test either because I still haven't managed to get a replacement
MB - the last vendor said he was checking if they had it in stock, but
never wrote back one way or the other. I could probably use a different
MB as long as I *knew* it would run XP ... and if I could find the
original OEM CD (which is not where it should be). I could set up a test
(I know how to make null modem cables, and might even have one left over
from ages ago), but testing between two Linux machines would not help at
all.

--
Ted Davis (tda...@mst.edu)

te...@testnospam.nl

unread,
Aug 7, 2010, 12:41:32 AM8/7/10
to
>> I can "see" the COM port with the MODE command, but I don't see how I
>> can read/write with it...
>
>Redirection to write to it (say named as com4) ...
>
> echo Data sent to com port> com4
>
>To read from it, try (as suggested by Ted) ...
>
> for /f "tokens=* delims=" %%a in (COM4) do call :Sub "%%a"
> goto :EOF
>
> :SUB
>:: For example ...
> echo FROM COM4: %~1
>
>I don't 'know' that the latter approach will work. It's just the
>first thing to try. Note that the last character sent through the
>COM4 port might well need to be Ctrl-Z to indicate the end of the
>file, but I have no easy way of testing that assertion.
>_____________________
>Tom Lavedas

Oh my!!
I'm going to test it later today, if this work..... oh my!!!!

Thanks all of you! :-)

Frank P. Westlake

unread,
Aug 7, 2010, 9:02:16 AM8/7/10
to
"foxidrive" news:t4ql56h0949unrrlf...@4ax.com...

>> echo string> COM1:

> It can't read the serial port though, which is what the OP wanted to
> do.

Doesn't this still work?

TYPE COM1: >file

I don't have anything to plug in so I can't verify it for myself.

Frank


te...@testnospam.nl

unread,
Aug 7, 2010, 10:45:40 AM8/7/10
to
Its alive!!! :-)

So far I've got these:

Set up the communication with COM9

MODE COM9:19200,N,8,1,P

This returns the status for the COM9 port.
How can I check the error code so I can check if the device is ready?
If I disconnect the device and try to setup the communication, DOS
returns a message that the device is not valid.

ECHO "b" > COM9

This is the signal the device needs to start sending data.
I've set the device that it just starts sending data after it received
a "b" (for Begin).
This works, the device starts sending data after DOS sends this "b".
When I open hyperterminal to read the data from the device and try to
send the "b", DOS answers that connection to the device is refused.
Because another application uses the COM9 connection.
This I want to check too in the batch file to check for errors.

TYPE COM9: >c:\fromserial.csv

This one is tricky.
When I issue this sometimes it doesn't do anything, sometimes it
works.
This is because the device sends data every 5 seconds, this is how its
programmed right now.
Later I will change this but I can't change the device right now.

What I want to become is a combination of these commands in a batch
file that checks every step of the way if everything is still working.

The ultimate goal is to get it work as follow:

Setup the settings for the device and check if this is successful.
(mode com9...)
After pressing the "b" on the keyboard, send the begin signal to the
device (and check if the connection is made (if not send an error
message to the DOS screen and terminate the connection)).

After the start signal is issued and successful accepted by the
device, begin listening to the device and check the data.
The data will be in this format:
1,120,17
2,11,125

So three bytes separated by a comma and a carriage return (or new
line)
The device will start sending zero's when there is no more data.
So if the received data is
2,11,125
0,0,0
0,0,0
0,0,0

The batch should end the connection by sending a stop signal to the
device.
echo "e" > com9
(e stands for END)

So the batch should listen for a serie of zero-bytes.
I don't care how many zero-bytes it checks before it sends the "e"
(end) signal.
Maybe 10 series of 3 zero's?

With all these, do you think it's possible to make something that
going to work and is a bit robust?
I'm not an expert in batch, you guys have already helped me well.
I thank you all again for al previous and future help with this
project.

Thanks guys!!!


foxidrive

unread,
Aug 7, 2010, 11:19:18 AM8/7/10
to
On Sat, 7 Aug 2010 06:02:16 -0700, "Frank P. Westlake"
<frank.w...@gmail.com> wrote:

>"foxidrive" news:t4ql56h0949unrrlf...@4ax.com...
>
>>> echo string> COM1:
>
>> It can't read the serial port though, which is what the OP wanted to
>> do.
>
>Doesn't this still work?
>
> TYPE COM1: >file

I've never seen the com port used for reading. Maybe it can but I don't
have a com port to check.

>I don't have anything to plug in so I can't verify it for myself.

To the OP:

You want to read some control characters which is going to make it even
harder.

If the COM port is sending something in this format, it will make it
more complex because the COM port is not sending a CR/LF or Control Z to
signal EOL or EOF.

byte byte byte null null null


--
Regards,
Mic

te...@testnospam.nl

unread,
Aug 8, 2010, 10:44:36 AM8/8/10
to
>To the OP:
>
>You want to read some control characters which is going to make it even
>harder.
>
>If the COM port is sending something in this format, it will make it
>more complex because the COM port is not sending a CR/LF or Control Z to
>signal EOL or EOF.
>
>byte byte byte null null null

Thanks Foxydrive!

I've tried it, see my post from yesterday.
It works, I can send and receive bytes.
This is all I need.

The way I need it to work is described in my post I did yesterday.
Now is the real challenge to make a batchfile with the things that
work.. Again I could use some help :-s

foxidrive

unread,
Aug 8, 2010, 2:16:29 PM8/8/10
to
On Sun, 08 Aug 2010 16:44:36 +0200, te...@testnospam.nl wrote:

>I've tried it, see my post from yesterday.
>It works, I can send and receive bytes.
>This is all I need.
>
>The way I need it to work is described in my post I did yesterday.
>Now is the real challenge to make a batchfile with the things that
>work.. Again I could use some help :-s

Can you run these three and zip up the three csv files and post them
someplace? I need to see the output to be able to write a batch.

@echo off
MODE COM9:19200,N,8,1,P
echo b> com9
TYPE COM9: >c:\fromserial1.csv
echo e> com9
pause


@echo off
MODE COM9:19200,N,8,1,P
echo b> com9
for /f "delims=," %%a in ('TYPE COM9:') do echo %%a>>c:\fromserial2.csv
echo e> com9
pause


@echo off
MODE COM9:19200,N,8,1,P
echo b> com9
for /f "delims=" %%a in ('TYPE COM9:') do echo %%a>>c:\fromserial3.csv
echo e> com9
pause


--
Regards,
Mic

te...@testnospam.nl

unread,
Aug 8, 2010, 6:01:14 PM8/8/10
to
>Can you run these three and zip up the three csv files and post them
>someplace? I need to see the output to be able to write a batch.
>
>@echo off
>MODE COM9:19200,N,8,1,P
>echo b> com9
>TYPE COM9: >c:\fromserial1.csv
>echo e> com9
>pause
>
>
>@echo off
>MODE COM9:19200,N,8,1,P
>echo b> com9
>for /f "delims=," %%a in ('TYPE COM9:') do echo %%a>>c:\fromserial2.csv
>echo e> com9
>pause
>
>
>@echo off
>MODE COM9:19200,N,8,1,P
>echo b> com9
>for /f "delims=" %%a in ('TYPE COM9:') do echo %%a>>c:\fromserial3.csv
>echo e> com9
>pause

Great work Foxy,

Here is the zipped file with the return of the batch files.
http://rapidshare.com/files/411826440/fromserial.zip
MD5: F6198A0BD14A6089747F98ED60064EF9

And here in Rar-format
http://rapidshare.com/files/411825854/fromserial.rar
MD5: 67C4C8106F1FB8A4F8A41FF82A9CDF51

I noticed that the *.csv files must exist before the begin "b" signal
is send.
If they don't exist the batch is beyond the point of reading the
device before the *.csv files are generated on my PC.

The output in the csv files are random generated, they always end with
7 timer three 0 bytes.

Thanks you

foxidrive

unread,
Aug 9, 2010, 4:59:49 AM8/9/10
to

This is all untested:

It should tell you if no data has beeen received and abort.

It will check for a single case of 0,0,0 and abort the transfer.

What it doesn't do at this stage is verify that the com port has been
setup correctly, but it should say "The COM port is not responding"
anyway and abort.


@echo off
set "file=c:\fromserial3.csv"
MODE COM9:19200,N,8,1,P
rem.>"%file%"
echo b> com9

for /f "delims=" %%a in ('TYPE COM9: 2^>nul') do (
if not "%%a"=="0,0,0" echo %%a>>"%file%"
if "%%a"=="0,0,0" goto :next
)
:next

for %%a in ("%file%") do if %%~za EQU 0 (
echo The COM port is not responding
del "%file%" 2>nul
pause
goto :EOF
)

echo e> com9
echo The capture has ended
echo Any data captured should be in "%file%"
pause

--
Regards,
Mic

te...@testnospam.nl

unread,
Aug 9, 2010, 4:12:23 PM8/9/10
to

Great thanks Foxy,

Is this right? I numbered the lines just to ask if there isn't a line
cut in two.
The problem is that now it only receives the first line of code
(0,1,9<LF><CR>), and then hangs.

The bytes come in one by one, so for the 0,0,0<LF><CR> this means that
the batch will see "0" then "," again "0", then "," and so on.
Never 0,0,0.
So it should search for several 0's followed by comma's and a
<LF><CR>.
Can this be done with the batch?

[1] @echo off
[2] set "file=c:\fromserial3.csv"
[3] MODE COM9:19200,N,8,1,P
[4] rem.>"%file%"
[5] echo b> com9
[6]
[7] for /f "delims=" %%a in ('TYPE COM9: 2^>nul') do (
[8] if not "%%a"=="0,0,0" echo %%a>>"%file%"
[9] if "%%a"=="0,0,0" goto :next
[10] )
[11] :next
[12]
[13] for %%a in ("%file%") do if %%~za EQU 0 (
[14] echo The COM port is not responding
[15] del "%file%" 2>nul
[16] pause
[17] goto :EOF
[18] )
[19]
[20] echo e> com9
[21] echo The capture has ended
[22] echo Any data captured should be in "%file%"
[23] pause

foxidrive

unread,
Aug 9, 2010, 7:35:22 PM8/9/10
to
On Mon, 09 Aug 2010 22:12:23 +0200, te...@testnospam.nl wrote:

>Is this right? I numbered the lines just to ask if there isn't a line
>cut in two.

No, I think it's ok.

>The problem is that now it only receives the first line of code
>(0,1,9<LF><CR>), and then hangs.
>
>The bytes come in one by one, so for the 0,0,0<LF><CR> this means that
>the batch will see "0" then "," again "0", then "," and so on.
>Never 0,0,0.

I've had a closer look at the files - there is no CR/LF but only a LF.

Try this - the code is the same but the MORE command is added in the
forindo command.

Depending on how the bytes are processed by the forindo it may still
need work. As I see it each set of 5 bytes "1,2,3" will be delimited by
a CR/LF and then should processed as a unit - but see what happens
anyway.


@echo off
set "file=c:\fromserial3.csv"
MODE COM9:19200,N,8,1,P
rem.>"%file%"
echo b> com9

for /f "delims=" %%a in ('TYPE COM9: 2^>nul^ |more') do (


if not "%%a"=="0,0,0" echo %%a>>"%file%"
if "%%a"=="0,0,0" goto :next
)
:next

for %%a in ("%file%") do if %%~za EQU 0 (
echo The COM port is not responding
del "%file%" 2>nul
pause
goto :EOF
)

echo e> com9
echo The capture has ended
echo Any data captured should be in "%file%"
pause


--
Regards,
Mic

Ted Davis

unread,
Aug 9, 2010, 7:43:27 PM8/9/10
to
On Mon, 09 Aug 2010 22:12:23 +0200, test wrote:

> I numbered the lines just to ask if there isn't a line cut in two.

The convention here is to indent real lines two spaces and let them wrap
- anything against the left margin belongs to the line above.

--
Ted Davis (tda...@mst.edu)

te...@testnospam.nl

unread,
Aug 10, 2010, 12:52:10 PM8/10/10
to

Thank you Foxy, but still it won't work..

After I removed the space before "|more" it does something more, but
still doesn't write to the csv file.

Is there an other possibility?
Maybe if we could tell the batch to capture a certain amount of data?
Let's say 1000 times the serie x,x,x<LF><CR>?
And then end?

This way I maybe get a file with a few hundred 0,0,0, but I could
filter them out later?

So make the batch more simpel by just send the "b" and then capture
series for a certain number of times? After that send the "e" to the
device.

Maybe later we could find a way to search in the CSV for series 0,0,0
(like with GAWK), and delete them?

Maybe this would be more successfully?
I appreciate al your help!

Still not sure about the conventions for breaking up lines.
All lines in my newsreader start at the left most side.

te...@testnospam.nl

unread,
Aug 10, 2010, 12:53:01 PM8/10/10
to
On 9 Aug 2010 23:43:27 GMT, Ted Davis <tda...@mst.edu> wrote:

>On Mon, 09 Aug 2010 22:12:23 +0200, test wrote:
>
>> I numbered the lines just to ask if there isn't a line cut in two.
>
>The convention here is to indent real lines two spaces and let them wrap
>- anything against the left margin belongs to the line above.

Thanks Ted, but in my newsreader every line starts at the left most
side, never any spacing before a line.

Ted Davis

unread,
Aug 10, 2010, 7:14:10 PM8/10/10
to

When did Agent start doing that? It's not like them to do that ...
unless there is an HTML mode - HTML for newsgroups is a Microsoft
invention; it is not standard ... not according to RFC977 (NNTP defining
RFC).

--
Ted Davis (tda...@mst.edu)

foxidrive

unread,
Aug 10, 2010, 9:54:39 PM8/10/10
to
On 11/08/2010 02:52, te...@testnospam.nl wrote:

> After I removed the space before "|more" it does something more, but
> still doesn't write to the csv file.

What does it do??

Try this and tell me what is written to the file.


@echo off
set "file=c:\fromserial3.csv"
MODE COM9:19200,N,8,1,P
rem.>"%file%"
echo b> com9

for /f "delims=" %%a in ('TYPE COM9: 2^>nul ^|more') do (

echo %%a>>"%file%"
)
:next

for %%a in ("%file%") do if %%~za EQU 0 (
echo The COM port is not responding
del "%file%" 2>nul
pause
goto :EOF
)

echo e> com9
echo The capture has ended
echo Any data captured should be in "%file%"
pause

> Still not sure about the conventions for breaking up lines.
> All lines in my newsreader start at the left most side.

I don't indent my code unless it is longer than 76ish characters.


--
Regards,
Mic

te...@testnospam.nl

unread,
Aug 11, 2010, 5:57:59 AM8/11/10
to
>On 11/08/2010 02:52, te...@testnospam.nl wrote:
>
>> After I removed the space before "|more" it does something more, but
>> still doesn't write to the csv file.
>
>What does it do??
>
>Try this and tell me what is written to the file.
>
>
>@echo off
>set "file=c:\fromserial3.csv"
>MODE COM9:19200,N,8,1,P
>rem.>"%file%"
>echo b> com9
>
>for /f "delims=" %%a in ('TYPE COM9: 2^>nul ^|more') do (
>echo %%a>>"%file%"
>)
>:next
>
>for %%a in ("%file%") do if %%~za EQU 0 (
>echo The COM port is not responding
>del "%file%" 2>nul
>pause
>goto :EOF
>)
>
>echo e> com9
>echo The capture has ended
>echo Any data captured should be in "%file%"
>pause
>

It writes absolutly nothing to the file.
I can see that the device is triggered, but the batchfile ends before
all data is send.
The file is created but stays empty.
If I receive the data via a serial port monitor it looks like this:

b
0,1,9<LF>
1,2,8<LF>
2,3,7<LF>
3,4,6<LF>
4,5,5<LF>
5,6,4<LF>
6,7,3<LF>
0,0,0<LF>
0,0,0<LF>
0,0,0<LF>
0,0,0<LF>
0,0,0<LF>
0,0,0<LF>
0,0,0<LF>

Could it be a timing problem?

foxidrive

unread,
Aug 11, 2010, 7:57:39 AM8/11/10
to
On Wed, 11 Aug 2010 11:57:59 +0200, te...@testnospam.nl wrote:

Try this and tell me what is written to the file.

@echo off
set "file=c:\fromserial3.csv"
MODE COM9:19200,N,8,1,P
rem.>"%file%"
echo b> com9

for /f "delims=" %%a in ('TYPE COM9: 2^>nul') do (
echo %%a>>"%file%"
)

echo e> com9
pause

>
>It writes absolutly nothing to the file.
>I can see that the device is triggered, but the batchfile ends before
>all data is send.
>The file is created but stays empty.
>If I receive the data via a serial port monitor it looks like this:
>
>b
>0,1,9<LF>
>1,2,8<LF>
>2,3,7<LF>
>3,4,6<LF>
>4,5,5<LF>
>5,6,4<LF>
>6,7,3<LF>
>0,0,0<LF>
>0,0,0<LF>
>0,0,0<LF>
>0,0,0<LF>
>0,0,0<LF>
>0,0,0<LF>
>0,0,0<LF>
>
>Could it be a timing problem?

Maybe. Try the code above - it essentially is the same as the code you
created the test files with, and also the same as yesterday but with the
MORE command removed.


--
Regards,
Mic

Frank P. Westlake

unread,
Aug 11, 2010, 9:19:06 AM8/11/10
to
I think I also used COPY to read a com port. Maybe something like "COPY
COM9: CON:" will be more useful.

Frank


te...@testnospam.nl

unread,
Aug 11, 2010, 10:31:45 AM8/11/10
to
>Try this and tell me what is written to the file.
>
>@echo off
>set "file=c:\fromserial3.csv"
>MODE COM9:19200,N,8,1,P
>rem.>"%file%"
>echo b> com9
>
>for /f "delims=" %%a in ('TYPE COM9: 2^>nul') do (
>echo %%a>>"%file%"
>)
>
>echo e> com9
>pause

It again writes nothing to the CSV-file.

The for /f... line is broken just behind (
The next line starts with echo %%
I always think that there may be something wrong with broken lines in
my newsreader.

The batch sends the "b" signal to the device (I can tell from the
LED's that light), but then waits.
The batch seems to listen for ever for data, but never receives them.
I have to close the batch manually otherwise it will keep running.

In a serial port monitor the data appear instantly to the screen and
file if I let it write to a file..

>>Could it be a timing problem?
>
>Maybe. Try the code above - it essentially is the same as the code you
>created the test files with, and also the same as yesterday but with the
>MORE command removed.

I could invoke a pause in the device before sending data if this would
solve the problem.

te...@testnospam.nl

unread,
Aug 11, 2010, 10:36:28 AM8/11/10
to
>>Could it be a timing problem?
>
>Maybe. Try the code above - it essentially is the same as the code you
>created the test files with, and also the same as yesterday but with the
>MORE command removed.

Because the batch keeps waiting after issueing the "b" (and the device
tells me that that de data is send), I put a pause of 2 seconds to the
device after receiving the "b" and start sending the data.
Still the batch keeps hanging, seems to listen for data...

te...@testnospam.nl

unread,
Aug 11, 2010, 10:37:20 AM8/11/10
to

Oh, thanks Frank,

How would I use this in the batch created by Foxy?

foxidrive

unread,
Aug 11, 2010, 10:42:45 AM8/11/10
to

It is possible that the com port is sending on STDERR so try the
following modification. I removed the 2>nul item from the forindo
command.


@echo off
set "file=c:\fromserial3.csv"
MODE COM9:19200,N,8,1,P
rem.>"%file%"
echo b> com9

for /f "delims=" %%a in ('TYPE COM9:') do (
echo %%a>>"%file%"
)

echo e> com9
pause


You can try this too but I think the copy command will need a control Z
to terminate the copy.


@echo off
set "file=c:\fromserial3.csv"
MODE COM9:19200,N,8,1,P
rem.>"%file%"
echo b> com9

for /f "delims=" %%a in ('COPY /B COM9: CON:') do (
echo %%a>>"%file%"
)

echo e> com9
pause

--
Regards,
Mic

foxidrive

unread,
Aug 11, 2010, 10:45:06 AM8/11/10
to
On Wed, 11 Aug 2010 16:31:45 +0200, te...@testnospam.nl wrote:

for /f "delims=" %%a in ('TYPE COM9: 2^>nul') do (
echo %%a>>"%file%"
)

>The for /f... line is broken just behind (
>The next line starts with echo %%
>I always think that there may be something wrong with broken lines in
>my newsreader.

As an example the code above is indented and the middle line does indeed
start with "echo %%a"

The ( and ) allow multiple commands on individual lines.

--
Regards,
Mic

te...@testnospam.nl

unread,
Aug 11, 2010, 11:04:24 AM8/11/10
to

No, still the same.
Strange that a few days ago these tests worked.
The serial monitor works like a charm, only the batch won't work :-s

Tom Lavedas

unread,
Aug 11, 2010, 12:15:14 PM8/11/10
to
On Aug 11, 10:42 am, foxidrive <got...@woohoo.invalid> wrote:

Pardon me for butting in here, but it seems to me the problem may lie
in the fact that the batch procedure is waiting for an end-of-file. I
do not think the FOR actually processes anything until it has finished
'reading' the file. That's the problem with doing this in the 'batch'
environment. It works to 'send' stuff to a port, but is just not well
endowed with things to read from them. If the device can be made to
send Control-Zs, then you might get something to work. Otherwise, I'd
look around for a scriptable serial terminal program.
___________________________
Tom Lavedas

te...@testnospam.nl

unread,
Aug 11, 2010, 12:28:25 PM8/11/10
to
>Pardon me for butting in here, but it seems to me the problem may lie
>in the fact that the batch procedure is waiting for an end-of-file. I
>do not think the FOR actually processes anything until it has finished
>'reading' the file. That's the problem with doing this in the 'batch'
>environment. It works to 'send' stuff to a port, but is just not well
>endowed with things to read from them. If the device can be made to
>send Control-Zs, then you might get something to work. Otherwise, I'd
>look around for a scriptable serial terminal program.
>___________________________
>Tom Lavedas

Hey thanks for your input!
Do you mean that the device should send a Control-Z.
Is that an particular ASCII command?

te...@testnospam.nl

unread,
Aug 11, 2010, 12:42:15 PM8/11/10
to
>Pardon me for butting in here, but it seems to me the problem may lie
>in the fact that the batch procedure is waiting for an end-of-file. I
>do not think the FOR actually processes anything until it has finished
>'reading' the file. That's the problem with doing this in the 'batch'
>environment. It works to 'send' stuff to a port, but is just not well
>endowed with things to read from them. If the device can be made to
>send Control-Zs, then you might get something to work. Otherwise, I'd
>look around for a scriptable serial terminal program.
>___________________________
>Tom Lavedas

I've added the SUB byte at the end

b
0,1,9<LF>
1,2,8<LF>
2,3,7<LF>
3,4,6<LF>
4,5,5<LF>
5,6,4<LF>
6,7,3<LF>
0,0,0<LF>
0,0,0<LF>
0,0,0<LF>
0,0,0<LF>
0,0,0<LF>
0,0,0<LF>
0,0,0<LF>

<SUB>

foxidrive

unread,
Aug 11, 2010, 1:14:43 PM8/11/10
to

Do any of the scripts work with that in place?


--
Regards,
Mic

Tom Lavedas

unread,
Aug 11, 2010, 1:20:44 PM8/11/10
to

It's an ASCII code 26 decimal.
_________________________
Tom Lavedas

te...@testnospam.nl

unread,
Aug 11, 2010, 1:37:23 PM8/11/10
to
>>I've added the SUB byte at the end
>>
>>b
>>0,1,9<LF>
>>1,2,8<LF>
>>2,3,7<LF>
>>3,4,6<LF>
>>4,5,5<LF>
>>5,6,4<LF>
>>6,7,3<LF>
>>0,0,0<LF>
>>0,0,0<LF>
>>0,0,0<LF>
>>0,0,0<LF>
>>0,0,0<LF>
>>0,0,0<LF>
>>0,0,0<LF>
>><SUB>
>
>Do any of the scripts work with that in place?

I'm going to test them all again, but what would be the best way to
send them?

Now I send

byte-comma-byte-comma-byte<LF><CR>
byte-comma-byte-comma-byte<LF><CR>
zero-comma-zero-comma-zero<LF><CR>
<SUB>

Is there a better way to send the data??
Is there a way to send first a control byte after sending the "b" from
within the batch?

Maybe a kind of handshaking between the device and the batch?

foxidrive

unread,
Aug 11, 2010, 1:48:35 PM8/11/10
to
On Wed, 11 Aug 2010 19:37:23 +0200, te...@testnospam.nl wrote:

>I'm going to test them all again, but what would be the best way to
>send them?
>
>Now I send
>
>byte-comma-byte-comma-byte<LF><CR>
>byte-comma-byte-comma-byte<LF><CR>
>zero-comma-zero-comma-zero<LF><CR>
><SUB>

It should be <CR><LF> with the CR first.

>Is there a better way to send the data??

That may work with the control Z. The version with the copy command may
even work but remove the /B from the line.

>Is there a way to send first a control byte after sending the "b" from
>within the batch?

I'm not sure what you mean.

>Maybe a kind of handshaking between the device and the batch?

You'd need to use a High Level Language.

--
Regards,
Mic

Ted Davis

unread,
Aug 11, 2010, 8:47:37 PM8/11/10
to
On Wed, 11 Aug 2010 18:28:25 +0200, test wrote:

> Hey thanks for your input!
> Do you mean that the device should send a Control-Z. Is that an
> particular ASCII command?

Recognition of ^Z as end of file applies to text, not binary files, and
goes back to DOS 1. A lot of really stupid thing still present in
Windows DOS enulators date back to DOS 1 and were not 'best practice'
even then.

My understand of the inner workings is that binary files are not parsed
for control characters and are managed by their length field in the file
control block while text files (based on the file name extension) were
parsed for control characters and reading stopped when ^z was encountered
(I think writing would continue to the end of the allocation unit, but
just garbage). Serial devices were handled like text files by
COMMAND.COM's built-in data handling processes (text files and COM ports
are character oriented - disks and binary files are block oriented).

One would have hoped this strange behavior would have gone away with
COMMAND.COM, but A lot of DOS 1 is still there in CMD.EXE.

--
Ted Davis (tda...@mst.edu)

te...@testnospam.nl

unread,
Aug 12, 2010, 10:46:37 AM8/12/10
to
>>Now I send
>>
>>byte-comma-byte-comma-byte<LF><CR>
>>byte-comma-byte-comma-byte<LF><CR>
>>zero-comma-zero-comma-zero<LF><CR>
>><SUB>
>
>It should be <CR><LF> with the CR first.

I've been punishing my brain all day, I found some things that weren't
100% good and adapted them.
Now when I run this:

@echo off
set "file=c:\fromserial3.csv"

MODE COM6:19200,N,8,1,P
rem.>"%file%"
echo b> COM6

for /f "delims=" %%a in ('COPY COM6: CON:') do (
echo %%a>>"%file%"
)

echo e> COM6
pause

I get a csv-file that says " 1 file(s) copied"
This means that things start to work, that's great.
But now only find how I can add the data instead of the message that
one file was copied.

And maybe the test for 0,0,0 ?

Thanks for your patience with me!

foxidrive

unread,
Aug 12, 2010, 10:59:03 AM8/12/10
to

Does the TYPE command one work any differently?


--
Regards,
Mic

te...@testnospam.nl

unread,
Aug 12, 2010, 11:13:11 AM8/12/10
to
>>@echo off
>>set "file=c:\fromserial3.csv"
>>MODE COM6:19200,N,8,1,P
>>rem.>"%file%"
>>echo b> COM6
>>
>>for /f "delims=" %%a in ('COPY COM6: CON:') do (
>>echo %%a>>"%file%"
>>)
>>
>>echo e> COM6
>>pause
>>
>>I get a csv-file that says " 1 file(s) copied"
>>This means that things start to work, that's great.
>>But now only find how I can add the data instead of the message that
>>one file was copied.
>
>Does the TYPE command one work any differently?

That returns an empty csv file (0 byte).

foxidrive

unread,
Aug 12, 2010, 11:22:34 AM8/12/10
to

Something has changed - try these three again to see if they create and
data.


@echo off
MODE COM6:19200,N,8,1,P
echo b> COM6
TYPE COM6: >c:\fromserial1.csv
echo e> COM6
pause


@echo off
MODE COM6:19200,N,8,1,P
echo b> COM6
for /f "delims=," %%a in ('TYPE COM6:') do echo %%a>>c:\fromserial2.csv
echo e> COM6
pause


@echo off
MODE COM6:19200,N,8,1,P
echo b> COM6
for /f "delims=" %%a in ('TYPE COM6:') do echo %%a>>c:\fromserial3.csv
echo e> COM6
pause

--
Regards,
Mic

te...@testnospam.nl

unread,
Aug 12, 2010, 4:52:17 PM8/12/10
to
When I run the same device with a hyperterminal session get this:

COM port is opened
In/out queue size 8192/8192
Baud rate 2400
DTR on
Data bits=8, Stop bits=1, Parity=None
Set chars: Eof=0x00, Error=0x00, Break=0x00, Event=0x00, Xon=0x11,
Xoff=0x13
Handflow: ControlHandShake=(DTR_CONTROL, CTS_HANDSHAKE, ERROR_ABORT),
FlowReplace=(TRANSMIT_TOGGLE, RTS_HANDSHAKE, XOFF_CONTINUE),
XonLimit=80, XoffLimit=200
Set timeouts: ReadInterval=10, ReadTotalTimeoutMultiplier=0,
ReadTotalTimeoutConstant=0, WriteTotalTimeoutMultiplier=0,
WriteTotalTimeoutConstant=5000
b
0,1,15,1,2,16, [len=164]
<LF><SUB>
eb
0,1,15,1,2,16, [len=16]
<LF><SUB>
e
Purge the serial port: RXABORT, TXABORT

-----------------------------------------------------------------------------------------------------------------------
When I run the same with the batch I get this


COM port is opened
COM port is closed
COM port is opened
Baud rate 2400
Data bits=8, Stop bits=1, Parity=None
Set chars: Eof=0x00, Error=0x00, Break=0x00, Event=0x00, Xon=0x11,
Xoff=0x13
Handflow: ControlHandShake=(DTR_HANDSHAKE, CTS_HANDSHAKE,
DSR_HANDSHAKE, ERROR_ABORT), FlowReplace=(TRANSMIT_TOGGLE,
RTS_HANDSHAKE, XOFF_CONTINUE), XonLimit=80, XoffLimit=200
COM port is closed
COM port is opened
COM port is closed
COM port is opened
b [len=1]
<LF>
COM port is closed
COM port is opened
COM port is closed
COM port is opened
COM port is closed
COM port is opened
COM port is closed
COM port is opened
e [len=1]
<LF>
COM port is closed
-----------------------------------------------------------------------------------------------------------------------

Should the batch turn the DTR parameter on?
I know this is beginning to turn into a strange post, but I hope this
will ever work..

The Mode command has these switches:

Serial port: MODE COMm[:] [BAUD=b] [PARITY=p] [DATA=d] [STOP=s]

[to=on|off] [xon=on|off] [odsr=on|off]
[octs=on|off] [dtr=on|off|hs]
[rts=on|off|hs|tg] [idsr=on|off]

How can I turn the DTR on the same line as the baud settings?

Thanks you all!

Dr J R Stockton

unread,
Aug 13, 2010, 4:18:17 PM8/13/10
to
In alt.msdos.batch.nt message <8cgul9...@mid.individual.net>, Thu, 12
Aug 2010 00:47:37, Ted Davis <tda...@mst.edu> posted:

>Recognition of ^Z as end of file applies to text, not binary files, and
>goes back to DOS 1. A lot of really stupid thing still present in
>Windows DOS enulators date back to DOS 1 and were not 'best practice'
>even then.

I believe that it goes back further, to CP/M, in which only the file
size in 128-byte sectors was recorded, with ^Z being used at least when
text did not fill a sector. One wonders why they did not just fill the
sector with NUL characters.

--
(c) John Stockton, nr London, UK. ?@merlyn.demon.co.uk Turnpike v6.05 IE 7.
Web <URL:http://www.merlyn.demon.co.uk/> - FAQish topics, acronyms, & links.
Command-prompt MiniTrue is useful for viewing/searching/altering files. Free,
DOS/Win/UNIX now 2.0.6; see <URL:http://www.merlyn.demon.co.uk/pc-links.htm>.

Ted Davis

unread,
Aug 13, 2010, 7:18:34 PM8/13/10
to
On Fri, 13 Aug 2010 21:18:17 +0100, Dr J R Stockton wrote:

> I believe that it goes back further, to CP/M, in which only the file
> size in 128-byte sectors was recorded, with ^Z being used at least when
> text did not fill a sector. One wonders why they did not just fill the
> sector with NUL characters.

I'm pretty sure that correct - CP/M to QDOS to MS/PC DOS. Since I have
had no contact with CPM in over twenty years, never did get all that far
into it, and I didn't trust my memory that far back, I omitted mention of
both CP/M and QDOS.

--
Ted Davis (tda...@mst.edu)

Frank P. Westlake

unread,
Aug 14, 2010, 9:00:49 AM8/14/10
to
<test@...> news:nbd5661hnpgr80d5e...@4ax.com...
> "Frank P. Westlake":

> >>I think I also used COPY to read a com port. Maybe something like
> >>"COPY
>>COM9: CON:" will be more useful.

> How would I use this in the batch created by Foxy?

I don't have the time to examine that script and I have only been
skimming through the messages. I added the above suggestion only because
I happened to see a comment on some trouble with an error message. It
occurred to me that COPY might produce conditions which eliminated that
trouble -- or perhaps conditions which reduced the trouble, I don't
know -- so I offered the suggestion in case someone wanted to
invistigate. I didn't think this much of an explanation would be
necesary.

Frank


mss

unread,
Sep 6, 2010, 10:08:04 PM9/6/10
to
Ted Davis wrote:

[...]

> null modem cables

Just thinking aloud here... would be nifty to setup
up a a connection to an older computer dedicated to
error logging:

foo 2> COM

--
later on,
Mike

http://www.topcat.hypermart.net/index.html

0 new messages