Maker Pro
Maker Pro

Serial comms in PC Dos REXX - how?

J

Jim Backus

Jan 1, 1970
0
The serial interface part of a small Rexx program has got me
completely stuck.

What I want to do is read data from a unit that sends temperature
readings at a regular interval and save reformated data to a file. It
is my intention to use an old 486 PC, running PC Dos 7, to record data
over several days or weeks.

The temperature measuring module has 4 channels and sends data in one
line per channel in the form "1 0016.53" with a single linefeed
character (0A) at the end of line; in the example 1 is the channel
number and 0016.53 is the temperature reading. The unit sends data at
2400 bps, 8 bits, no parity, 1 stop bit - hardly a demanding
interface. The only thing that is non-preferred is that the unit sends
its data single ended rather than as a true RS232 signal.

The problem is that while a terminal emulator can read and display the
data continuously and without apparent problems, my Rexx program
refuses to read a single character. I've never done this sort of thing
in Rexx before so there is probably a simple fundamental error. Any
help or advice would be welcomed. I've tried the program both on an
old 486 running PC Dos 7 Rexx and on a IBM Thinkpad 600E running
Windows 98 and Regina. Both behave the same so I don't think this is a
hardware problem.

As you can see from the program listing below, I've tried both Charin
and Linein functions - both fail to receive any data. The version
below has the Linein section commented out. The program listing
follows:

port = 'COM1'

temp1 = 1.0
temp2 = 2.0
temp3 = 3.0
temp4 = 4.0

Call Stream port, 'C', 'OPEN'
'mode' port||': 24,N,8,1 >NUL'

today = Date('S')
today = Left(today,4)||'-'||SubStr(today,5,2)||'-'||Right(today,2)

now = Time()
then = now

Say today

instr=''
Do until Pos('.', instr)<>0
end /* do */
charvalue = CharIn(port)
instr = instr||charvalue
end /* do */
Say 'Received data was ' instr

/* Do count=1 to 10
instr = LineIn(port)
Say instr
channel = word(instr,1)
Select
when channel = 1 then
temp1 = word(instr,2)
when channel = 2 then
temp2 = word(instr,2)
when channel = 3 then
temp3 = word(instr,2)
when channel = 4 then
temp4 = word(instr,2)
otherwise
temp5 = 'none'
end /* select */
Say now temp1 temp2 temp3 temp4
End */

Thanks for reading this.

Jim
 
R

Robert Baer

Jan 1, 1970
0
Jim said:
The serial interface part of a small Rexx program has got me
completely stuck.

What I want to do is read data from a unit that sends temperature
readings at a regular interval and save reformated data to a file. It
is my intention to use an old 486 PC, running PC Dos 7, to record data
over several days or weeks.

The temperature measuring module has 4 channels and sends data in one
line per channel in the form "1 0016.53" with a single linefeed
character (0A) at the end of line; in the example 1 is the channel
number and 0016.53 is the temperature reading. The unit sends data at
2400 bps, 8 bits, no parity, 1 stop bit - hardly a demanding
interface. The only thing that is non-preferred is that the unit sends
its data single ended rather than as a true RS232 signal.

The problem is that while a terminal emulator can read and display the
data continuously and without apparent problems, my Rexx program
refuses to read a single character. I've never done this sort of thing
in Rexx before so there is probably a simple fundamental error. Any
help or advice would be welcomed. I've tried the program both on an
old 486 running PC Dos 7 Rexx and on a IBM Thinkpad 600E running
Windows 98 and Regina. Both behave the same so I don't think this is a
hardware problem.

As you can see from the program listing below, I've tried both Charin
and Linein functions - both fail to receive any data. The version
below has the Linein section commented out. The program listing
follows:

port = 'COM1'

temp1 = 1.0
temp2 = 2.0
temp3 = 3.0
temp4 = 4.0

Call Stream port, 'C', 'OPEN'
'mode' port||': 24,N,8,1 >NUL'

today = Date('S')
today = Left(today,4)||'-'||SubStr(today,5,2)||'-'||Right(today,2)

now = Time()
then = now

Say today

instr=''
Do until Pos('.', instr)<>0
end /* do */
charvalue = CharIn(port)
instr = instr||charvalue
end /* do */
Say 'Received data was ' instr

/* Do count=1 to 10
instr = LineIn(port)
Say instr
channel = word(instr,1)
Select
when channel = 1 then
temp1 = word(instr,2)
when channel = 2 then
temp2 = word(instr,2)
when channel = 3 then
temp3 = word(instr,2)
when channel = 4 then
temp4 = word(instr,2)
otherwise
temp5 = 'none'
end /* select */
Say now temp1 temp2 temp3 temp4
End */

Thanks for reading this.

Jim

It has been ages since i used Rexx, will look in the manuals tomorrow
for any other ideas.
Right now, i would guess the problem stems from having no <CR> before
the <LF>.
If there is a character stream mode, then processing would happen even
without either <CR> or <LF>.
But i would guess that the PARSE function would be needed to break up
he data: ie character stream would be parsed from a lump X into NUM VAL
X on a repetitive basis.
 
P

Phil Hobbs

Jan 1, 1970
0
Robert said:
Jim Backus wrote:
.0
Here's your trouble! You've got one too many ENDs--
you're stuck in an infinite loop because there's no CHARIN inside!
Cheers,

Phil Hobbs
 
J

Jim Backus

Jan 1, 1970
0
Here's your trouble! You've got one too many ENDs--
you're stuck in an infinite loop because there's no CHARIN inside!

Thanks - I'll check. The E editor in PC Dos has a habit of adding end
statements. As I'm not used to an intelligent editor I then add them
myself.
 
Top