You are not logged in.
Hi,
I have tried to send data to serial port from file. Line by line and delayed after every line sent. To another file I can send everything fine, but to COM port CR and LF are not appearing, not in ascii or binary formats. I have tried with SET, ECHO, combinations, COPY...
here is one of the dozens tryouts:
arguments %1 input file with lines to be sent, %2 COM port, %3 delay in seconds before next line to be sent. e.g. sender input.txt COM8 2
-----
@echo off > nul
mode %2 BAUD=921600 PARITY=n DATA=8 STOP=1
for /f "tokens=*" %%a in (%1) do (
echo %%a > output.txt
copy /B output.txt \\.\%2
timeout /t %3 /nobreak > nul
)
pause
----
Any proposals to get the CR and LF sent or mistakes in above preventing the CR and LF to be sent?. With terminal program the data is possible to be sent and handled in target correctly.
BR
Makro
Offline
Disclaimer: Can't say I've messed with serial data much at all.
Does it need to use a transitional file? Like, can't you just do:
for /f "tokens=*" %%a in (%1) do (
> \\.\%2 echo:%%a
timeout /t %3 /nobreak > nul
)
If that works (in that it sends the %%a data) but doesn't fix the problem, what is the result if you change it to this?
for /f "tokens=*" %%a in (%1) do (
> \\.\%2 echo:%%a
> \\.\%2 echo:
timeout /t %3 /nobreak > nul
)
(I don't know the reason behind your rate limit, but you might need to add a further delay between the echo commands)
cmd | *sh | ruby | chef
Offline
Thanks for reply bluesxman,
Reason for the middle output.txt was that it seemed to write correctly to file the line feeds, though I am not absolute sure. Meanwhile I learnt that the for /f collects tokens so it probably cleans CR & LF away. echo should add it though.
I will try those proposals. and reply results.
Serial data rate is default 921600 in the target. Everything else seems to appear but the LF&CR not. I can test with lower data rates, though powershell works ok, but cmd may have something. I would prefer cmd if possible. In target the data rate is not problem. only some message sequences may take longer time, so script to delay. It might be interesting when available in a couple months.
BR
Makro
Disclaimer: Can't say I've messed with serial data much at all.
Does it need to use a transitional file? Like, can't you just do:
for /f "tokens=*" %%a in (%1) do ( > \\.\%2 echo:%%a timeout /t %3 /nobreak > nul )
If that works (in that it sends the %%a data) but doesn't fix the problem, what is the result if you change it to this?
for /f "tokens=*" %%a in (%1) do ( > \\.\%2 echo:%%a > \\.\%2 echo: timeout /t %3 /nobreak > nul )
(I don't know the reason behind your rate limit, but you might need to add a further delay between the echo commands)
Offline
Hi,
Unfortunately I was not able to solve the issue with bluesxman advices.
Here is well working powershell script for the purpose I was trying to get the cmd version. I assume that the serial port data rate is not issue either due I tried with lower rates like 14400 and 1200 bits/s.
---
param([string]$input_file = "", [string]$serial_port_name = "", [int]$sending_delay = 0)
$reader = [System.IO.File]::OpenText($input_file)
$port = new-Object System.IO.Ports.SerialPort $serial_port_name,921600,None,8,one
$port.open()
while($null -ne ($line = $reader.ReadLine())) {
$port.WriteLine($line)
Start-Sleep -m $sending_delay
}
$port.Close()
---
BR
Makro
Offline