Post by Rod on Apr 1, 2023 3:53:54 GMT -5
This has been getting discussed in another thread but it needs a thread of its own. The RS22-168 is a popular multimeter that has a serial interface and lends itself to tracking readings over time. Being able to link to Liberty would be great.
It has a five pin lead that connects to any USB based serial dongle. The lead can either be five pins equally spaced or five pins with an offset. This to prevent it being reversed. The lead should point upwards towards the top of the meter.
The interface is said to use RTS low -12v and and DTR high +12v for power. It is opto isolated so the pc side must supply power. It seems to use RTS/DTR to provide this.
It uses a very common protocol and receives D,M or C as a prompt to either send data D, send memory readings M, or C clear memory. So only three commands to send. It appears to send a fixed length packet of info depending on what the meter is set to read. It terminates with a CR, chr$(13)
So this is a first attempt to get a response from the meter. If you have one please see if the code works or try and tell me where it fails.
It has a five pin lead that connects to any USB based serial dongle. The lead can either be five pins equally spaced or five pins with an offset. This to prevent it being reversed. The lead should point upwards towards the top of the meter.
The interface is said to use RTS low -12v and and DTR high +12v for power. It is opto isolated so the pc side must supply power. It seems to use RTS/DTR to provide this.
It uses a very common protocol and receives D,M or C as a prompt to either send data D, send memory readings M, or C clear memory. So only three commands to send. It appears to send a fixed length packet of info depending on what the meter is set to read. It terminates with a CR, chr$(13)
So this is a first attempt to get a response from the meter. If you have one please see if the code works or try and tell me where it fails.
'Open the port briefly using an API call to determine the handle given by Windows
'We will use this handle later in Liberty, its the only way to get it.
'substitute your own port number
lpFileName$ = "Com4"
dwCreationDistribution = _OPEN_EXISTING
hTemplateFile = _NULL
calldll #kernel32, "CreateFileA", _
lpFileName$ as ptr, _
dwDesiredAccess as ulong, _
dwShareMode as ulong, _
lpSecurityAttributes as ulong, _
dwCreationDistribution as ulong, _
dwFlagsAndAttributes as ulong, _
hTemplateFile as ulong, _
hFileHandle as ulong
calldll #kernel32, "CloseHandle", _
hFileHandle as ulong, _
result as long
call pause 250
'Now open the com port in Liberty and use the hFileHandle value in API calls
open lpFileName$;":1200,n,7,2,ds0,cs0,rs" for random as #com
call pause 250
'now set DTR high and RTS low
print "setting DTR"
CALLDLL #kernel32, "EscapeCommFunction", hFileHandle as ulong, _SETDTR as long,_
result as long
print "re-setting RTS"
CALLDLL #kernel32, "EscapeCommFunction", hFileHandle as ulong, _CLRRTS as long,_
result as long
call pause 250
#com "D";
call pause 500
response$ = input$(#com, lof(#com))
print len(response$)
print response$
close #com
end
sub pause ms
timer ms,[done]
wait
[done]
timer 0
end sub