By registering with us, you'll be able to discuss, share and private message with other members of our community.

SignUp Now!

Batch Read from COM1

HI guys,

I read COM1 port with a Batch file after triggering an Barcode scanner that replies immediately after getting the trigger command with the code and the required CTRL-Z.

my code:
mode COM1 Baud=9600 Parity=N Data=8 Stop=1 dtr=off rts=off
echo ^|^|^>trigger on>COM1
ping -n 1 -w 50
copy COM1 /b buffer.txt

my monitor-app shows me the answer as:
||[1]1234567 <SUB> <CR><LF>

the batch file stops running because it's waiting for the CTRL-Z (SUB)...(what definetly appears at the end of the answer) but my batch magically doesn't get it....

my problem supposed to be between echo... and copy...
sometimes it workes pretty well, sometimes not...
sometimes I can fix the problem with changing the delay between echo and copy (50ms) or using an other Computer or COM port.

I'm quite sure there is a time-issue...
I already tried changing lots of things, including setting a delay between sending back the barcode or stuff..

does somebody have an idea what I do wrong?

The support for serial devices in Windows is so limited as to be nearly useless. You're never going to make it work reliably with COPY.

TCC has variable functions to read & write to serial ports (@SERIALPORTOPEN, @SERIALPORTREAD, @SERIALPORTWRITE), but they're not available in TCC/LE. If you don't want to use the full version of TCC, you're going to have to find a utility to do the serial port reads & writes.
With TCC 16.0 64-bit, licensed, I am trying to read and write a serial device using @SERIALPORTOPEN, @SERIALPORTREAD, @SERIALPORTWRITE, but I am struggling with the documentations, which is a bit thin. I am trying to control a device that responds to the following commands:
  • ?
  • n1
  • f1
  • s0
All commands need a carriage return to terminate them (^M or 0x0d).

I have the following questions:
If I do set h=%@SERIALPORTOPEN[COM5], and COM5 does not exist on my system, why does it return a 6-digit handle, rather than 0 or -1 to indicate that it failed?

How do I send a Carriage Return to a serial port?

If I do echo %@SERIALPORTWRITE[%h,n1], it echos '1'. What do the return codes mean? It looks like 0 means success, and 1 means failure. My hardware does not seem to have received the command (or perhaps it is waiting for the CR?)

What does %@SERIALPORTFLUSH do? It could mean: delete any queued characters in the input buffer, delete any queued characters in the output buffer, make sure any characters in the output buffer have actually been sent to the serial port. But I cannot find documentation that says.

I then tried set result=%@SERIALPORTREAD[%h], and got a message:
TCC: (Sys) <filename> [32} The parameter is incorrect.
However, I know the handle is valid, because the following two commands yield 0 (for success, first time) and 1 (invalid handle, I presume, second time)

Comparing with the @FILEWRITE or @FILEWRITEB functions, the serial functions are poorly documented, and thin in functionality. Some examples would be great. Especially as serial ports tend to be used to communicate with embedded hardware, and these can be fussy about control characters, quotes, CR/LF, and binary data.

Thanks very much