Sending Decimal Numbers instead of their ascii equivalent

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
dieluna
Posts: 1
Joined: 19 Dec 2014 09:04

Sending Decimal Numbers instead of their ascii equivalent

#1 Post by dieluna » 19 Dec 2014 09:11

Hi everyone
I'm trying to send decimal numbers to one my serial com ports .. For example ;

Code: Select all

@echo off
mode COM3 BAUD=9600 PARITY=n DATA=8

:main
set /p x=5<nul >\\.\COM3
TYPE COM3
goto main


The command above sends decimal 53 (Ascii 5 )actually ... But I want to send decimal 5 ...
Is there such an operator in command prompt ?

Thanks in advance

Squashman
Expert
Posts: 4488
Joined: 23 Dec 2011 13:59

Re: Sending Decimal Numbers instead of their ascii equivalen

#2 Post by Squashman » 19 Dec 2014 09:34

Give this a try.

Code: Select all

@echo off
setlocal

::Define a Linefeed variable
set LF=^


::above 2 blank lines are critical - do not remove.

call :hexprint "0x05" rtnvar

mode COM3 BAUD=9600 PARITY=n DATA=8

:main
set /p x=%rtnvar%<nul >\\.\COM3
TYPE COM3
goto main

exit /b

:hexPrint  string  [rtnVar]
  for /f eol^=^%LF%%LF%^ delims^= %%A in (
    'forfiles /p "%~dp0." /m "%~nx0" /c "cmd /c echo(%~1"'
  ) do if "%~2" neq "" (set %~2=%%A) else echo(%%A
exit /b

penpen
Expert
Posts: 2009
Joined: 23 Jun 2013 06:15
Location: Germany

Re: Sending Decimal Numbers instead of their ascii equivalen

#3 Post by penpen » 19 Dec 2014 16:41

If you need all binary byte values, this may help you:
http://www.dostips.com/forum/viewtopic.php?f=3&t=5326

penpen

Post Reply